Skip to content

Commit

Permalink
Fix expected queries after upgrading Prometheus
Browse files Browse the repository at this point in the history
This changes mostly the `sum by(grouping)` to `sum by (grouping)`.
  • Loading branch information
metalmatze committed Dec 23, 2022
1 parent 64f479f commit 593e52b
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 146 deletions.
4 changes: 2 additions & 2 deletions kubernetes/controllers/servicelevelobjective_test.go
Expand Up @@ -89,7 +89,7 @@ func Test_makePrometheusRule(t *testing.T) {
Rules: []monitoringv1.Rule{
{
Record: "http_requests:increase4w",
Expr: intstr.FromString(`sum by(status) (increase(http_requests_total{job="app"}[4w]))`),
Expr: intstr.FromString(`sum by (status) (increase(http_requests_total{job="app"}[4w]))`),
Labels: map[string]string{
"job": "app",
"slo": "http",
Expand Down Expand Up @@ -200,7 +200,7 @@ func Test_makeConfigMap(t *testing.T) {
- interval: 2m30s
name: http-increase
rules:
- expr: sum by(status) (increase(http_requests_total{job="app"}[4w]))
- expr: sum by (status) (increase(http_requests_total{job="app"}[4w]))
labels:
job: app
slo: http
Expand Down
8 changes: 4 additions & 4 deletions slo/promql.go
Expand Up @@ -85,7 +85,7 @@ func (o Objective) QueryErrors(window model.Duration) string {
}

if o.Indicator.Latency != nil && o.Indicator.Latency.Total.Name != "" {
expr, err := parser.ParseExpr(`sum by(grouping) (metric{matchers="total"}) - sum by(grouping) (errorMetric{matchers="errors"})`)
expr, err := parser.ParseExpr(`sum by (grouping) (metric{matchers="total"}) - sum by (grouping) (errorMetric{matchers="errors"})`)
if err != nil {
return ""
}
Expand Down Expand Up @@ -394,7 +394,7 @@ func (r objectiveReplacer) replace(node parser.Node) {

func (o Objective) RequestRange(timerange time.Duration) string {
if o.Indicator.Ratio != nil && o.Indicator.Ratio.Total.Name != "" {
expr, err := parser.ParseExpr(`sum by(group) (rate(metric{}[1s])) > 0`)
expr, err := parser.ParseExpr(`sum by (group) (rate(metric{}[1s])) > 0`)
if err != nil {
return err.Error()
}
Expand Down Expand Up @@ -433,7 +433,7 @@ func (o Objective) RequestRange(timerange time.Duration) string {

func (o Objective) ErrorsRange(timerange time.Duration) string {
if o.Indicator.Ratio != nil && o.Indicator.Ratio.Total.Name != "" {
expr, err := parser.ParseExpr(`sum by(group) (rate(errorMetric{matchers="errors"}[1s])) / scalar(sum(rate(metric{matchers="total"}[1s]))) > 0`)
expr, err := parser.ParseExpr(`sum by (group) (rate(errorMetric{matchers="errors"}[1s])) / scalar(sum(rate(metric{matchers="total"}[1s]))) > 0`)
if err != nil {
return err.Error()
}
Expand Down Expand Up @@ -477,7 +477,7 @@ func (o Objective) DurationRange(timerange time.Duration, percentile float64) st
}

if o.Indicator.Latency != nil && o.Indicator.Latency.Total.Name != "" {
expr, err := parser.ParseExpr(`histogram_quantile(0.420, sum by(le) (rate(errorMetric{matchers="errors"}[1s])))`)
expr, err := parser.ParseExpr(`histogram_quantile(0.420, sum by (le) (rate(errorMetric{matchers="errors"}[1s])))`)
if err != nil {
return err.Error()
}
Expand Down

0 comments on commit 593e52b

Please sign in to comment.