Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry options to Synthetics multi step #1317

Merged
merged 5 commits into from Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 48 additions & 21 deletions datadog/resource_datadog_synthetics_test_.go
Expand Up @@ -339,6 +339,30 @@ func syntheticsAPIAssertion() *schema.Schema {
}
}

func syntheticsTestOptionsRetry() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Description: "Number of retries needed to consider a location as failed before sending a notification alert.",
Type: schema.TypeInt,
Default: 0,
Optional: true,
},
"interval": {
Description: "Interval between a failed test and the next retry in milliseconds.",
Type: schema.TypeInt,
Default: 300,
Optional: true,
},
},
},
}
}

func syntheticsTestOptionsList() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -395,27 +419,7 @@ func syntheticsTestOptionsList() *schema.Schema {
Optional: true,
ValidateFunc: validation.IntBetween(1, 5),
},
"retry": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Description: "Number of retries needed to consider a location as failed before sending a notification alert.",
Type: schema.TypeInt,
Default: 0,
Optional: true,
},
"interval": {
Description: "Interval between a failed test and the next retry in milliseconds.",
Type: schema.TypeInt,
Default: 300,
Optional: true,
},
},
},
},
"retry": syntheticsTestOptionsRetry(),
"no_screenshot": {
Description: "Prevents saving screenshots of the steps.",
Type: schema.TypeBool,
Expand Down Expand Up @@ -515,6 +519,7 @@ func syntheticsTestAPIStep() *schema.Schema {
Type: schema.TypeBool,
Optional: true,
},
"retry": syntheticsTestOptionsRetry(),
},
},
}
Expand Down Expand Up @@ -1143,6 +1148,17 @@ func buildSyntheticsAPITestStruct(d *schema.ResourceData) *datadogV1.SyntheticsA
step.SetAllowFailure(stepMap["allow_failure"].(bool))
step.SetIsCritical(stepMap["is_critical"].(bool))

optionsRetry := datadogV1.SyntheticsTestOptionsRetry{}
retry := stepMap["retry"].([]interface{})[0]

if count, ok := retry.(map[string]interface{})["count"]; ok {
optionsRetry.SetCount(int64(count.(int)))
}
if interval, ok := retry.(map[string]interface{})["interval"]; ok {
optionsRetry.SetInterval(float64(interval.(int)))
}
step.SetRetry(optionsRetry)

steps = append(steps, step)
}

Expand Down Expand Up @@ -2183,6 +2199,17 @@ func updateSyntheticsAPITestLocalState(d *schema.ResourceData, syntheticsTest *d
localStep["allow_failure"] = step.GetAllowFailure()
localStep["is_critical"] = step.GetIsCritical()

if retry, ok := step.GetRetryOk(); ok {
localRetry := make(map[string]interface{})
if count, ok := retry.GetCountOk(); ok {
localRetry["count"] = *count
}
if interval, ok := retry.GetIntervalOk(); ok {
localRetry["interval"] = *interval
}
localStep["retry"] = []map[string]interface{}{localRetry}
}

localSteps[i] = localStep
}

Expand Down
@@ -1 +1 @@
2021-12-20T13:23:11.646067-05:00
2022-01-04T18:22:11.40064+01:00