Skip to content

Commit

Permalink
[datadog_synthetics_test] Add support for timings scope for response …
Browse files Browse the repository at this point in the history
…assertions (#2101)

* Update go clients

* Add support for timings scope for response time assetions

* Fix missing description

* Update docs
  • Loading branch information
romainberger authored Sep 14, 2023
1 parent 0441602 commit 46203b8
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 175 deletions.
12 changes: 12 additions & 0 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ func syntheticsAPIAssertion() *schema.Schema {
},
},
},
"timings_scope": {
Description: "Timings scope for response time assertions.",
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsAssertionTimingsScopeFromValue),
},
},
},
}
Expand Down Expand Up @@ -1866,6 +1872,9 @@ func buildAssertions(attr []interface{}) []datadogV1.SyntheticsAssertion {
assertionTarget.SetTarget(v.(string))
}
}
if v, ok := assertionMap["timings_scope"].(string); ok && len(v) > 0 {
assertionTarget.SetTimingsScope(datadogV1.SyntheticsAssertionTimingsScope(v))
}
if v, ok := assertionMap["targetjsonpath"].([]interface{}); ok && len(v) > 0 {
log.Printf("[WARN] targetjsonpath shouldn't be specified for non-validatesJSONPath operator, only target")
}
Expand Down Expand Up @@ -2360,6 +2369,9 @@ func buildLocalAssertions(actualAssertions []datadogV1.SyntheticsAssertion) (loc
if v, ok := assertionTarget.GetTypeOk(); ok {
localAssertion["type"] = string(*v)
}
if assertionTarget.HasTimingsScope() {
localAssertion["timings_scope"] = assertionTarget.GetTimingsScope()
}
} else if assertion.SyntheticsAssertionJSONPathTarget != nil {
assertionTarget := assertion.SyntheticsAssertionJSONPathTarget
if v, ok := assertionTarget.GetOperatorOk(); ok {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-02-02T21:53:48.59555+01:00
2023-09-13T09:53:58.401802+02:00
76 changes: 38 additions & 38 deletions datadog/tests/cassettes/TestAccDatadogSyntheticsAPITest_Basic.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-02-06T14:44:20.616769-05:00
2023-09-13T09:58:11.767846+02:00
108 changes: 54 additions & 54 deletions datadog/tests/cassettes/TestAccDatadogSyntheticsAPITest_Updated.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-06-21T15:54:06.149008+02:00
2023-09-13T09:58:11.767503+02:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-02-02T21:54:04.824108+01:00
2023-09-13T10:01:38.055501+02:00

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions datadog/tests/resource_datadog_synthetics_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ func createSyntheticsAPITestStep(ctx context.Context, accProvider func() (*schem
"datadog_synthetics_test.foo", "assertion.2.operator", "lessThan"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "assertion.2.target", "2000"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "assertion.2.timings_scope", "withoutDNS"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "assertion.3.type", "body"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -716,6 +718,7 @@ resource "datadog_synthetics_test" "foo" {
type = "responseTime"
operator = "lessThan"
target = "2000"
timings_scope = "withoutDNS"
}
assertion {
type = "body"
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/synthetics_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ Optional:
- `target` (String) Expected value. Depends on the assertion type, refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test) for details.
- `targetjsonpath` (Block List, Max: 1) Expected structure if `operator` is `validatesJSONPath`. Exactly one nested block is allowed with the structure below. (see [below for nested schema](#nestedblock--api_step--assertion--targetjsonpath))
- `targetxpath` (Block List, Max: 1) Expected structure if `operator` is `validatesXPath`. Exactly one nested block is allowed with the structure below. (see [below for nested schema](#nestedblock--api_step--assertion--targetxpath))
- `timings_scope` (String) Timings scope for response time assertions. Valid values are `all`, `withoutDNS`.

<a id="nestedblock--api_step--assertion--targetjsonpath"></a>
### Nested Schema for `api_step.assertion.targetjsonpath`
Expand Down Expand Up @@ -561,6 +562,7 @@ Optional:
- `target` (String) Expected value. Depends on the assertion type, refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test) for details.
- `targetjsonpath` (Block List, Max: 1) Expected structure if `operator` is `validatesJSONPath`. Exactly one nested block is allowed with the structure below. (see [below for nested schema](#nestedblock--assertion--targetjsonpath))
- `targetxpath` (Block List, Max: 1) Expected structure if `operator` is `validatesXPath`. Exactly one nested block is allowed with the structure below. (see [below for nested schema](#nestedblock--assertion--targetxpath))
- `timings_scope` (String) Timings scope for response time assertions. Valid values are `all`, `withoutDNS`.

<a id="nestedblock--assertion--targetjsonpath"></a>
### Nested Schema for `assertion.targetjsonpath`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-datadog

require (
github.com/DataDog/datadog-api-client-go/v2 v2.17.0
github.com/DataDog/datadog-api-client-go/v2 v2.17.1-0.20230912212818-5516505764fa
github.com/DataDog/dd-sdk-go-testing v0.0.0-20211116174033-1cd082e322ad
github.com/dnaeon/go-vcr v1.0.1
github.com/hashicorp/go-cleanhttp v0.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-api-client-go/v2 v2.17.0 h1:0jI5TotLfWgsydMg/QTHkuoqNCFKSMorjU3ki/fbVI8=
github.com/DataDog/datadog-api-client-go/v2 v2.17.0/go.mod h1:uJd7G1BONVIyiVw684VMn2XYI1FfN1tx4bRGenAf2bo=
github.com/DataDog/datadog-api-client-go/v2 v2.17.1-0.20230912212818-5516505764fa h1:DDYJ7gcGUN9lZY90s6xZKsHcQTOaRc70BcegRY/4VQA=
github.com/DataDog/datadog-api-client-go/v2 v2.17.1-0.20230912212818-5516505764fa/go.mod h1:uJd7G1BONVIyiVw684VMn2XYI1FfN1tx4bRGenAf2bo=
github.com/DataDog/datadog-go v4.4.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down

0 comments on commit 46203b8

Please sign in to comment.