cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.33.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/parser/fuzz_test.go

284lines · modecode

1package parser_test
2
3import (
4 "testing"
5
6 "github.com/cloudflare/pint/internal/parser"
7)
8
9func FuzzParse(f *testing.F) {
10 testcases := []string{
11 `# head comment
12- record: foo # record comment
13 expr: foo offset 10m # expr comment
14 # pre-labels comment
15 labels:
16 # pre-foo comment
17 foo: bar
18 # post-foo comment
19 bob: alice
20# foot comment
21`,
22 `
23- alert: foo
24 annotations: {}
25 expr: bar
26 annotations: {}
27`,
28 `- record: name
29expr: sum(foo)
30labels:
31 foo: bar
32 bob: alice
33`,
34 `
35groups:
36- name: custom_rules
37 rules:
38 - record: name
39 expr: sum(foo)
40 labels:
41 foo: bar
42 bob: alice
43`,
44 `- alert: Down
45 expr: |
46 up == 0
47 for: |+
48 11m
49 labels:
50 severity: critical
51 annotations:
52 uri: https://docs.example.com/down.html
53
54- record: >
55 foo
56 expr: |-
57 bar
58 /
59 baz > 1
60 labels: {}
61`,
62 `- alert: Foo
63expr:
64 (
65 xxx
66 -
67 yyy
68 ) * bar > 0
69 and on(instance, device) baz
70for: 30m
71`,
72 `
73# pint ignore/begin
74{%- set foo = 1 %}
75{% set bar = 2 -%}
76{# comment #}
77{#
78 comment
79#}
80# pint ignore/end
81
82- record: colo_job:up:count
83 expr: sum(foo) without(job)
84
85- record: invalid
86 expr: sum(foo) by ())
87
88# pint ignore/begin
89- record: colo_job:down:count
90 expr: up == {{ foo }}
91# pint ignore/end
92
93- record: colo:multiline
94 expr: |
95 sum(
96 multiline
97 ) without(job, instance)
98
99- record: colo:multiline:sum
100 expr: |
101 sum(sum) without(job)
102 +
103 sum(sum) without(job)
104
105- record: colo:multiline2
106 expr: >-
107 sum(
108 multiline2
109 ) without(job, instance)
110
111- record: colo_job:up:byinstance
112 expr: sum(byinstance) by(instance)
113
114- record: instance_mode:node_cpu:rate4m
115 expr: sum(rate(node_cpu_seconds_total[4m])) without (cpu)
116
117- record: instance_mode:node_cpu:rate4m
118 expr: sum(rate(node_cpu_seconds_total[5m])) without (cpu)
119
120- record: instance_mode:node_cpu:rate5min
121 expr: sum(irate(node_cpu_seconds_total[5m])) without (cpu)
122
123- alert: Instance Is Down
124 expr: up == 0
125`,
126 `
127- record: colo_job:down:count
128 expr: up{job=~"foo"} == 0
129
130- record: colo_job:down:count
131 expr: up{job!~"foo"} == 0
132`,
133 `
134- record: colo_job:fl_cf_html_bytes_in:rate10m
135 expr: sum(rate(fl_cf_html_bytes_in[10m])) WITHOUT (colo_id, instance, node_type, region, node_status, job, colo_name)
136- record: colo_job:foo:rate1m
137 expr: sum(rate(foo[1m])) WITHOUT (instance)
138- record: colo_job:foo:irate3m
139 expr: sum(irate(foo[3m])) WITHOUT (colo_id)
140`,
141 `
142xxx:
143 xxx:
144 xxx:
145
146- xx
147- yyy
148`,
149 `
150- record: "colo:test1"
151 expr: topk(6, sum(rate(edgeworker_subrequest_errorCount{cordon="free"}[5m])) BY (zoneId,job))
152- record: "colo:test2"
153 expr: topk(6, sum(rate(edgeworker_subrequest_errorCount{cordon="free"}[10m])) without (instance))
154`,
155 `- alert: Always
156 expr: up
157- alert: AlwaysIgnored
158 expr: up # pint disable alerts/comparison
159 labels:
160 severity: warning
161 annotations:
162 url: "https://wiki.example.com/page/ServiceIsDown.html"
163- alert: ServiceIsDown
164 expr: up == 0
165- alert: ServiceIsDown
166 expr: up == 0
167 labels:
168 severity: bad
169 annotations:
170 url: bad
171- alert: ServiceIsDown
172 expr: up == 0
173 labels:
174 severity: warning
175 annotations:
176 url: "https://wiki.example.com/page/ServiceIsDown.html"
177`,
178 `
179- alert: Foo Is Down
180 expr: up{job="foo"} == 0
181 annotations:
182 url: "https://wiki.example.com/page/ServiceIsDown.html"
183 summary: 'Instance {{ $label.instance }} down'
184 func: '{{ $valuexx | xxx }}'
185 labels:
186 severity: warning
187 summary: 'Instance {{ $label.instance }} down'
188 func: '{{ $value | xxx }}'
189 bar: 'Some {{$value}} value'
190 val: '{{ .Value|humanizeDuration }}'
191 ignore: '$value is not a variable'
192`,
193 `groups:
194- name: example
195 rules:
196
197 # Alert for any instance that is unreachable for >5 minutes.
198 - alert: InstanceDown
199 expr: up == 0
200 for: 5m
201 labels:
202 severity: page
203 annotations:
204 summary: "Instance {{ $labels.instance }} down"
205 description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."
206
207 # Alert for any instance that has a median request latency >1s.
208 - alert: APIHighRequestLatency
209 expr: sum by (instance) (http_inprogress_requests) > 0
210 for: 10m
211 annotations:
212 summary: "High request latency on {{ $labels.instance }}"
213 description: "{{ $labels.instance }} has a median request latency above 1s (current value: {{ $value }}s)"
214`,
215 `- alert: Good
216expr: up == 0
217for: 2m
218labels:
219 component: foo
220
221alert: Bad
222expr: up == 0
223for: 2m
224labels:
225 component: foo
226`,
227 `
228- record: disabled
229 expr: sum(errors_total) by ) # pint disable promql/syntax
230
231- record: active
232 expr: sum(errors_total) by )
233
234- record: disabled
235 # pint disable promql/aggregate(job:true)
236 expr: sum(errors_total) without(job)
237
238- record: disabled
239 # pint disable promql/aggregate
240 expr: sum(errors_total) without(job)
241
242- record: active
243 expr: sum(errors_total) without(job)
244
245- alert: disabled
246 expr: sum(errors_total) by ) # pint disable promql/syntax
247
248- alert: active
249 expr: sum(errors_total) by )
250
251- alert: disabled
252 # pint disable promql/aggregate(job:true)
253 expr: sum(errors_total) without(job) > 0
254
255- alert: disabled
256 # pint disable promql/aggregate
257 expr: sum(errors_total) without(job) > 0
258
259- alert: active
260 expr: sum(errors_total) without(job)
261`,
262 `groups:
263- name: "haproxy.api_server.rules"
264 rules:
265 - alert: HaproxyServerHealthcheckFailure
266 expr: increase(haproxy_server_check_failures_total[15m]) > 100
267 for: 5m
268 labels:
269 severity: 24x7
270 annotations:
271 summary: "HAProxy server healthcheck failure (instance {{ $labels.instance }})"
272 description: "Some server healthcheck are failing on {{ $labels.server }}\n VALUE = {{ $value }}\n LABELS: {{ $labels }}"
273
274`,
275 }
276 for _, tc := range testcases {
277 f.Add(tc)
278 }
279 p := parser.NewParser()
280 f.Fuzz(func(t *testing.T, s string) {
281 t.Logf("Parsing: [%s]\n", s)
282 _, _ = p.Parse([]byte(s))
283 })
284}
285