From 01d04c3f10348bbbc9ba13614e8b99bd888df25d Mon Sep 17 00:00:00 2001 From: Arthur Hemery Date: Thu, 14 Nov 2024 08:47:03 +0100 Subject: [PATCH] More tests --- .../fwprovider/resource_datadog_rum_metric.go | 13 +- .../TestAccRumMetricAttributes.freeze | 2 +- .../cassettes/TestAccRumMetricAttributes.yaml | 390 ++++++++++++++++-- .../cassettes/TestAccRumMetricImport.freeze | 2 +- .../cassettes/TestAccRumMetricImport.yaml | 24 +- .../tests/resource_datadog_rum_metric_test.go | 105 ++++- 6 files changed, 462 insertions(+), 74 deletions(-) diff --git a/datadog/fwprovider/resource_datadog_rum_metric.go b/datadog/fwprovider/resource_datadog_rum_metric.go index 78d8cc1d9..ba3754c6b 100644 --- a/datadog/fwprovider/resource_datadog_rum_metric.go +++ b/datadog/fwprovider/resource_datadog_rum_metric.go @@ -105,6 +105,9 @@ func (r *rumMetricResource) Schema(_ context.Context, _ resource.SchemaRequest, "path": schema.StringAttribute{ Description: "The path to the value the rum-based metric will aggregate on. Only present when `aggregation_type` is `distribution`.", Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, }, }, @@ -212,7 +215,7 @@ func (r *rumMetricResource) Update(ctx context.Context, request resource.UpdateR return } - id := state.ID.ValueString() + id := state.Name.ValueString() body, diags := r.buildRumMetricUpdateRequestBody(ctx, &state) response.Diagnostics.Append(diags...) @@ -273,9 +276,7 @@ func (r *rumMetricResource) updateState(ctx context.Context, state *rumMetricMod computeTf.IncludePercentiles = types.BoolValue(*includePercentiles) } if path, ok := compute.GetPathOk(); ok { - if *path != "" { - computeTf.Path = types.StringValue(*path) - } + computeTf.Path = types.StringValue(*path) } state.Compute = &computeTf @@ -366,7 +367,7 @@ func (r *rumMetricResource) buildRumMetricRequestBody(ctx context.Context, state req := datadogV2.NewRumMetricCreateRequestWithDefaults() req.Data = *datadogV2.NewRumMetricCreateDataWithDefaults() - req.Data.SetId(state.Name.String()) + req.Data.SetId(state.Name.ValueString()) req.Data.SetAttributes(*attributes) return req, diags @@ -410,7 +411,7 @@ func (r *rumMetricResource) buildRumMetricUpdateRequestBody(ctx context.Context, req := datadogV2.NewRumMetricUpdateRequestWithDefaults() req.Data = *datadogV2.NewRumMetricUpdateDataWithDefaults() - req.Data.SetId(state.Name.String()) + req.Data.SetId(state.Name.ValueString()) req.Data.SetAttributes(*attributes) return req, diags diff --git a/datadog/tests/cassettes/TestAccRumMetricAttributes.freeze b/datadog/tests/cassettes/TestAccRumMetricAttributes.freeze index 5ff118de3..40c5aca43 100644 --- a/datadog/tests/cassettes/TestAccRumMetricAttributes.freeze +++ b/datadog/tests/cassettes/TestAccRumMetricAttributes.freeze @@ -1 +1 @@ -2024-11-13T14:53:37.123281+01:00 \ No newline at end of file +2024-11-14T08:43:39.339296+01:00 \ No newline at end of file diff --git a/datadog/tests/cassettes/TestAccRumMetricAttributes.yaml b/datadog/tests/cassettes/TestAccRumMetricAttributes.yaml index 3ce7c4b6d..87e24a54d 100644 --- a/datadog/tests/cassettes/TestAccRumMetricAttributes.yaml +++ b/datadog/tests/cassettes/TestAccRumMetricAttributes.yaml @@ -6,14 +6,14 @@ interactions: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 166 + content_length: 162 transfer_encoding: [] trailer: {} host: api.datadoghq.com remote_addr: "" request_uri: "" body: | - {"data":{"attributes":{"compute":{"aggregation_type":"count"},"event_type":"action"},"id":"\"tf_TestAccRumMetricAttributes_local_1731506017\"","type":"rum_metrics"}} + {"data":{"attributes":{"compute":{"aggregation_type":"count"},"event_type":"action"},"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics"}} form: {} headers: Accept: @@ -30,13 +30,13 @@ interactions: trailer: {} content_length: 175 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' headers: Content-Type: - application/vnd.api+json status: 201 Created code: 201 - duration: 815.741958ms + duration: 284.684291ms - id: 1 request: proto: HTTP/1.1 @@ -53,7 +53,7 @@ interactions: headers: Accept: - application/json - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 method: GET response: proto: HTTP/2.0 @@ -63,13 +63,13 @@ interactions: trailer: {} content_length: 175 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' headers: Content-Type: - application/vnd.api+json status: 200 OK code: 200 - duration: 109.067958ms + duration: 110.622375ms - id: 2 request: proto: HTTP/1.1 @@ -86,7 +86,7 @@ interactions: headers: Accept: - '*/*' - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 method: DELETE response: proto: HTTP/2.0 @@ -100,20 +100,20 @@ interactions: headers: {} status: 204 No Content code: 204 - duration: 117.488125ms + duration: 106.971625ms - id: 3 request: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 219 + content_length: 215 transfer_encoding: [] trailer: {} host: api.datadoghq.com remote_addr: "" request_uri: "" body: | - {"data":{"attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":true,"path":"@duration"},"event_type":"action"},"id":"\"tf_TestAccRumMetricAttributes_local_1731506017\"","type":"rum_metrics"}} + {"data":{"attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":true,"path":"@duration"},"event_type":"action"},"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics"}} form: {} headers: Accept: @@ -130,13 +130,13 @@ interactions: trailer: {} content_length: 228 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":true,"path":"@duration"},"event_type":"action","group_by":[]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":true,"path":"@duration"},"event_type":"action","group_by":[]}}}' headers: Content-Type: - application/vnd.api+json status: 201 Created code: 201 - duration: 1.02972725s + duration: 169.534458ms - id: 4 request: proto: HTTP/1.1 @@ -153,7 +153,7 @@ interactions: headers: Accept: - application/json - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 method: GET response: proto: HTTP/2.0 @@ -163,14 +163,116 @@ interactions: trailer: {} content_length: 228 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":true,"path":"@duration"},"event_type":"action","group_by":[]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":true,"path":"@duration"},"event_type":"action","group_by":[]}}}' headers: Content-Type: - application/vnd.api+json status: 200 OK code: 200 - duration: 108.842709ms + duration: 101.855583ms - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 228 + uncompressed: false + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":true,"path":"@duration"},"event_type":"action","group_by":[]}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 103.168042ms + - id: 6 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 141 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"compute":{"include_percentiles":false}},"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 229 + uncompressed: false + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":false,"path":"@duration"},"event_type":"action","group_by":[]}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 198.737833ms + - id: 7 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 229 + uncompressed: false + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":false,"path":"@duration"},"event_type":"action","group_by":[]}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 105.835417ms + - id: 8 request: proto: HTTP/1.1 proto_major: 1 @@ -186,7 +288,7 @@ interactions: headers: Accept: - '*/*' - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 method: DELETE response: proto: HTTP/2.0 @@ -200,20 +302,20 @@ interactions: headers: {} status: 204 No Content code: 204 - duration: 112.006667ms - - id: 6 + duration: 103.626958ms + - id: 9 request: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 203 + content_length: 199 transfer_encoding: [] trailer: {} host: api.datadoghq.com remote_addr: "" request_uri: "" body: | - {"data":{"attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","filter":{"query":"@service:web-ui"}},"id":"\"tf_TestAccRumMetricAttributes_local_1731506017\"","type":"rum_metrics"}} + {"data":{"attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","filter":{"query":"@service:web-ui"}},"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics"}} form: {} headers: Accept: @@ -230,14 +332,14 @@ interactions: trailer: {} content_length: 212 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","filter":{"query":"@service:web-ui"},"group_by":[]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","filter":{"query":"@service:web-ui"},"group_by":[]}}}' headers: Content-Type: - application/vnd.api+json status: 201 Created code: 201 - duration: 247.393ms - - id: 7 + duration: 295.008292ms + - id: 10 request: proto: HTTP/1.1 proto_major: 1 @@ -253,7 +355,7 @@ interactions: headers: Accept: - application/json - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 method: GET response: proto: HTTP/2.0 @@ -263,14 +365,116 @@ interactions: trailer: {} content_length: 212 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","filter":{"query":"@service:web-ui"},"group_by":[]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","filter":{"query":"@service:web-ui"},"group_by":[]}}}' headers: Content-Type: - application/vnd.api+json status: 200 OK code: 200 - duration: 107.427541ms - - id: 8 + duration: 103.364625ms + - id: 11 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 212 + uncompressed: false + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","filter":{"query":"@service:web-ui"},"group_by":[]}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 102.999625ms + - id: 12 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 160 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"compute":{},"filter":{"query":"@service:another-service"}},"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 221 + uncompressed: false + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","filter":{"query":"@service:another-service"},"group_by":[]}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 113.463959ms + - id: 13 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 221 + uncompressed: false + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","filter":{"query":"@service:another-service"},"group_by":[]}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 105.07ms + - id: 14 request: proto: HTTP/1.1 proto_major: 1 @@ -286,7 +490,7 @@ interactions: headers: Accept: - '*/*' - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 method: DELETE response: proto: HTTP/2.0 @@ -300,20 +504,20 @@ interactions: headers: {} status: 204 No Content code: 204 - duration: 107.245458ms - - id: 9 + duration: 105.244208ms + - id: 15 request: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 251 + content_length: 247 transfer_encoding: [] trailer: {} host: api.datadoghq.com remote_addr: "" request_uri: "" body: | - {"data":{"attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[{"path":"@os","tag_name":"os"},{"path":"@service","tag_name":"service"}]},"id":"\"tf_TestAccRumMetricAttributes_local_1731506017\"","type":"rum_metrics"}} + {"data":{"attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[{"path":"@os","tag_name":"os"},{"path":"@service","tag_name":"service"}]},"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics"}} form: {} headers: Accept: @@ -330,14 +534,14 @@ interactions: trailer: {} content_length: 246 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[{"path":"@os","tag_name":"os"},{"path":"@service","tag_name":"service"}]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[{"path":"@os","tag_name":"os"},{"path":"@service","tag_name":"service"}]}}}' headers: Content-Type: - application/vnd.api+json status: 201 Created code: 201 - duration: 550.922458ms - - id: 10 + duration: 173.423208ms + - id: 16 request: proto: HTTP/1.1 proto_major: 1 @@ -353,7 +557,7 @@ interactions: headers: Accept: - application/json - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 method: GET response: proto: HTTP/2.0 @@ -363,14 +567,116 @@ interactions: trailer: {} content_length: 246 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[{"path":"@os","tag_name":"os"},{"path":"@service","tag_name":"service"}]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[{"path":"@os","tag_name":"os"},{"path":"@service","tag_name":"service"}]}}}' headers: Content-Type: - application/vnd.api+json status: 200 OK code: 200 - duration: 107.373583ms - - id: 11 + duration: 101.0235ms + - id: 17 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 246 + uncompressed: false + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[{"path":"@os","tag_name":"os"},{"path":"@service","tag_name":"service"}]}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 103.437333ms + - id: 18 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 276 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"compute":{},"group_by":[{"path":"@os","tag_name":"os"},{"path":"@os.version.major","tag_name":"os_version_major"},{"path":"@os.version.minor","tag_name":"os_version_minor"}]},"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 323 + uncompressed: false + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[{"path":"@os","tag_name":"os"},{"path":"@os.version.major","tag_name":"os_version_major"},{"path":"@os.version.minor","tag_name":"os_version_minor"}]}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 167.486542ms + - id: 19 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 323 + uncompressed: false + body: '{"data":{"id":"tf_TestAccRumMetricAttributes_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[{"path":"@os","tag_name":"os"},{"path":"@os.version.major","tag_name":"os_version_major"},{"path":"@os.version.minor","tag_name":"os_version_minor"}]}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 102.668125ms + - id: 20 request: proto: HTTP/1.1 proto_major: 1 @@ -386,7 +692,7 @@ interactions: headers: Accept: - '*/*' - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricAttributes_local_1731570219 method: DELETE response: proto: HTTP/2.0 @@ -400,4 +706,4 @@ interactions: headers: {} status: 204 No Content code: 204 - duration: 108.528417ms + duration: 105.208958ms diff --git a/datadog/tests/cassettes/TestAccRumMetricImport.freeze b/datadog/tests/cassettes/TestAccRumMetricImport.freeze index 05e44395d..978a2cd7d 100644 --- a/datadog/tests/cassettes/TestAccRumMetricImport.freeze +++ b/datadog/tests/cassettes/TestAccRumMetricImport.freeze @@ -1 +1 @@ -2024-11-13T14:53:37.123287+01:00 \ No newline at end of file +2024-11-14T08:43:39.33944+01:00 \ No newline at end of file diff --git a/datadog/tests/cassettes/TestAccRumMetricImport.yaml b/datadog/tests/cassettes/TestAccRumMetricImport.yaml index 6a2f59a8b..99a541846 100644 --- a/datadog/tests/cassettes/TestAccRumMetricImport.yaml +++ b/datadog/tests/cassettes/TestAccRumMetricImport.yaml @@ -6,14 +6,14 @@ interactions: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 162 + content_length: 158 transfer_encoding: [] trailer: {} host: api.datadoghq.com remote_addr: "" request_uri: "" body: | - {"data":{"attributes":{"compute":{"aggregation_type":"count"},"event_type":"action"},"id":"\"tf_TestAccRumMetricImport_local_1731506017\"","type":"rum_metrics"}} + {"data":{"attributes":{"compute":{"aggregation_type":"count"},"event_type":"action"},"id":"tf_TestAccRumMetricImport_local_1731570219","type":"rum_metrics"}} form: {} headers: Accept: @@ -30,13 +30,13 @@ interactions: trailer: {} content_length: 171 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricImport_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricImport_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' headers: Content-Type: - application/vnd.api+json status: 201 Created code: 201 - duration: 707.791ms + duration: 303.473833ms - id: 1 request: proto: HTTP/1.1 @@ -53,7 +53,7 @@ interactions: headers: Accept: - application/json - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricImport_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricImport_local_1731570219 method: GET response: proto: HTTP/2.0 @@ -63,13 +63,13 @@ interactions: trailer: {} content_length: 171 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricImport_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricImport_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' headers: Content-Type: - application/vnd.api+json status: 200 OK code: 200 - duration: 108.442334ms + duration: 120.268708ms - id: 2 request: proto: HTTP/1.1 @@ -86,7 +86,7 @@ interactions: headers: Accept: - application/json - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricImport_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricImport_local_1731570219 method: GET response: proto: HTTP/2.0 @@ -96,13 +96,13 @@ interactions: trailer: {} content_length: 171 uncompressed: false - body: '{"data":{"id":"tf_TestAccRumMetricImport_local_1731506017","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' + body: '{"data":{"id":"tf_TestAccRumMetricImport_local_1731570219","type":"rum_metrics","attributes":{"compute":{"aggregation_type":"count"},"event_type":"action","group_by":[]}}}' headers: Content-Type: - application/vnd.api+json status: 200 OK code: 200 - duration: 109.190917ms + duration: 107.598417ms - id: 3 request: proto: HTTP/1.1 @@ -119,7 +119,7 @@ interactions: headers: Accept: - '*/*' - url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricImport_local_1731506017 + url: https://api.datadoghq.com/api/v2/rum/config/metrics/tf_TestAccRumMetricImport_local_1731570219 method: DELETE response: proto: HTTP/2.0 @@ -133,4 +133,4 @@ interactions: headers: {} status: 204 No Content code: 204 - duration: 111.724542ms + duration: 107.622958ms diff --git a/datadog/tests/resource_datadog_rum_metric_test.go b/datadog/tests/resource_datadog_rum_metric_test.go index 4f3756aa9..042c132f1 100644 --- a/datadog/tests/resource_datadog_rum_metric_test.go +++ b/datadog/tests/resource_datadog_rum_metric_test.go @@ -19,10 +19,9 @@ func TestAccRumMetricImport(t *testing.T) { ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t) // The API will currently silently remap - to _, which makes terraform unhappy. This will - // just make the tests pass but this is a real issue. - // Being addressed in https://datadoghq.atlassian.net/browse/RUM-7124. Note that this is - // also an issue for other existing APIs using the same backend (spans metrics and maybe - // logs metrics?). + // just make the tests pass but this is a real issue. It is discussed in + // https://datadoghq.atlassian.net/browse/RUM-7124. Note that this is also the case for + // other existing APIs using the same backend (spans metrics and maybe logs metrics?). uniq := strings.ReplaceAll(uniqueEntityName(ctx, t), "-", "_") resource.Test(t, resource.TestCase{ @@ -84,6 +83,14 @@ func TestAccRumMetricAttributes(t *testing.T) { "datadog_rum_metric.testing_rum_metric", "compute.path", "@duration"), ), }, + { + Config: distributionDatadogRumMetricUpdate(uniq), + Check: resource.ComposeTestCheckFunc( + testAccCheckDatadogSpansMetricExists(providers.frameworkProvider), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "compute.include_percentiles", "false"), + ), + }, }, }) @@ -99,6 +106,14 @@ func TestAccRumMetricAttributes(t *testing.T) { "datadog_rum_metric.testing_rum_metric", "filter.query", "@service:web-ui"), ), }, + { + Config: filterDatadogRumMetricUpdate(uniq), + Check: resource.ComposeTestCheckFunc( + testAccCheckDatadogRumMetricExists(providers.frameworkProvider), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "filter.query", "@service:another-service"), + ), + }, }, }) @@ -108,12 +123,39 @@ func TestAccRumMetricAttributes(t *testing.T) { Steps: []resource.TestStep{ { Config: groupByDatadogRumMetric(uniq), - Check: testAccCheckDatadogRumMetricExists(providers.frameworkProvider), - // resource.ComposeTestCheckFunc( - - // resource.TestCheckResourceAttr( - // "datadog_rum_metric.testing_rum_metric", "group_by.#", "2"), - // ), + Check: resource.ComposeTestCheckFunc( + testAccCheckDatadogRumMetricExists(providers.frameworkProvider), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.#", "2"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.0.path", "@os"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.0.tag_name", "os"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.1.path", "@service"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.1.tag_name", "service"), + ), + }, + { + Config: groupByDatadogRumMetricUpdate(uniq), + Check: resource.ComposeTestCheckFunc( + testAccCheckDatadogRumMetricExists(providers.frameworkProvider), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.#", "3"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.0.path", "@os"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.0.tag_name", "os"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.1.path", "@os.version.major"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.1.tag_name", "os_version_major"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.2.path", "@os.version.minor"), + resource.TestCheckResourceAttr( + "datadog_rum_metric.testing_rum_metric", "group_by.2.tag_name", "os_version_minor"), + ), }, }, }) @@ -143,12 +185,14 @@ func distributionDatadogRumMetric(uniq string) string { `, uniq) } -func countDatadogRumMetric(uniq string) string { +func distributionDatadogRumMetricUpdate(uniq string) string { return fmt.Sprintf(`resource "datadog_rum_metric" "testing_rum_metric" { name = %q event_type = "action" compute { - aggregation_type = "count" + aggregation_type = "distribution" + include_percentiles = false + path = "@duration" } } `, uniq) @@ -168,6 +212,20 @@ func filterDatadogRumMetric(uniq string) string { `, uniq) } +func filterDatadogRumMetricUpdate(uniq string) string { + return fmt.Sprintf(`resource "datadog_rum_metric" "testing_rum_metric" { + name = %q + event_type = "action" + compute { + aggregation_type = "count" + } + filter { + query = "@service:another-service" + } + } + `, uniq) +} + func groupByDatadogRumMetric(uniq string) string { // Note: the group_bys are not defined in alphabetical order. This is on purpose to verify // a set behavior rather than a list behavior on the terraform attribute. @@ -189,6 +247,29 @@ func groupByDatadogRumMetric(uniq string) string { `, uniq) } +func groupByDatadogRumMetricUpdate(uniq string) string { + return fmt.Sprintf(`resource "datadog_rum_metric" "testing_rum_metric" { + name = %q + event_type = "action" + compute { + aggregation_type = "count" + } + group_by { + path = "@os" + tag_name = "os" + } + group_by { + path = "@os.version.major" + tag_name = "os_version_major" + } + group_by { + path = "@os.version.minor" + tag_name = "os_version_minor" + } + } + `, uniq) +} + func testAccCheckDatadogRumMetricDestroy(accProvider *fwprovider.FrameworkProvider) func(*terraform.State) error { return func(s *terraform.State) error { apiInstances := accProvider.DatadogApiInstances