Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generation with prometheus type #9

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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