Skip to content

Commit

Permalink
SM: Higher default for multi HTTP checks (#1342)
Browse files Browse the repository at this point in the history
As suggested here: #1173
Can't hurt to raise the defaults for those. Not going to raise all of them because it would cause too much drift. Multi-HTTP is newer and is the one that needs it so it's fine, I think
  • Loading branch information
julienduchesne authored Feb 9, 2024
1 parent 7215653 commit 2216fb2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions internal/resources/syntheticmonitoring/resource_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
"github.com/grafana/terraform-provider-grafana/internal/common"
)

const (
checkDefaultTimeout = 3000
checkMultiHTTPDefaultTimeout = 5000
)

var (

// Set variables for schemas used in multiple fields and/or used to transform
Expand Down Expand Up @@ -675,7 +680,18 @@ multiple checks for a single endpoint to check different capabilities.
"The minimum acceptable value is 1 second (1000 ms), and the maximum 10 seconds (10000 ms).",
Type: schema.TypeInt,
Optional: true,
Default: 3000,
Default: checkDefaultTimeout,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
// Suppress diff if it's a multihttp check with a timeout of 5000 (default timeout for those)
// and it's being changed to 3000 (default timeout set here).
if d.Get("settings.0.multihttp.0") != nil &&
old == strconv.Itoa(checkMultiHTTPDefaultTimeout) &&
new == strconv.Itoa(checkDefaultTimeout) {
return true
}

return old == new
},
},
"enabled": {
Description: "Whether to enable the check.",
Expand Down Expand Up @@ -1093,13 +1109,18 @@ func makeCheck(d *schema.ResourceData) (*sm.Check, error) {
return nil, fmt.Errorf("invalid settings: %w", err)
}

timeout := int64(d.Get("timeout").(int))
if timeout == checkDefaultTimeout && settings.Multihttp != nil {
timeout = checkMultiHTTPDefaultTimeout
}

return &sm.Check{
Id: id,
TenantId: int64(d.Get("tenant_id").(int)),
Job: d.Get("job").(string),
Target: d.Get("target").(string),
Frequency: int64(d.Get("frequency").(int)),
Timeout: int64(d.Get("timeout").(int)),
Timeout: timeout,
Enabled: d.Get("enabled").(bool),
AlertSensitivity: d.Get("alert_sensitivity").(string),
BasicMetricsOnly: d.Get("basic_metrics_only").(bool),
Expand Down
2 changes: 2 additions & 0 deletions internal/resources/syntheticmonitoring/resource_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestAccResourceCheck_dns(t *testing.T) {
resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.dns", "tenant_id"),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.dns", "job", jobName),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.dns", "target", "grafana.com"),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.dns", "timeout", "3000"), // default
resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.dns", "probes.0"),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.dns", "labels.foo", "bar"),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.dns", "settings.0.dns.0.ip_version", "V4"),
Expand Down Expand Up @@ -300,6 +301,7 @@ func TestAccResourceCheck_multihttp(t *testing.T) {
resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.multihttp", "tenant_id"),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.multihttp", "job", jobName),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.multihttp", "target", "https://www.grafana-dev.com"),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.multihttp", "timeout", "5000"), // multihttp has a default timeout of 5000
resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.multihttp", "probes.0"),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.multihttp", "labels.foo", "bar"),
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.multihttp", "settings.0.multihttp.0.entries.0.request.0.method", "GET"),
Expand Down

0 comments on commit 2216fb2

Please sign in to comment.