Skip to content

Commit 6c40082

Browse files
authored
Merge pull request #458 from SumoLogic/SUMO-203323-terraform-minDataPoints-field
Sumo 203323 terraform min data points field
2 parents bf7d2d1 + 8d731ae commit 6c40082

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
## 2.20.1 (Unreleased)
22
FEATURES:
33
* **New Resource:** sumologic_cse_first_seen_rule (GH-476)
4+
* Add new optional `min_data_points` field to metrics monitor trigger_conditions (GH-464)
45

56
BUG FIXES:
67
* Added validations to fail if no trigger conditions defined in monitor resource (GH-463)
7-
8+
89
## 2.20.0 (December 15, 2022)
910
FEATURES:
1011
* **New Resource:** sumologic_cse_custom_match_list_column (GH-462)
1112

1213
BUG FIXES:
1314
* Fix typo on cse_match_list documentation (GH-461)
1415

16+
1517
## 2.19.2 (November 4, 2022)
1618
ENHANCEMENTS:
1719
* Suppress diffs for equivalent values of some time attributes. This should reduce output of `terraform plan` that didn't disappear after running `terraform apply`. (GH-442)

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
120120
Optional: true,
121121
ValidateFunc: validation.StringInSlice([]string{"AtLeastOnce", "Always", "ResultCount", "MissingData"}, false),
122122
},
123+
"min_data_points": {
124+
Type: schema.TypeInt,
125+
Optional: true,
126+
ValidateFunc: validation.IntBetween(1, 100),
127+
Computed: true,
128+
},
123129
"detection_method": {
124130
Type: schema.TypeString,
125131
Optional: true,
@@ -446,26 +452,30 @@ var metricsStaticTriggerConditionSchema = map[string]*schema.Schema{
446452
"time_range": &timeRangeSchema,
447453
"occurrence_type": &occurrenceTypeSchema,
448454
"alert": nested(false, schemaMap{
449-
"threshold": &thresholdSchema,
450-
"threshold_type": &thresholdTypeSchema,
455+
"threshold": &thresholdSchema,
456+
"threshold_type": &thresholdTypeSchema,
457+
"min_data_points": &minDataPointsOptSchema,
451458
}),
452459
"resolution": nested(false, schemaMap{
453460
"threshold": &thresholdSchema,
454461
"threshold_type": &thresholdTypeSchema,
455462
"occurrence_type": &occurrenceTypeOptSchema,
463+
"min_data_points": &minDataPointsOptSchema,
456464
}),
457465
}, metricsStaticConditionCriticalOrWarningAtleastOneKeys),
458466
"warning": nestedWithAtleastOneOfKeys(true, schemaMap{
459467
"time_range": &timeRangeSchema,
460468
"occurrence_type": &occurrenceTypeSchema,
461469
"alert": nested(false, schemaMap{
462-
"threshold": &thresholdSchema,
463-
"threshold_type": &thresholdTypeSchema,
470+
"threshold": &thresholdSchema,
471+
"threshold_type": &thresholdTypeSchema,
472+
"min_data_points": &minDataPointsOptSchema,
464473
}),
465474
"resolution": nested(false, schemaMap{
466475
"threshold": &thresholdSchema,
467476
"threshold_type": &thresholdTypeSchema,
468477
"occurrence_type": &occurrenceTypeOptSchema,
478+
"min_data_points": &minDataPointsOptSchema,
469479
}),
470480
}, metricsStaticConditionCriticalOrWarningAtleastOneKeys),
471481
}
@@ -569,6 +579,13 @@ var occurrenceTypeOptSchema = schema.Schema{
569579
ValidateFunc: validation.StringInSlice([]string{"AtLeastOnce", "Always"}, false),
570580
}
571581

