Skip to content

Commit

Permalink
Fix generation with prometheus type (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guðmundur Björn Birkisson authored Jan 9, 2024
1 parent b643653 commit 6809a83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/prometheus/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions pkg/prometheus/api/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6809a83

Please sign in to comment.