Skip to content

Commit 6103c5e

Browse files
authored
Merge pull request #437 from SumoLogic/feature/SUMO-191578-monitor-configurable-resolution-window-support
SUMO-191578, made resolution window a optional field and added test c…
2 parents 34d00d8 + 3dc3756 commit 6103c5e

File tree

3 files changed

+113
-8
lines changed

3 files changed

+113
-8
lines changed

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
127127
"LogsMissingDataCondition", "MetricsMissingDataCondition", "SloSliCondition",
128128
"SloBurnRateCondition"}, false),
129129
},
130-
"resolution_window": {
131-
Type: schema.TypeString,
132-
Optional: true,
133-
ValidateFunc: validation.StringMatch(regexp.MustCompile(`-?(\d)+[smhd]`), "Time range must be in the format '-?\\d+[smhd]'. Examples: -15m, 1d, etc."),
134-
},
130+
"resolution_window": &resolutionWindowSchema,
135131
},
136132
},
137133
},
@@ -388,7 +384,7 @@ var logsStaticTriggerConditionSchema = map[string]*schema.Schema{
388384
"resolution": nested(false, schemaMap{
389385
"threshold": &thresholdSchema,
390386
"threshold_type": &thresholdTypeSchema,
391-
"resolution_window": &timeRangeSchema,
387+
"resolution_window": &resolutionWindowSchema,
392388
}),
393389
}),
394390
"warning": nested(true, schemaMap{
@@ -400,7 +396,7 @@ var logsStaticTriggerConditionSchema = map[string]*schema.Schema{
400396
"resolution": nested(false, schemaMap{
401397
"threshold": &thresholdSchema,
402398
"threshold_type": &thresholdTypeSchema,
403-
"resolution_window": &timeRangeSchema,
399+
"resolution_window": &resolutionWindowSchema,
404400
}),
405401
}),
406402
}
@@ -556,6 +552,12 @@ var timeRangeSchema = schema.Schema{
556552
ValidateFunc: validation.StringMatch(regexp.MustCompile(`-?(\d)+[smhd]`), "Time range must be in the format '-?\\d+[smhd]'. Examples: -15m, 1d, etc."),
557553
}
558554

555+
var resolutionWindowSchema = schema.Schema{
556+
Type: schema.TypeString,
557+
Optional: true,
558+
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^(\d)+[smhd]`), "Resolution window must be in the format '\\d+[smhd]'. Examples: 0m, 15m, 1d, etc."),
559+
}
560+
559561
var thresholdSchema = schema.Schema{
560562
Type: schema.TypeFloat,
561563
Optional: true,

sumologic/resource_sumologic_monitors_library_monitor_test.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,49 @@ func TestAccSumologicMonitorsLibraryMonitor_create(t *testing.T) {
225225
})
226226
}
227227

228+
func TestAccSumologicMonitorsLibraryMonitor_create_with_no_resolution_window(t *testing.T) {
229+
var monitorsLibraryMonitor MonitorsLibraryMonitor
230+
testNameSuffix := acctest.RandString(16)
231+
232+
testTriggers := []TriggerCondition{
233+
{
234+
ThresholdType: "GreaterThan",
235+
Threshold: 40.0,
236+
TimeRange: "15m",
237+
OccurrenceType: "ResultCount",
238+
TriggerSource: "AllResults",
239+
TriggerType: "Critical",
240+
DetectionMethod: "StaticCondition",
241+
},
242+
{
243+
ThresholdType: "LessThanOrEqual",
244+
Threshold: 40.0,
245+
TimeRange: "15m",
246+
OccurrenceType: "ResultCount",
247+
TriggerSource: "AllResults",
248+
TriggerType: "ResolvedCritical",
249+
DetectionMethod: "StaticCondition",
250+
},
251+
}
252+
253+
resource.Test(t, resource.TestCase{
254+
PreCheck: func() { testAccPreCheck(t) },
255+
Providers: testAccProviders,
256+
CheckDestroy: testAccCheckMonitorsLibraryMonitorDestroy(monitorsLibraryMonitor),
257+
Steps: []resource.TestStep{
258+
{
259+
Config: testAccSumologicMonitorsLibraryMonitorWithNoResolutionWindow(testNameSuffix),
260+
Check: resource.ComposeTestCheckFunc(
261+
testAccCheckMonitorsLibraryMonitorExists("sumologic_monitor.test", &monitorsLibraryMonitor, t),
262+
testAccCheckMonitorsLibraryMonitorAttributes("sumologic_monitor.test"),
263+
resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.trigger_type", testTriggers[0].TriggerType),
264+
resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.time_range", testTriggers[0].TimeRange),
265+
),
266+
},
267+
},
268+
})
269+
}
270+
228271
func TestAccSumologicMonitorsLibraryMonitor_create_all_monitor_types(t *testing.T) {
229272
var monitorsLibraryMonitor MonitorsLibraryMonitor
230273
for _, monitorConfig := range allExampleMonitors {
@@ -731,6 +774,43 @@ resource "sumologic_role" "tf_test_role_03" {
731774
}`, testName, testName, testName, testName)
732775
}
733776

