Skip to content

Commit 51ac037

Browse files
committed
Move sensitivity under trigger object
1 parent 61f7571 commit 51ac037

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,13 @@ var logsAnomalyTriggerConditionSchema = map[string]*schema.Schema{
635635
Required: true,
636636
ValidateFunc: validation.StringInSlice([]string{"Cluster"}, false),
637637
},
638-
"sensitivity": {
639-
Type: schema.TypeFloat,
640-
Optional: true,
641-
Default: 0.5,
642-
},
643638
"critical": nested(false, schemaMap{
639+
"sensitivity": {
640+
Type: schema.TypeFloat,
641+
Optional: true,
642+
Default: 0.5,
643+
ValidateFunc: validation.FloatBetween(0.1, 1.0),
644+
},
644645
"min_anomaly_count": {
645646
Type: schema.TypeInt,
646647
Optional: true,
@@ -978,6 +979,7 @@ func resourceSumologicMonitorsLibraryMonitorUpdate(d *schema.ResourceData, meta
978979
monitor = *updatedMonitor
979980
}
980981
monitor.Type = "MonitorsLibraryMonitorUpdate"
982+
log.Printf("updating monitor: %+v\n", monitor)
981983
err := c.UpdateMonitorsLibraryMonitor(monitor)
982984
if err != nil {
983985
return err
@@ -1253,7 +1255,6 @@ func logsAnomalyConditionBlockToJson(block map[string]interface{}) []TriggerCond
12531255
Field: block["field"].(string),
12541256
Direction: block["direction"].(string),
12551257
AnomalyDetectorType: block["anomaly_detector_type"].(string),
1256-
Sensitivity: block["sensitivity"].(float64),
12571258
DetectionMethod: logsAnomalyConditionDetectionMethod,
12581259
}
12591260
// log anomaly condition does not have 'alert' and 'resolution' objects. Here we generate empty blocks
@@ -1554,7 +1555,6 @@ func jsonToLogsAnomalyConditionBlock(conditions []TriggerCondition) map[string]i
15541555
block["field"] = conditions[0].Field
15551556
block["direction"] = conditions[0].Direction
15561557
block["anomaly_detector_type"] = conditions[0].AnomalyDetectorType
1557-
block["sensitivity"] = conditions[0].Sensitivity
15581558

15591559
var criticalDict = dict{}
15601560
block["critical"] = toSingletonArray(criticalDict)
@@ -1564,10 +1564,12 @@ func jsonToLogsAnomalyConditionBlock(conditions []TriggerCondition) map[string]i
15641564
switch condition.TriggerType {
15651565
case "Critical":
15661566
hasCritical = true
1567+
criticalDict["sensitivity"] = condition.Sensitivity
15671568
criticalDict["min_anomaly_count"] = condition.MinAnomalyCount
15681569
criticalDict["time_range"] = condition.PositiveTimeRange()
15691570
case "ResolvedCritical":
15701571
hasCritical = true
1572+
criticalDict["sensitivity"] = condition.Sensitivity
15711573
criticalDict["min_anomaly_count"] = condition.MinAnomalyCount
15721574
criticalDict["time_range"] = condition.PositiveTimeRange()
15731575
}
@@ -1817,7 +1819,9 @@ func (base TriggerCondition) cloneReadingFromNestedBlocks(block map[string]inter
18171819

18181820
if criticalCondition.DetectionMethod == logsAnomalyConditionDetectionMethod {
18191821
criticalCondition.MinAnomalyCount = critical["min_anomaly_count"].(int)
1822+
criticalCondition.Sensitivity = critical["sensitivity"].(float64)
18201823
resolvedCriticalCondition.MinAnomalyCount = criticalCondition.MinAnomalyCount
1824+
resolvedCriticalCondition.Sensitivity = criticalCondition.Sensitivity
18211825
}
18221826

18231827
if alert, ok := fromSingletonArray(critical, "alert"); ok {
@@ -1827,6 +1831,8 @@ func (base TriggerCondition) cloneReadingFromNestedBlocks(block map[string]inter
18271831
resolvedCriticalCondition.readFrom(resolved)
18281832
}
18291833
conditions = append(conditions, criticalCondition, resolvedCriticalCondition)
1834+
fmt.Printf("##DEBUG## [cloneReadingFromNestedBlocks] criticalCondition: %+v\n", criticalCondition)
1835+
fmt.Printf("##DEBUG## [cloneReadingFromNestedBlocks] resolvedCriticalCondition: %+v\n", resolvedCriticalCondition)
18301836
}
18311837
if warning, ok := fromSingletonArray(block, "warning"); ok {
18321838
warningCondition.readFrom(warning)

sumologic/resource_sumologic_monitors_library_monitor_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,12 +1426,12 @@ var exampleSloBurnRateTriggerConditionBlock = `
14261426
var exampleLogsAnomalyTriggerConditionBlock = `
14271427
logs_anomaly_condition {
14281428
field = "_count"
1429-
sensitivity = 0.5
1430-
anomaly_detector_type = "Cluster"
1431-
critical {
1432-
min_anomaly_count = 5
1433-
time_range = "-1h"
1434-
}
1429+
anomaly_detector_type = "Cluster"
1430+
critical {
1431+
sensitivity = 0.5
1432+
min_anomaly_count = 5
1433+
time_range = "-1h"
1434+
}
14351435
}`
14361436

14371437
func exampleLogsStaticMonitor(testName string) string {

website/docs/r/monitor.html.markdown

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ resource "sumologic_monitor" "tf_example_anomaly_monitor" {
351351
trigger_conditions {
352352
logs_anomaly_condition {
353353
field = "_count"
354-
sensitivity = 0.4
355354
anomaly_detector_type = "Cluster"
356355
critical {
356+
sensitivity = 0.4
357357
min_anomaly_count = 9
358358
time_range = "-3h"
359359
}
@@ -372,7 +372,6 @@ resource "sumologic_monitor" "tf_example_anomaly_monitor" {
372372
}
373373
run_for_trigger_types = ["Critical", "ResolvedCritical"]
374374
}
375-
376375
}
377376
```
378377

@@ -574,9 +573,9 @@ Here is a summary of arguments for each condition type (fields which are not mar
574573

575574
#### log_anomaly_condition
576575
- `field`: The name of the field that the trigger condition will alert on. The trigger could compare the value of specified field with the threshold. If field is not specified, monitor would default to result count instead.
577-
- `sensitivity`: The triggering sensitivity of the anomaly model used for this monitor.
578576
- `anomaly_detector_type`: The type of anomaly model that will be used for evaluating this monitor. Possible values are: `Cluster`.
579577
- `critical`
578+
- `sensitivity`: The triggering sensitivity of the anomaly model used for this monitor.
580579
- `min_anomaly_count` (Required) : The minimum number of anomalies required to exist in the current time range for the condition to trigger.
581580
- `time_range` (Required) : The relative time range for anomaly evaluation. 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`.
582581

0 commit comments

Comments
 (0)