Skip to content

Commit b975978

Browse files
authored
Merge pull request #729 from SumoLogic/SUMO-253872_frequency-configurability-changes
SUMO-253872: Add frequency configurability field to LogsStaticCondition and LogsMissingDataCondition
2 parents a6c7436 + b1172bc commit b975978

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,10 @@ func getMonitorSchema() map[string]*schema.Schema {
251251
Optional: true,
252252
ValidateFunc: validation.StringInSlice([]string{"Critical", "Warning", "MissingData", "ResolvedCritical", "ResolvedWarning", "ResolvedMissingData"}, false),
253253
},
254-
"threshold": {
255-
Type: schema.TypeFloat,
256-
Optional: true,
257-
},
258-
"threshold_type": {
259-
Type: schema.TypeString,
260-
Optional: true,
261-
ValidateFunc: validation.StringInSlice([]string{"LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual"}, false),
262-
},
263-
"time_range": {
264-
Type: schema.TypeString,
265-
Optional: true,
266-
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^-?(\d)+[smhd]$`), "Time range must be in the format '-?\\d+[smhd]'. Examples: -15m, 1d, etc."),
267-
DiffSuppressFunc: SuppressEquivalentTimeDiff(false),
268-
},
254+
"threshold": &thresholdSchema,
255+
"threshold_type": &thresholdTypeSchema,
256+
"time_range": &timeRangeWithFormatSchema,
257+
"frequency": &frequencySchema,
269258
"trigger_source": {
270259
Type: schema.TypeString,
271260
Optional: true,
@@ -490,6 +479,7 @@ var logsStaticTriggerConditionSchema = map[string]*schema.Schema{
490479
},
491480
"critical": nestedWithAtleastOneOfKeys(true, schemaMap{
492481
"time_range": &timeRangeWithAllowedValuesSchema,
482+
"frequency": &frequencySchema,
493483
"alert": nested(false, schemaMap{
494484
"threshold": &thresholdSchema,
495485
"threshold_type": &thresholdTypeSchema,
@@ -502,6 +492,7 @@ var logsStaticTriggerConditionSchema = map[string]*schema.Schema{
502492
}, logStaticConditionCriticalOrWarningAtleastOneKeys),
503493
"warning": nestedWithAtleastOneOfKeys(true, schemaMap{
504494
"time_range": &timeRangeWithAllowedValuesSchema,
495+
"frequency": &frequencySchema,
505496
"alert": nested(false, schemaMap{
506497
"threshold": &thresholdSchema,
507498
"threshold_type": &thresholdTypeSchema,
@@ -587,6 +578,7 @@ var metricsOutlierTriggerConditionSchema = map[string]*schema.Schema{
587578

588579
var logsMissingDataTriggerConditionSchema = map[string]*schema.Schema{
589580
"time_range": &timeRangeWithAllowedValuesSchema,
581+
"frequency": &frequencySchema,
590582
}
591583

592584
var metricsMissingDataTriggerConditionSchema = map[string]*schema.Schema{
@@ -813,6 +805,12 @@ var thresholdTypeSchema = schema.Schema{
813805
ValidateFunc: validation.StringInSlice([]string{"LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual"}, false),
814806
}
815807

808+
var frequencySchema = schema.Schema{
809+
Type: schema.TypeString,
810+
Optional: true,
811+
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^(\d)+[smhd]`), "Frequency time must be in the format '\\d+[smhd]'. Examples: 1m, 2m, 10m, 20m, 1h"),
812+
}
813+
816814
func resourceSumologicMonitorsLibraryMonitorCreate(d *schema.ResourceData, meta interface{}) error {
817815
c := meta.(*Client)
818816

@@ -975,6 +973,7 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
975973
for i, t := range monitor.Triggers {
976974
triggers[i] = map[string]interface{}{
977975
"time_range": t.PositiveTimeRange(),
976+
"frequency": t.Frequency,
978977
"trigger_type": t.TriggerType,
979978
"threshold": t.Threshold,
980979
"threshold_type": t.ThresholdType,
@@ -1138,6 +1137,7 @@ func getTriggers(d *schema.ResourceData) []TriggerCondition {
11381137
Threshold: triggerDict["threshold"].(float64),
11391138
ThresholdType: triggerDict["threshold_type"].(string),
11401139
TimeRange: triggerDict["time_range"].(string),
1140+
Frequency: triggerDict["frequency"].(string),
11411141
OccurrenceType: triggerDict["occurrence_type"].(string),
11421142
TriggerSource: triggerDict["trigger_source"].(string),
11431143
MinDataPoints: triggerDict["min_data_points"].(int),
@@ -1244,11 +1244,13 @@ func metricsOutlierConditionBlockToJson(block map[string]interface{}) []TriggerC
12441244
func logsMissingDataConditionBlockToJson(block map[string]interface{}) []TriggerCondition {
12451245
alert := TriggerCondition{
12461246
TimeRange: block["time_range"].(string),
1247+
Frequency: block["frequency"].(string),
12471248
DetectionMethod: logsMissingDataConditionDetectionMethod,
12481249
TriggerType: "MissingData",
12491250
}
12501251
resolution := TriggerCondition{
12511252
TimeRange: block["time_range"].(string),
1253+
Frequency: block["frequency"].(string),
12521254
DetectionMethod: logsMissingDataConditionDetectionMethod,
12531255
TriggerType: "ResolvedMissingData",
12541256
}
@@ -1382,22 +1384,26 @@ func jsonToLogsStaticConditionBlock(conditions []TriggerCondition) map[string]in
13821384
case "Critical":
13831385
hasCritical = true
13841386
criticalDict["time_range"] = condition.PositiveTimeRange()
1387+
criticalDict["frequency"] = condition.Frequency
13851388
criticalAlrt["threshold"] = condition.Threshold
13861389
criticalAlrt["threshold_type"] = condition.ThresholdType
13871390
case "ResolvedCritical":
13881391
hasCritical = true
13891392
criticalDict["time_range"] = condition.PositiveTimeRange()
1393+
criticalDict["frequency"] = condition.Frequency
13901394
criticalRslv["threshold"] = condition.Threshold
13911395
criticalRslv["threshold_type"] = condition.ThresholdType
13921396
criticalRslv["resolution_window"] = condition.PositiveResolutionWindow()
13931397
case "Warning":
13941398
hasWarning = true
13951399
warningDict["time_range"] = condition.PositiveTimeRange()
1400+
warningDict["frequency"] = condition.Frequency
13961401
warningAlrt["threshold"] = condition.Threshold
13971402
warningAlrt["threshold_type"] = condition.ThresholdType
13981403
case "ResolvedWarning":
13991404
hasWarning = true
14001405
warningDict["time_range"] = condition.PositiveTimeRange()
1406+
warningDict["frequency"] = condition.Frequency
14011407
warningRslv["threshold"] = condition.Threshold
14021408
warningRslv["threshold_type"] = condition.ThresholdType
14031409
warningRslv["resolution_window"] = condition.PositiveResolutionWindow()
@@ -1690,6 +1696,7 @@ func jsonToLogsMissingDataConditionBlock(conditions []TriggerCondition) map[stri
16901696
block := map[string]interface{}{}
16911697
firstCondition := conditions[0]
16921698
block["time_range"] = firstCondition.PositiveTimeRange()
1699+
block["frequency"] = firstCondition.Frequency
16931700
return block
16941701
}
16951702

@@ -1842,6 +1849,8 @@ func (condition *TriggerCondition) readFrom(block map[string]interface{}) {
18421849
switch k {
18431850
case "time_range":
18441851
condition.TimeRange = v.(string)
1852+
case "frequency":
1853+
condition.Frequency = v.(string)
18451854
case "trigger_type":
18461855
condition.TriggerType = v.(string)
18471856
case "threshold":

sumologic/resource_sumologic_monitors_library_monitor_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func TestAccSumologicMonitorsLibraryMonitor_schemaTriggerValidations(t *testing.
114114
type = "MonitorsLibraryMonitor"
115115
monitor_type = "Logs"
116116
triggers {
117+
time_range = "1h"
117118
threshold_type = "foo"
118119
}
119120
}`
@@ -1306,6 +1307,7 @@ var exampleLogsStaticTriggerConditionBlock = `
13061307
logs_static_condition {
13071308
critical {
13081309
time_range = "60m"
1310+
frequency = "5m"
13091311
alert {
13101312
threshold = 100.0
13111313
threshold_type = "GreaterThan"
@@ -1322,6 +1324,7 @@ var exampleLogsStaticTriggerConditionBlockWithResolutionWindow = `
13221324
logs_static_condition {
13231325
critical {
13241326
time_range = "1h"
1327+
frequency = "5m"
13251328
alert {
13261329
threshold = 100.0
13271330
threshold_type = "GreaterThan"

sumologic/sumologic_monitors_library_monitor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ type MonitorQuery struct {
160160

161161
type TriggerCondition struct {
162162
TimeRange string `json:"timeRange,omitempty"`
163+
Frequency string `json:"frequency,omitempty"`
163164
TriggerType string `json:"triggerType"`
164165
Threshold float64 `json:"threshold,omitempty"`
165166
ThresholdType string `json:"thresholdType,omitempty"`

0 commit comments

Comments
 (0)