Skip to content

Commit 56a3896

Browse files
committed
add tests
1 parent 8cf169b commit 56a3896

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

slo/rules_test.go

+30-10
Original file line numberDiff line numberDiff line change
@@ -359,31 +359,31 @@ func TestObjective_Burnrates(t *testing.T) {
359359
Interval: monitoringDuration("30s"),
360360
Rules: []monitoringv1.Rule{{
361361
Record: "http_request_duration_seconds:burnrate5m",
362-
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[5m]))`),
362+
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, sum(rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[5m])))`),
363363
Labels: map[string]string{"job": "metrics-service-thanos-receive-default", "slo": "monitoring-http-latency"},
364364
}, {
365365
Record: "http_request_duration_seconds:burnrate30m",
366-
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[30m]))`),
366+
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, sum(rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[30m])))`),
367367
Labels: map[string]string{"job": "metrics-service-thanos-receive-default", "slo": "monitoring-http-latency"},
368368
}, {
369369
Record: "http_request_duration_seconds:burnrate1h",
370-
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[1h]))`),
370+
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, sum(rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[1h])))`),
371371
Labels: map[string]string{"job": "metrics-service-thanos-receive-default", "slo": "monitoring-http-latency"},
372372
}, {
373373
Record: "http_request_duration_seconds:burnrate2h",
374-
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[2h]))`),
374+
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, sum(rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[2h])))`),
375375
Labels: map[string]string{"job": "metrics-service-thanos-receive-default", "slo": "monitoring-http-latency"},
376376
}, {
377377
Record: "http_request_duration_seconds:burnrate6h",
378-
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[6h]))`),
378+
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, sum(rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[6h])))`),
379379
Labels: map[string]string{"job": "metrics-service-thanos-receive-default", "slo": "monitoring-http-latency"},
380380
}, {
381381
Record: "http_request_duration_seconds:burnrate1d",
382-
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[1d]))`),
382+
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, sum(rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[1d])))`),
383383
Labels: map[string]string{"job": "metrics-service-thanos-receive-default", "slo": "monitoring-http-latency"},
384384
}, {
385385
Record: "http_request_duration_seconds:burnrate4d",
386-
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[4d]))`),
386+
Expr: intstr.FromString(`1 - histogram_fraction(0, 1, sum(rate(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[4d])))`),
387387
Labels: map[string]string{"job": "metrics-service-thanos-receive-default", "slo": "monitoring-http-latency"},
388388
}, {
389389
Alert: "ErrorBudgetBurn",
@@ -1369,11 +1369,11 @@ func TestObjective_IncreaseRules(t *testing.T) {
13691369
Interval: monitoringDuration("2m30s"),
13701370
Rules: []monitoringv1.Rule{{
13711371
Record: "http_request_duration_seconds:increase4w",
1372-
Expr: intstr.FromString(`histogram_count(increase(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[4w]))`),
1372+
Expr: intstr.FromString(`histogram_count(sum(increase(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[4w])))`),
13731373
Labels: map[string]string{"job": "metrics-service-thanos-receive-default", "slo": "monitoring-http-latency"},
13741374
}, {
13751375
Record: "http_request_duration_seconds:increase4w",
1376-
Expr: intstr.FromString(`histogram_fraction(0, 1, increase(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[4w])) * histogram_count(increase(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[4w]))`),
1376+
Expr: intstr.FromString(`histogram_fraction(0, 1, sum(increase(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[4w]))) * histogram_count(sum(increase(http_request_duration_seconds{code=~"2..",job="metrics-service-thanos-receive-default"}[4w])))`),
13771377
Labels: map[string]string{"job": "metrics-service-thanos-receive-default", "slo": "monitoring-http-latency", "le": "1"},
13781378
//}, {
13791379
// Alert: "SLOMetricAbsent",
@@ -1774,6 +1774,26 @@ func TestObjective_GrafanaRules(t *testing.T) {
17741774
Labels: map[string]string{"slo": "monitoring-http-latency"},
17751775
}},
17761776
},
1777+
}, {
1778+
name: "http-latency-native",
1779+
slo: objectiveHTTPNativeLatency(),
1780+
rules: monitoringv1.RuleGroup{
1781+
Name: "monitoring-http-latency-generic",
1782+
Interval: monitoringDuration("30s"),
1783+
Rules: []monitoringv1.Rule{{
1784+
Record: "pyrra_objective",
1785+
Expr: intstr.FromString("0.995"),
1786+
Labels: map[string]string{"slo": "monitoring-http-latency"},
1787+
}, {
1788+
Record: "pyrra_window",
1789+
Expr: intstr.FromString("2419200"),
1790+
Labels: map[string]string{"slo": "monitoring-http-latency"},
1791+
}, {
1792+
Record: "pyrra_availability",
1793+
Expr: intstr.FromString(`sum(http_request_duration_seconds:increase4w{code=~"2..",job="metrics-service-thanos-receive-default",le="1",slo="monitoring-http-latency"} or vector(0)) / sum(http_request_duration_seconds:increase4w{code=~"2..",job="metrics-service-thanos-receive-default",le="",slo="monitoring-http-latency"})`),
1794+
Labels: map[string]string{"slo": "monitoring-http-latency"},
1795+
}},
1796+
},
17771797
}, {
17781798
name: "http-latency-grouping",
17791799
slo: objectiveHTTPLatencyGrouping(),
@@ -1912,7 +1932,7 @@ func TestObjective_GrafanaRules(t *testing.T) {
19121932
err: ErrGroupingUnsupported,
19131933
}}
19141934

1915-
require.Len(t, testcases, 16)
1935+
require.Len(t, testcases, 17)
19161936

19171937
for _, tc := range testcases {
19181938
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)