Skip to content

Commit 6809a83

Browse files
author
Guðmundur Björn Birkisson
authored
Fix generation with prometheus type (#9)
1 parent b643653 commit 6809a83

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

internal/prometheus/spec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ func (y YAMLSpecLoader) mapSpecToModel(ctx context.Context, spec prometheusv1.Sp
9494
}
9595
}
9696

97+
if specSLO.SLI.DenominatorCorrected != nil {
98+
slo.SLI.DenominatorCorrected = &SLIDenominatorCorrectedEvents{
99+
ErrorQuery: specSLO.SLI.DenominatorCorrected.ErrorQuery,
100+
SuccessQuery: specSLO.SLI.DenominatorCorrected.SuccessQuery,
101+
TotalQuery: specSLO.SLI.DenominatorCorrected.TotalQuery,
102+
}
103+
}
104+
97105
if specSLO.SLI.Plugin != nil {
98106
plugin, err := y.pluginsRepo.GetSLIPlugin(ctx, specSLO.SLI.Plugin.ID)
99107
if err != nil {

pkg/prometheus/api/v1/v1.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ type SLI struct {
103103
Events *SLIEvents `yaml:"events,omitempty"`
104104
// Plugin is the pluggable SLI type.
105105
Plugin *SLIPlugin `yaml:"plugin,omitempty"`
106+
// DenominatorCorrected is the denominator corrected events SLI type.
107+
DenominatorCorrected *SLIDenominatorCorrected `yaml:"denominator_corrected,omitempty"`
106108
}
107109

108110
// SLIRaw is a error ratio SLI already calculated. Normally this will be used when the SLI
@@ -133,6 +135,29 @@ type SLIPlugin struct {
133135
Options map[string]string `yaml:"options"`
134136
}
135137

138+
// SLIDenominatorCorrected is an SLI that is calculated as the division of bad events and total events, or
139+
// 1 - (good / total) events giving a ratio SLI. This SLI is corrected based on the total number of events
140+
// for the last 30d, meaning that low-event hours will have less impact on burn-rate than high-event hours.
141+
// In other words, ratios with low denominators will have less impact.
142+
type SLIDenominatorCorrected struct {
143+
// ErrorQuery is a Prometheus query that will get the number/count of events
144+
// that we consider that are bad for the SLO (e.g "http 5xx", "latency > 250ms"...).
145+
// Requires the usage of `{{.window}}` template variable. ErrorQuery and
146+
// SuccessQuery are mutually exclusive.
147+
ErrorQuery *string `yaml:"errorQuery,omitempty"`
148+
149+
// SuccessQuery is a Prometheus query that will get the number/count of events
150+
// that we consider that are good for the SLO (e.g "http not 5xx", "latency < 250ms"...).
151+
// Requires the usage of `{{.window}}` template variable. ErrorQuery and
152+
// SuccessQuery are mutually exclusive.
153+
SuccessQuery *string `yaml:"successQuery,omitempty"`
154+
155+
// TotalQuery is a Prometheus query that will get the total number/count of events
156+
// for the SLO (e.g "all http requests"...).
157+
// Requires the usage of `{{.window}}` template variable.
158+
TotalQuery string `yaml:"totalQuery"`
159+
}
160+
136161
// Alerting wraps all the configuration required by the SLO alerts.
137162
type Alerting struct {
138163
// Name is the name used by the alerts generated for this SLO.

0 commit comments

Comments
 (0)