Skip to content

Commit 7d76c91

Browse files
authored
Merge pull request #344 from SumoLogic/accept-atleast-once-resolutions
Accept AtLeastOnce resolution conditions
2 parents abcbd5f + ca9c2da commit 7d76c91

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
ENHANCEMENTS:
44
* Add support for importing folder resource (GH-345)
5+
* Allow AtLeastOnce resolution conditions for Metrics monitors (GH-346)
56

67
## 2.12.0 (February 7, 2022)
78

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,9 @@ var metricsStaticTriggerConditionSchema = map[string]*schema.Schema{
368368
"threshold_type": &thresholdTypeSchema,
369369
}),
370370
"resolution": nested(false, schemaMap{
371-
"threshold": &thresholdSchema,
372-
"threshold_type": &thresholdTypeSchema,
371+
"threshold": &thresholdSchema,
372+
"threshold_type": &thresholdTypeSchema,
373+
"occurrence_type": &occurrenceTypeOptSchema,
373374
}),
374375
}),
375376
"warning": nested(true, schemaMap{
@@ -380,8 +381,9 @@ var metricsStaticTriggerConditionSchema = map[string]*schema.Schema{
380381
"threshold_type": &thresholdTypeSchema,
381382
}),
382383
"resolution": nested(false, schemaMap{
383-
"threshold": &thresholdSchema,
384-
"threshold_type": &thresholdTypeSchema,
384+
"threshold": &thresholdSchema,
385+
"threshold_type": &thresholdTypeSchema,
386+
"occurrence_type": &occurrenceTypeOptSchema,
385387
}),
386388
}),
387389
}
@@ -443,6 +445,12 @@ var occurrenceTypeSchema = schema.Schema{
443445
ValidateFunc: validation.StringInSlice([]string{"AtLeastOnce", "Always"}, false),
444446
}
445447

448+
var occurrenceTypeOptSchema = schema.Schema{
449+
Type: schema.TypeString,
450+
Optional: true,
451+
ValidateFunc: validation.StringInSlice([]string{"AtLeastOnce", "Always"}, false),
452+
}
453+
446454
var windowSchema = schema.Schema{
447455
Type: schema.TypeInt,
448456
Optional: true,
@@ -767,7 +775,8 @@ func metricsStaticConditionBlockToJson(block map[string]interface{}) []TriggerCo
767775
}
768776
triggerConditions := base.cloneReadingFromNestedBlocks(block)
769777
for i, _ := range triggerConditions {
770-
if triggerConditions[i].TriggerType == "ResolvedCritical" || triggerConditions[i].TriggerType == "ResolvedWarning" {
778+
if (triggerConditions[i].TriggerType == "ResolvedCritical" && triggerConditions[i].OccurrenceType == "") ||
779+
(triggerConditions[i].TriggerType == "ResolvedWarning" && triggerConditions[i].OccurrenceType == "") {
771780
triggerConditions[i].OccurrenceType = "Always"
772781
}
773782
}
@@ -943,6 +952,11 @@ func jsonToMetricsStaticConditionBlock(conditions []TriggerCondition) map[string
943952
criticalDict["time_range"] = condition.PositiveTimeRange()
944953
criticalRslv["threshold"] = condition.Threshold
945954
criticalRslv["threshold_type"] = condition.ThresholdType
955+
if condition.OccurrenceType == "AtLeastOnce" {
956+
criticalRslv["occurrence_type"] = condition.OccurrenceType
957+
} else {
958+
// otherwise, the canonical translation is to leave out occurrenceType in the Resolved block
959+
}
946960
case "Warning":
947961
hasWarning = true
948962
warningDict["time_range"] = condition.PositiveTimeRange()
@@ -954,6 +968,11 @@ func jsonToMetricsStaticConditionBlock(conditions []TriggerCondition) map[string
954968
warningDict["time_range"] = condition.PositiveTimeRange()
955969
warningRslv["threshold"] = condition.Threshold
956970
warningRslv["threshold_type"] = condition.ThresholdType
971+
if condition.OccurrenceType == "AtLeastOnce" {
972+
criticalRslv["occurrence_type"] = condition.OccurrenceType
973+
} else {
974+
// otherwise, the canonical translation is to leave out occurrenceType in the Resolved block
975+
}
957976
}
958977
}
959978
if !hasCritical {
@@ -1210,6 +1229,11 @@ func (base TriggerCondition) cloneReadingFromNestedBlocks(block map[string]inter
12101229
if critical, ok := fromSingletonArray(block, "critical"); ok {
12111230
criticalCondition.readFrom(critical)
12121231
resolvedCriticalCondition.readFrom(critical)
1232+
if resolvedCriticalCondition.DetectionMethod == metricsStaticConditionDetectionMethod {
1233+
// do not inherit the top-level occurrence type into resolution blocks for MetricsStaticConditions
1234+
// we want the caller to be able to tell whether the resolution block had set its own occurrence type
1235+
resolvedCriticalCondition.OccurrenceType = ""
1236+
}
12131237
if alert, ok := fromSingletonArray(critical, "alert"); ok {
12141238
criticalCondition.readFrom(alert)
12151239
}
@@ -1221,6 +1245,11 @@ func (base TriggerCondition) cloneReadingFromNestedBlocks(block map[string]inter
12211245
if warning, ok := fromSingletonArray(block, "warning"); ok {
12221246
warningCondition.readFrom(warning)
12231247
resolvedWarningCondition.readFrom(warning)
1248+
if resolvedCriticalCondition.DetectionMethod == metricsStaticConditionDetectionMethod {
1249+
// do not inherit the top-level occurrence type into resolution blocks for MetricsStaticConditions
1250+
// we want the caller to be able to tell whether the resolution block had set its own occurrence type
1251+
resolvedCriticalCondition.OccurrenceType = ""
1252+
}
12241253
if alert, ok := fromSingletonArray(warning, "alert"); ok {
12251254
warningCondition.readFrom(alert)
12261255
}

0 commit comments

Comments
 (0)