777+
func testAccSumologicMonitorsLibraryMonitorWithNoResolutionWindow(testName string) string {
778+
return fmt.Sprintf(`
779+
resource "sumologic_monitor" "test" {
780+
name = "terraform_test_monitor_%s"
781+
description = "terraform_test_monitor_description"
782+
type = "MonitorsLibraryMonitor"
783+
is_disabled = false
784+
content_type = "Monitor"
785+
monitor_type = "Logs"
786+
evaluation_delay = "5m"
787+
queries {
788+
row_id = "A"
789+
query = "_sourceCategory=monitor-manager error"
790+
}
791+
triggers {
792+
threshold_type = "GreaterThan"
793+
threshold = 40.0
794+
time_range = "15m"
795+
occurrence_type = "ResultCount"
796+
trigger_source = "AllResults"
797+
trigger_type = "Critical"
798+
detection_method = "StaticCondition"
799+
}
800+
triggers {
801+
threshold_type = "LessThanOrEqual"
802+
threshold = 40.0
803+
time_range = "15m"
804+
occurrence_type = "ResultCount"
805+
trigger_source = "AllResults"
806+
trigger_type = "ResolvedCritical"
807+
detection_method = "StaticCondition"
808+
}
809+
playbook = "This is a test playbook"
810+
alert_name = "Alert from {{Name}}"
811+
}`, testName)
812+
}
813+
734814
func testAccSumologicMonitorsLibraryMonitorUpdate(testName string) string {
735815
return fmt.Sprintf(`
736816
resource "sumologic_monitor" "test" {
@@ -958,6 +1038,22 @@ resource "sumologic_monitor" "test" {
9581038
}
9591039

9601040
var exampleLogsStaticTriggerConditionBlock = `
1041+
logs_static_condition {
1042+
critical {
1043+
time_range = "30m"
1044+
alert {
1045+
threshold = 100.0
1046+
threshold_type = "GreaterThan"
1047+
}
1048+
resolution {
1049+
threshold = 90
1050+
threshold_type = "LessThanOrEqual"
1051+
}
1052+
}
1053+
field = "field"
1054+
}`
1055+
1056+
var exampleLogsStaticTriggerConditionBlockWithResolutionWindow = `
9611057
logs_static_condition {
9621058
critical {
9631059
time_range = "30m"
@@ -1043,6 +1139,12 @@ func exampleLogsStaticMonitor(testName string) string {
10431139
exampleLogsStaticTriggerConditionBlock, []string{"Critical", "ResolvedCritical"})
10441140
}
10451141

1142+
func exampleLogsStaticMonitorWithResolutionWindow(testName string) string {
1143+
query := "error | timeslice 1m | count as field by _timeslice"
1144+
return exampleMonitorWithTriggerCondition(testName, "Logs", query,
1145+
exampleLogsStaticTriggerConditionBlockWithResolutionWindow, []string{"Critical", "ResolvedCritical"})
1146+
}
1147+
10461148
func exampleMetricsStaticMonitor1(testName string) string {
10471149
query := "error _sourceCategory=category"
10481150
return exampleMonitorWithTriggerCondition(testName, "Metrics", query,
@@ -1081,6 +1183,7 @@ func exampleMetricsMissingDataMonitor(testName string) string {
10811183

10821184
var allExampleMonitors = []func(testName string) string{
10831185
exampleLogsStaticMonitor,
1186+
exampleLogsStaticMonitorWithResolutionWindow,
10841187
exampleMetricsStaticMonitor1,
10851188
exampleMetricsStaticMonitor2,
10861189
exampleLogsOutlierMonitor,

sumologic/sumologic_monitors_library_monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (s *Client) CreateMonitorsLibraryMonitor(monitorsLibraryMonitor MonitorsLib
2525
if err != nil {
2626
return "", err
2727
}
28-
28+
2929
var createdMonitorsLibraryMonitor MonitorsLibraryMonitor
3030

3131
err = json.Unmarshal(data, &createdMonitorsLibraryMonitor)

0 commit comments

Comments
 (0)