cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.84.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

docs/checks/yaml/parse.md

77lines · modecode

1---
2layout: default
3parent: Checks
4grand_parent: Documentation
5---
6
7# yaml/parse
8
9You will only ever see this check reporting problems if a file containing
10Prometheus rules to check doesn't parse as valid [YAML](https://yaml.org/),
11meaning that pint is unable to read any rules from that file or when
12some fields are using the wrong type.
13
14This check will also report errors for files that cannot be read at all,
15for example broken symlinks or files with insufficient permissions.
16
17This includes basic YAML parser checks but will also fail if a rule
18block contains duplicate keys, example:
19
20```yaml
21- record: foo
22 expr: sum(my_metric)
23 expr: sum(my_metric) without(instance)
24```
25
26Syntax checks enforced by pint are more strict than what Prometheus uses,
27so a rule definition that fails pint checks might still be parsed by
28Prometheus. This is because pint enforces that all fields have the correct type.
29For example all annotations are expected to be strings, but the YAML parser
30will load any value that can be represented as a string, for example a number:
31
32```yaml
33- alert: Foo
34 expr: up == 0
35 annotations:
36 priotity: 1
37```
38
39The above rule will work in Prometheus but, for example, if you try to parse
40such file using Python to find all rules where `priority` is `"1"` it will skip it,
41because Python doesn't know the schema of rule file, so it returns whatever types
42it finds:
43
44```python
45import yaml
46
47with open("rules.yaml") as f:
48 for rule in yaml.safe_load(f):
49 if rule["annotations"]["priority"] == "1":
50 ...
51```
52
53This kind of type confusion can be even more problematic because YAML will
54automatically convert certain string values to boolean, for example:
55
56```yaml
57- alert: Foo
58 expr: up == 0
59 annotations:
60 critical: no
61```
62
63In the above YAML will parse `no` as `false`.
64There are other well known gotchas that are caused by YAML complex parsing rules
65and the best way to avoid these is to always use explicit types for string.
66
67## Configuration
68
69This check doesn't have any configuration options.
70
71## How to enable it
72
73This check is enabled by default.
74
75## How to disable it
76
77You cannot disable this check.
78