cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.15.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

docs/checks/query/cost.md

114lines · modecode

1---
2layout: default
3parent: Checks
4grand_parent: Documentation
5---
6
7# query/cost
8
9This check is used to calculate cost of a query and optionally report an issue
10if that cost is too high. It will run `expr` query from every rule against
11selected Prometheus servers and report results.
12This check can be used for both recording and alerting rules, but is most
13useful for recording rules.
14
15## Configuration
16
17Syntax:
18
19```js
20cost {
21 severity = "bug|warning|info"
22 bytesPerSample = 1024
23 maxSeries = 5000
24}
25```
26
27- `severity` - set custom severity for reported issues, defaults to a warning.
28 This is only used when query result series exceed `maxSeries` value (if set).
29 If `maxSeries` is not set or when results count is below it pint will still
30 report it as information.
31- `bytesPerSample` - if set results will use this to calculate estimated memory
32 required to store returned series in Prometheus.
33- `maxSeries` - if set and number of results for given query exceeds this value
34 it will be reported as a bug (or custom severity if `severity` is set).
35
36## How to enable it
37
38This check is not enabled by default as it requires explicit configuration
39to work.
40To enable it add one or more `prometheus {...}` blocks and a `rule {...}` block
41with this checks config.
42
43Examples:
44
45All rules from files matching `rules/dev/.+` pattern will be tested against
46`dev` server. Results will be reported as information regardless of results.
47
48```js
49prometheus "dev" {
50 uri = "https://prometheus-dev.example.com"
51 timeout = "30s"
52 paths = ["rules/dev/.+"]
53}
54
55rule {
56 cost {}
57}
58```
59
60To add memory usage estimate we first need to get average bytes per sample.
61This can be be estimated using two different queries:
62
63- for RSS usage: `process_resident_memory_bytes / prometheus_tsdb_head_series`
64- for Go allocations: `go_memstats_alloc_bytes / prometheus_tsdb_head_series`
65
66Since Go uses garbage collector RSS memory will be more than the sum of all
67memory allocations. RSS usage will be "worst case" while "Go alloc" best case,
68while real memory usage will be somewhere in between, depending on many factors
69like memory pressure, Go version, GOGC settings etc.
70
71```js
72...
73 cost {
74 bytesPerSample = 4096
75 }
76}
77```
78
79## How to disable it
80
81You can disable this check globally by adding this config block:
82
83```js
84checks {
85 disabled = ["query/cost"]
86}
87```
88
89Or you can disable it per rule by adding a comment to it:
90
91`# pint disable query/cost`
92
93If you want to disable only individual instances of this check
94you can add a more specific comment.
95
96### If `maxSeries` is set
97
98`# pint disable query/cost($prometheus:$maxSeries)`
99
100Where `$prometheus` is the name of Prometheus server to disable.
101
102Example:
103
104`# pint disable query/cost(dev:5000)`
105
106### If `maxSeries` is NOT set
107
108`# pint disable query/cost($prometheus)`
109
110Where `$prometheus` is the name of Prometheus server to disable.
111
112Example:
113
114`# pint disable query/cost(dev)`
115