diff --git a/internal/k8sprometheus/spec.go b/internal/k8sprometheus/spec.go index 375f854a..3ef71efd 100644 --- a/internal/k8sprometheus/spec.go +++ b/internal/k8sprometheus/spec.go @@ -94,16 +94,20 @@ func mapSpecToModel(ctx context.Context, defaultWindowPeriod time.Duration, plug spec := kspec.Spec for _, specSLO := range kspec.Spec.SLOs { slo := prometheus.SLO{ - ID: fmt.Sprintf("%s-%s", spec.Service, specSLO.Name), - Name: specSLO.Name, - Description: specSLO.Description, - Service: spec.Service, - TimeWindow: defaultWindowPeriod, - Objective: specSLO.Objective, - Labels: mergeLabels(spec.Labels, specSLO.Labels), - InfoLabels: specSLO.InfoLabels, - PageAlertMeta: prometheus.AlertMeta{Disable: true}, - TicketAlertMeta: prometheus.AlertMeta{Disable: true}, + ID: fmt.Sprintf("%s-%s", spec.Service, specSLO.Name), + RuleGroupInterval: specSLO.Interval.RuleGroupInterval, + SLIErrorRulesInterval: specSLO.Interval.SLIErrorRulesInterval, + MetadataRulesInterval: specSLO.Interval.MetadataRulesInterval, + AlertRulesInterval: specSLO.Interval.AlertRulesInterval, + Name: specSLO.Name, + Description: specSLO.Description, + Service: spec.Service, + TimeWindow: defaultWindowPeriod, + Objective: specSLO.Objective, + Labels: mergeLabels(spec.Labels, specSLO.Labels), + InfoLabels: specSLO.InfoLabels, + PageAlertMeta: prometheus.AlertMeta{Disable: true}, + TicketAlertMeta: prometheus.AlertMeta{Disable: true}, } // Set SLIs. diff --git a/pkg/kubernetes/api/sloth/v1/types.go b/pkg/kubernetes/api/sloth/v1/types.go index 67983d8a..d7abd6cb 100644 --- a/pkg/kubernetes/api/sloth/v1/types.go +++ b/pkg/kubernetes/api/sloth/v1/types.go @@ -1,6 +1,8 @@ package v1 import ( + time "time" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -81,6 +83,10 @@ type SLO struct { // Alerting is the configuration with all the things related with the SLO // alerts. Alerting Alerting `json:"alerting"` + + // Interval is the configuration for all things related to SLO rule_group intervals + // for specific rule groups and all rules. + Interval Interval `yaml:"interval,omitempty"` } // SLI will tell what is good or bad for the SLO. @@ -171,6 +177,18 @@ type Alert struct { Annotations map[string]string `json:"annotations,omitempty"` } +type Interval struct { + // RuleGroupInterval is an optional value for how often the Prometheus rule_group should be evaluated. + // RuleGroupInterval string `yaml:"rulegroup_interval,omitempty"` + RuleGroupInterval time.Duration `yaml:"all,omitempty"` + // Otherwise, specify custom rule_group intervals for each set of recording rules. + // RuleGroupInterval will "fill-in" for any non-specified individual groups + // but individual group settings override RuleGroupInterval. + SLIErrorRulesInterval time.Duration `yaml:"slierror,omitempty"` + MetadataRulesInterval time.Duration `yaml:"metadata,omitempty"` + AlertRulesInterval time.Duration `yaml:"alert,omitempty"` +} + type PrometheusServiceLevelStatus struct { // PromOpRulesGeneratedSLOs tells how many SLOs have been processed and generated for Prometheus operator successfully. PromOpRulesGeneratedSLOs int `json:"promOpRulesGeneratedSLOs"`