diff --git a/internal/prometheus/spec.go b/internal/prometheus/spec.go index 1935aa38..8dcc8fd0 100644 --- a/internal/prometheus/spec.go +++ b/internal/prometheus/spec.go @@ -94,6 +94,14 @@ func (y YAMLSpecLoader) mapSpecToModel(ctx context.Context, spec prometheusv1.Sp } } + if specSLO.SLI.DenominatorCorrected != nil { + slo.SLI.DenominatorCorrected = &SLIDenominatorCorrectedEvents{ + ErrorQuery: specSLO.SLI.DenominatorCorrected.ErrorQuery, + SuccessQuery: specSLO.SLI.DenominatorCorrected.SuccessQuery, + TotalQuery: specSLO.SLI.DenominatorCorrected.TotalQuery, + } + } + if specSLO.SLI.Plugin != nil { plugin, err := y.pluginsRepo.GetSLIPlugin(ctx, specSLO.SLI.Plugin.ID) if err != nil { diff --git a/pkg/prometheus/api/v1/v1.go b/pkg/prometheus/api/v1/v1.go index d81d367d..9d8eacc1 100644 --- a/pkg/prometheus/api/v1/v1.go +++ b/pkg/prometheus/api/v1/v1.go @@ -103,6 +103,8 @@ type SLI struct { Events *SLIEvents `yaml:"events,omitempty"` // Plugin is the pluggable SLI type. Plugin *SLIPlugin `yaml:"plugin,omitempty"` + // DenominatorCorrected is the denominator corrected events SLI type. + DenominatorCorrected *SLIDenominatorCorrected `yaml:"denominator_corrected,omitempty"` } // SLIRaw is a error ratio SLI already calculated. Normally this will be used when the SLI @@ -133,6 +135,29 @@ type SLIPlugin struct { Options map[string]string `yaml:"options"` } +// SLIDenominatorCorrected is an SLI that is calculated as the division of bad events and total events, or +// 1 - (good / total) events giving a ratio SLI. This SLI is corrected based on the total number of events +// for the last 30d, meaning that low-event hours will have less impact on burn-rate than high-event hours. +// In other words, ratios with low denominators will have less impact. +type SLIDenominatorCorrected struct { + // ErrorQuery is a Prometheus query that will get the number/count of events + // that we consider that are bad for the SLO (e.g "http 5xx", "latency > 250ms"...). + // Requires the usage of `{{.window}}` template variable. ErrorQuery and + // SuccessQuery are mutually exclusive. + ErrorQuery *string `yaml:"errorQuery,omitempty"` + + // SuccessQuery is a Prometheus query that will get the number/count of events + // that we consider that are good for the SLO (e.g "http not 5xx", "latency < 250ms"...). + // Requires the usage of `{{.window}}` template variable. ErrorQuery and + // SuccessQuery are mutually exclusive. + SuccessQuery *string `yaml:"successQuery,omitempty"` + + // TotalQuery is a Prometheus query that will get the total number/count of events + // for the SLO (e.g "all http requests"...). + // Requires the usage of `{{.window}}` template variable. + TotalQuery string `yaml:"totalQuery"` +} + // Alerting wraps all the configuration required by the SLO alerts. type Alerting struct { // Name is the name used by the alerts generated for this SLO.