cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.40.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/parser/utils/conditions_test.go

86lines · modecode

1package utils_test
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/require"
7
8 "github.com/cloudflare/pint/internal/parser/utils"
9)
10
11func TestRemoveConditions(t *testing.T) {
12 type testCaseT struct {
13 input string
14 output string
15 }
16
17 testCases := []testCaseT{
18 {
19 input: "100",
20 output: "100",
21 },
22 {
23 input: "(100)",
24 output: "100",
25 },
26 {
27 input: "100 ^ 2",
28 output: "",
29 },
30 {
31 input: "(1024 ^ 2)",
32 output: "",
33 },
34 {
35 input: "(100*(1024^2))",
36 output: "",
37 },
38 {
39 input: "min_over_time((foo_with_notfound > 0)[30m:1m]) / bar",
40 output: "min_over_time(foo_with_notfound[30m:1m]) / bar",
41 },
42 {
43 input: "min_over_time((foo_with_notfound > 0)[30m:1m]) / 2",
44 output: "min_over_time(foo_with_notfound[30m:1m])",
45 },
46 {
47 input: "min_over_time(rate(http_requests_total[5m])[30m:1m])",
48 output: "min_over_time(rate(http_requests_total[5m])[30m:1m])",
49 },
50 {
51 input: "(memory_bytes / ignoring(job) (memory_limit > 0)) * on(app_name) group_left(a,b,c) app_registry",
52 output: "(memory_bytes / ignoring (job) memory_limit) * on (app_name) group_left (a, b, c) app_registry",
53 },
54 {
55 input: `(quantile_over_time(0.9, (rate(container_cpu_system_seconds_total{app_name="foo"}[5m]) + rate(container_cpu_user_seconds_total{app_name="foo"}[5m]))[5m:]) / on(instance) bar) > 0.65`,
56 output: `(quantile_over_time(0.9, (rate(container_cpu_system_seconds_total{app_name="foo"}[5m]) + rate(container_cpu_user_seconds_total{app_name="foo"}[5m]))[5m:]) / on (instance) bar)`,
57 },
58 {
59 input: "sum(foo > 5)",
60 output: "sum(foo)",
61 },
62 {
63 input: `predict_linear(ceph_pool_max_avail[2d], 3600 * 24 * 5) * on(pool_id) group_left(name) ceph_pool_metadata < 0`,
64 output: `predict_linear(ceph_pool_max_avail[2d], 3600 * 24 * 5) * on (pool_id) group_left (name) ceph_pool_metadata`,
65 },
66 {
67 input: `label_join(sum by (job, cluster, id) (rate(errors_total[5m])), "_tmp", "/", "cluster", "id")`,
68 output: `label_join(sum by (job, cluster, id) (rate(errors_total[5m])), "_tmp", "/", "cluster", "id")`,
69 },
70 {
71 input: `round((foo > 0))`,
72 output: `round(foo)`,
73 },
74 {
75 input: `round((foo > 0), 10)`,
76 output: `round(foo, 10)`,
77 },
78 }
79
80 for _, tc := range testCases {
81 t.Run(tc.input, func(t *testing.T) {
82 output := utils.RemoveConditions(tc.input)
83 require.Equalf(t, tc.output, output.String(), "input: %q", tc.input)
84 })
85 }
86}
87