582+
var minDataPointsOptSchema = schema.Schema{
583+
Type: schema.TypeInt,
584+
Optional: true,
585+
Computed: true,
586+
ValidateFunc: validation.IntBetween(1, 100),
587+
}
588+
572589
var windowSchema = schema.Schema{
573590
Type: schema.TypeInt,
574591
Optional: true,
@@ -763,6 +780,7 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
763780
"threshold": t.Threshold,
764781
"threshold_type": t.ThresholdType,
765782
"occurrence_type": t.OccurrenceType,
783+
"min_data_points": t.MinDataPoints,
766784
"trigger_source": t.TriggerSource,
767785
"detection_method": t.DetectionMethod,
768786
"resolution_window": t.PositiveResolutionWindow(),
@@ -921,6 +939,7 @@ func getTriggers(d *schema.ResourceData) []TriggerCondition {
921939
TimeRange: triggerDict["time_range"].(string),
922940
OccurrenceType: triggerDict["occurrence_type"].(string),
923941
TriggerSource: triggerDict["trigger_source"].(string),
942+
MinDataPoints: triggerDict["min_data_points"].(int),
924943
DetectionMethod: triggerDict["detection_method"].(string),
925944
ResolutionWindow: triggerDict["resolution_window"].(string),
926945
}
@@ -1167,11 +1186,13 @@ func jsonToMetricsStaticConditionBlock(conditions []TriggerCondition) map[string
11671186
hasCritical = true
11681187
criticalDict["time_range"] = condition.PositiveTimeRange()
11691188
criticalDict["occurrence_type"] = condition.OccurrenceType
1189+
criticalAlrt["min_data_points"] = condition.MinDataPoints
11701190
criticalAlrt["threshold"] = condition.Threshold
11711191
criticalAlrt["threshold_type"] = condition.ThresholdType
11721192
case "ResolvedCritical":
11731193
hasCritical = true
11741194
criticalDict["time_range"] = condition.PositiveTimeRange()
1195+
criticalRslv["min_data_points"] = condition.MinDataPoints
11751196
criticalRslv["threshold"] = condition.Threshold
11761197
criticalRslv["threshold_type"] = condition.ThresholdType
11771198
if condition.OccurrenceType == "AtLeastOnce" {
@@ -1183,15 +1204,17 @@ func jsonToMetricsStaticConditionBlock(conditions []TriggerCondition) map[string
11831204
hasWarning = true
11841205
warningDict["time_range"] = condition.PositiveTimeRange()
11851206
warningDict["occurrence_type"] = condition.OccurrenceType
1207+
warningAlrt["min_data_points"] = condition.MinDataPoints
11861208
warningAlrt["threshold"] = condition.Threshold
11871209
warningAlrt["threshold_type"] = condition.ThresholdType
11881210
case "ResolvedWarning":
11891211
hasWarning = true
11901212
warningDict["time_range"] = condition.PositiveTimeRange()
1213+
warningRslv["min_data_points"] = condition.MinDataPoints
11911214
warningRslv["threshold"] = condition.Threshold
11921215
warningRslv["threshold_type"] = condition.ThresholdType
11931216
if condition.OccurrenceType == "AtLeastOnce" {
1194-
criticalRslv["occurrence_type"] = condition.OccurrenceType
1217+
warningRslv["occurrence_type"] = condition.OccurrenceType
11951218
} else {
11961219
// otherwise, the canonical translation is to leave out occurrenceType in the Resolved block
11971220
}
@@ -1501,6 +1524,8 @@ func (condition *TriggerCondition) readFrom(block map[string]interface{}) {
15011524
condition.ThresholdType = v.(string)
15021525
case "occurrence_type":
15031526
condition.OccurrenceType = v.(string)
1527+
case "min_data_points":
1528+
condition.MinDataPoints = v.(int)
15041529
case "trigger_source":
15051530
condition.TriggerSource = v.(string)
15061531
case "detection_method":

sumologic/resource_sumologic_monitors_library_monitor_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,31 +1113,35 @@ var exampleLogsStaticTriggerConditionBlockWithResolutionWindow = `
11131113
var exampleMetricsStaticTriggerConditionBlock1 = `
11141114
metrics_static_condition {
11151115
critical {
1116-
time_range = "-30m"
1117-
occurrence_type = "AtLeastOnce"
1116+
time_range = "30m"
1117+
occurrence_type = "Always"
11181118
alert {
11191119
threshold = 100.0
11201120
threshold_type = "GreaterThan"
1121+
min_data_points = 4
11211122
}
11221123
resolution {
11231124
threshold = 90
11241125
threshold_type = "LessThanOrEqual"
1126+
min_data_points = 7
11251127
}
11261128
}
11271129
}`
11281130

11291131
var exampleMetricsStaticTriggerConditionBlock2 = `
11301132
metrics_static_condition {
11311133
critical {
1132-
time_range = "30m"
1134+
time_range = "60m"
11331135
occurrence_type = "Always"
11341136
alert {
11351137
threshold = 100.0
11361138
threshold_type = "GreaterThan"
1139+
min_data_points = 6
11371140
}
11381141
resolution {
11391142
threshold = 90
11401143
threshold_type = "LessThanOrEqual"
1144+
occurrence_type = "AtLeastOnce"
11411145
}
11421146
}
11431147
}`
@@ -1270,6 +1274,7 @@ func exampleMetricsStaticTriggerCondition(triggerType string, threshold float64,
12701274
Threshold: threshold,
12711275
ThresholdType: thresholdType,
12721276
OccurrenceType: "Always",
1277+
MinDataPoints: 4,
12731278
DetectionMethod: "MetricsStaticCondition",
12741279
}
12751280
}

sumologic/sumologic_monitors_library_monitor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ type TriggerCondition struct {
162162
Threshold float64 `json:"threshold,omitempty"`
163163
ThresholdType string `json:"thresholdType,omitempty"`
164164
OccurrenceType string `json:"occurrenceType"`
165+
MinDataPoints int `json:"minDataPoints,omitempty"`
165166
TriggerSource string `json:"triggerSource"`
166167
DetectionMethod string `json:"detectionMethod"`
167168
ResolutionWindow string `json:"resolutionWindow,omitempty"`

website/docs/r/monitor.html.markdown

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ resource "sumologic_monitor" "tf_metrics_monitor_1" {
120120
metrics_static_condition {
121121
critical {
122122
time_range = "15m"
123-
occurrence_type = "AtLeastOnce"
123+
occurrence_type = "Always"
124124
alert {
125125
threshold = 40.0
126126
threshold_type = "GreaterThan"
127+
min_data_points = 5
127128
}
128129
resolution {
129130
threshold = 40.0
@@ -430,18 +431,22 @@ Here is a summary of arguments for each condition type (fields which are not mar
430431
- `alert` (Required)
431432
- `threshold`
432433
- `threshold_type`
434+
- `min_data_points` (Optional)
433435
- `resolution` (Required)
434436
- `threshold`
435437
- `threshold_type`
436-
- `warning`
438+
- `min_data_points` (Optional)
439+
- `warning`
437440
- `time_range` (Required) : Accepted format: Optional `-` sign followed by `<number>` followed by a `<time_unit>` character: `s` for seconds, `m` for minutes, `h` for hours, `d` for days. Examples: `30m`, `-12h`.
438441
- `occurrence_type` (Required)
439442
- `alert` (Required)
440443
- `threshold`
441444
- `threshold_type`
445+
- `min_data_points` (Optional)
442446
- `resolution` (Required)
443447
- `threshold`
444448
- `threshold_type`
449+
- `min_data_points` (Optional)
445450
#### logs_outlier_condition
446451
- `field`
447452
- `direction`

0 commit comments

Comments
 (0)