diff --git a/chronosphere/intschema/generateintschema/main.go b/chronosphere/intschema/generateintschema/main.go index 9b604fb..5a25eb5 100644 --- a/chronosphere/intschema/generateintschema/main.go +++ b/chronosphere/intschema/generateintschema/main.go @@ -57,7 +57,7 @@ var sharedSchemaTypeNames = map[*schema.Schema]string{ tfschema.TraceTagFilterSchema: "TraceTagFilter", tfschema.ValueMappingsSchema: "ValueMappings", tfschema.SLOAdditionalPromQLFilters: "SLOAdditionalPromQLFilters", - tfschema.MonitorSignalGrouping: "MonitorSignalGrouping", + tfschema.SignalGrouping: "SignalGrouping", } // Add shared element references here to generate shared types. Usually we diff --git a/chronosphere/intschema/monitor.go b/chronosphere/intschema/monitor.go index f288d34..39f8d92 100644 --- a/chronosphere/intschema/monitor.go +++ b/chronosphere/intschema/monitor.go @@ -25,7 +25,7 @@ type Monitor struct { Interval string `intschema:"interval,optional"` Labels map[string]string `intschema:"labels,optional"` Schedule *MonitorSchedule `intschema:"schedule,optional,list_encoded_object"` - SignalGrouping *MonitorSignalGrouping `intschema:"signal_grouping,optional,list_encoded_object"` + SignalGrouping *SignalGrouping `intschema:"signal_grouping,optional,list_encoded_object"` // Internal identifier used in the .state file, i.e. ResourceData.Id(). // Cannot be set, else ToResourceData will panic. diff --git a/chronosphere/intschema/shared_schemas.go b/chronosphere/intschema/shared_schemas.go index eb01c40..cf4d755 100644 --- a/chronosphere/intschema/shared_schemas.go +++ b/chronosphere/intschema/shared_schemas.go @@ -34,11 +34,6 @@ type MonitorSeriesCondition struct { Value float64 `intschema:"value,optional,default:0"` } -type MonitorSignalGrouping struct { - LabelNames []string `intschema:"label_names,optional"` - SignalPerSeries bool `intschema:"signal_per_series,optional"` -} - type NotificationRoute struct { Severity string `intschema:"severity"` GroupBy *NotificationRouteGroupBy `intschema:"group_by,optional,list_encoded_object"` @@ -79,6 +74,11 @@ type SLOAdditionalPromQLFilters struct { Value string `intschema:"value"` } +type SignalGrouping struct { + LabelNames []string `intschema:"label_names,optional"` + SignalPerSeries bool `intschema:"signal_per_series,optional"` +} + type TraceBoolFilter struct { Value bool `intschema:"value"` } diff --git a/chronosphere/intschema/slo.go b/chronosphere/intschema/slo.go index 38a69f2..eae031d 100644 --- a/chronosphere/intschema/slo.go +++ b/chronosphere/intschema/slo.go @@ -14,16 +14,16 @@ import ( var _ tfid.ID // Always use tfid for simplified import generation. type Slo struct { - Name string `intschema:"name"` - Slug string `intschema:"slug,optional,computed"` - CollectionId tfid.ID `intschema:"collection_id"` - NotificationPolicyId tfid.ID `intschema:"notification_policy_id,optional"` - Definition SloDefinition `intschema:"definition,list_encoded_object"` - Sli SloSli `intschema:"sli,list_encoded_object"` - Annotations map[string]string `intschema:"annotations,optional"` - Description string `intschema:"description,optional"` - Labels map[string]string `intschema:"labels,optional"` - SignalGrouping *MonitorSignalGrouping `intschema:"signal_grouping,optional,list_encoded_object"` + Name string `intschema:"name"` + Slug string `intschema:"slug,optional,computed"` + CollectionId tfid.ID `intschema:"collection_id"` + NotificationPolicyId tfid.ID `intschema:"notification_policy_id,optional"` + Definition SloDefinition `intschema:"definition,list_encoded_object"` + Sli SloSli `intschema:"sli,list_encoded_object"` + Annotations map[string]string `intschema:"annotations,optional"` + Description string `intschema:"description,optional"` + Labels map[string]string `intschema:"labels,optional"` + SignalGrouping *SignalGrouping `intschema:"signal_grouping,optional,list_encoded_object"` // Internal identifier used in the .state file, i.e. ResourceData.Id(). // Cannot be set, else ToResourceData will panic. diff --git a/chronosphere/resource_monitor.go b/chronosphere/resource_monitor.go index 8a995d6..2ab6fcb 100644 --- a/chronosphere/resource_monitor.go +++ b/chronosphere/resource_monitor.go @@ -415,7 +415,7 @@ func monitorConditionsFromModel( } func monitorSignalGroupingToModel( - g *intschema.MonitorSignalGrouping, + g *intschema.SignalGrouping, ) *models.MonitorSignalGrouping { if g == nil { return nil @@ -428,11 +428,11 @@ func monitorSignalGroupingToModel( func monitorSignalGroupingFromModel( g *models.MonitorSignalGrouping, -) *intschema.MonitorSignalGrouping { +) *intschema.SignalGrouping { if g == nil { return nil } - return &intschema.MonitorSignalGrouping{ + return &intschema.SignalGrouping{ LabelNames: g.LabelNames, SignalPerSeries: g.SignalPerSeries, } diff --git a/chronosphere/resource_slo.go b/chronosphere/resource_slo.go index 34ceed3..eecdcb3 100644 --- a/chronosphere/resource_slo.go +++ b/chronosphere/resource_slo.go @@ -227,7 +227,7 @@ func reportingWindowsFromModel(windows []*models.DefinitionTimeWindow) []intsche // TODO: once SLOs have been promoted to v1 this can be removed and monitorSignalGroupingToModel can be used. func unstableMonitorSignalGroupingToModel( - g *intschema.MonitorSignalGrouping, + g *intschema.SignalGrouping, ) *models.MonitorSignalGrouping { if g == nil { return nil @@ -241,11 +241,11 @@ func unstableMonitorSignalGroupingToModel( // TODO: once SLOs have been promoted to v1 this can be removed and monitorSignalGroupingFromModel can be used. func unstableMonitorSignalGroupingFromModel( g *models.MonitorSignalGrouping, -) *intschema.MonitorSignalGrouping { +) *intschema.SignalGrouping { if g == nil { return nil } - return &intschema.MonitorSignalGrouping{ + return &intschema.SignalGrouping{ LabelNames: g.LabelNames, SignalPerSeries: g.SignalPerSeries, } diff --git a/chronosphere/tfschema/common.go b/chronosphere/tfschema/common.go index 6b45a4f..8bc540d 100644 --- a/chronosphere/tfschema/common.go +++ b/chronosphere/tfschema/common.go @@ -42,7 +42,7 @@ var MatcherListSchema = &schema.Schema{ } // Used by both Monitor and SLO -var MonitorSignalGrouping = &schema.Schema{ +var SignalGrouping = &schema.Schema{ Type: schema.TypeList, Optional: true, MaxItems: 1, diff --git a/chronosphere/tfschema/monitor.go b/chronosphere/tfschema/monitor.go index 7122575..0068a47 100644 --- a/chronosphere/tfschema/monitor.go +++ b/chronosphere/tfschema/monitor.go @@ -83,7 +83,7 @@ var Monitor = map[string]*schema.Schema{ }, }, }, - "signal_grouping": MonitorSignalGrouping, + "signal_grouping": SignalGrouping, "series_conditions": { Type: schema.TypeList, Required: true, diff --git a/chronosphere/tfschema/slo.go b/chronosphere/tfschema/slo.go index 69eedae..2d41531 100644 --- a/chronosphere/tfschema/slo.go +++ b/chronosphere/tfschema/slo.go @@ -64,7 +64,7 @@ var Slo = map[string]*schema.Schema{ Schema: SloDefinition, }, }, - "signal_grouping": MonitorSignalGrouping, + "signal_grouping": SignalGrouping, "annotations": { Type: schema.TypeMap, Optional: true, diff --git a/examples/slo/main.tf b/examples/slo/main.tf index 860243e..1ec5284 100644 --- a/examples/slo/main.tf +++ b/examples/slo/main.tf @@ -43,13 +43,12 @@ resource "chronosphere_slo" "slo" { } } -resource "chronosphere_slo" "slo_with_signal_grouping" { - name = "SLO With Signal Grouping" +resource "chronosphere_slo" "slo_with_signal_grouping_signal_per_series" { + name = "SLO With Signal Grouping (Signal per series)" collection_id = chronosphere_collection.c.id notification_policy_id = chronosphere_notification_policy.np.id signal_grouping { - label_names = ["label1", "label2"] signal_per_series = true } @@ -67,3 +66,27 @@ resource "chronosphere_slo" "slo_with_signal_grouping" { } } } + +resource "chronosphere_slo" "slo_with_signal_grouping_labels" { + name = "SLO With Signal Grouping (Labels" + collection_id = chronosphere_collection.c.id + notification_policy_id = chronosphere_notification_policy.np.id + + signal_grouping { + label_names = ["label1", "label2"] + } + + definition { + objective = 99.95 + reporting_windows { + duration = "28d" + } + } + + sli { + custom_indicator { + bad_query_template = "sum(rate(http_request_duration_seconds_count{error=\"true\"}[{{ .Window }}]))" + total_query_template = "sum(rate(http_request_duration_seconds_count[{{ .Window }}]))" + } + } +}