Skip to content

Commit 01204c5

Browse files
Add http compression option to synthetic monitoring check resource (#1923)
1 parent 5cf4e52 commit 01204c5

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

docs/resources/synthetic_monitoring_check.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ resource "grafana_synthetic_monitoring_check" "http" {
147147
proxy_url = "https://almost-there"
148148
fail_if_ssl = true
149149
fail_if_not_ssl = true
150+
compression = "deflate"
150151
cache_busting_query_param_name = "pineapple"
151152
152153
tls_config {
@@ -522,6 +523,7 @@ Optional:
522523
- `bearer_token` (String, Sensitive) Token for use with bearer authorization header.
523524
- `body` (String) The body of the HTTP request used in probe.
524525
- `cache_busting_query_param_name` (String) The name of the query parameter used to prevent the server from using a cached response. Each probe will assign a random value to this parameter each time a request is made.
526+
- `compression` (String) Check fails if the response body is not compressed using this compression algorithm. One of `none`, `identity`, `br`, `gzip`, `deflate`.
525527
- `fail_if_body_matches_regexp` (Set of String) List of regexes. If any match the response body, the check will fail.
526528
- `fail_if_body_not_matches_regexp` (Set of String) List of regexes. If any do not match the response body, the check will fail.
527529
- `fail_if_header_matches_regexp` (Block Set) Check fails if headers match. (see [below for nested schema](#nestedblock--settings--http--fail_if_header_matches_regexp))

examples/resources/grafana_synthetic_monitoring_check/http_complex.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resource "grafana_synthetic_monitoring_check" "http" {
2121
proxy_url = "https://almost-there"
2222
fail_if_ssl = true
2323
fail_if_not_ssl = true
24+
compression = "deflate"
2425
cache_busting_query_param_name = "pineapple"
2526

2627
tls_config {

internal/resources/syntheticmonitoring/resource_check.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"maps"
8+
"slices"
79
"strconv"
810
"strings"
911

@@ -341,6 +343,12 @@ var (
341343
Optional: true,
342344
Elem: syntheticMonitoringCheckSettingsHTTPHeaderMatch,
343345
},
346+
"compression": {
347+
Description: "Check fails if the response body is not compressed using this compression algorithm. One of `none`, `identity`, `br`, `gzip`, `deflate`.",
348+
Type: schema.TypeString,
349+
Optional: true,
350+
ValidateFunc: validation.StringInSlice(slices.Collect(maps.Keys(sm.CompressionAlgorithm_value)), false),
351+
},
344352
"cache_busting_query_param_name": {
345353
Description: "The name of the query parameter used to prevent the server from using a cached response. Each probe will assign a random value to this parameter each time a request is made.",
346354
Type: schema.TypeString,
@@ -936,6 +944,12 @@ func resourceCheckRead(ctx context.Context, d *schema.ResourceData, c *smapi.Cli
936944
},
937945
)
938946
}
947+
// The default compression "none" is the same as omitting the value.
948+
// Since this value is usually not explicitly set, omit when set to "none"
949+
var compression string
950+
if chk.Settings.Http.Compression != sm.CompressionAlgorithm_none {
951+
compression = chk.Settings.Http.Compression.String()
952+
}
939953
headerMatch := func(hms []sm.HeaderMatch) *schema.Set {
940954
hmSet := schema.NewSet(
941955
schema.HashResource(syntheticMonitoringCheckSettingsTCPQueryResponse),
@@ -969,6 +983,7 @@ func resourceCheckRead(ctx context.Context, d *schema.ResourceData, c *smapi.Cli
969983
"fail_if_body_not_matches_regexp": common.StringSliceToSet(chk.Settings.Http.FailIfBodyNotMatchesRegexp),
970984
"fail_if_header_matches_regexp": headerMatch(chk.Settings.Http.FailIfHeaderMatchesRegexp),
971985
"fail_if_header_not_matches_regexp": headerMatch(chk.Settings.Http.FailIfHeaderNotMatchesRegexp),
986+
"compression": compression,
972987
"cache_busting_query_param_name": chk.Settings.Http.CacheBustingQueryParamName,
973988
})
974989

@@ -1475,6 +1490,10 @@ func makeCheckSettings(settings map[string]interface{}) (sm.CheckSettings, error
14751490
FailIfBodyNotMatchesRegexp: common.SetToStringSlice(h["fail_if_body_not_matches_regexp"].(*schema.Set)),
14761491
CacheBustingQueryParamName: h["cache_busting_query_param_name"].(string),
14771492
}
1493+
compression, ok := h["compression"].(string)
1494+
if ok {
1495+
cs.Http.Compression = sm.CompressionAlgorithm(sm.CompressionAlgorithm_value[compression])
1496+
}
14781497
if h["tls_config"].(*schema.Set).Len() > 0 {
14791498
cs.Http.TlsConfig = tlsConfig(h["tls_config"].(*schema.Set))
14801499
}

internal/resources/syntheticmonitoring/resource_check_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func TestAccResourceCheck_http(t *testing.T) {
124124
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.bearer_token", "asdfjkl;"),
125125
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.proxy_url", "https://almost-there"),
126126
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.fail_if_ssl", "true"),
127+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.compression", "deflate"),
127128
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.cache_busting_query_param_name", "pineapple"),
128129
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.tls_config.0.server_name", "grafana.org"),
129130
resource.TestMatchResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.tls_config.0.client_cert", regexp.MustCompile((`^-{5}BEGIN CERTIFICATE`))),

0 commit comments

Comments
 (0)