cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/query/cost.md
114lines · modecode
| 1 | --- |
| 2 | layout: default |
| 3 | parent: Checks |
| 4 | grand_parent: Documentation |
| 5 | --- |
| 6 | |
| 7 | # query/cost |
| 8 | |
| 9 | This check is used to calculate cost of a query and optionally report an issue |
| 10 | if that cost is too high. It will run `expr` query from every rule against |
| 11 | selected Prometheus servers and report results. |
| 12 | This check can be used for both recording and alerting rules, but is most |
| 13 | useful for recording rules. |
| 14 | |
| 15 | ## Configuration |
| 16 | |
| 17 | Syntax: |
| 18 | |
| 19 | ```js |
| 20 | cost { |
| 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 | |
| 38 | This check is not enabled by default as it requires explicit configuration |
| 39 | to work. |
| 40 | To enable it add one or more `prometheus {...}` blocks and a `rule {...}` block |
| 41 | with this checks config. |
| 42 | |
| 43 | Examples: |
| 44 | |
| 45 | All 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 |
| 49 | prometheus "dev" { |
| 50 | uri = "https://prometheus-dev.example.com" |
| 51 | timeout = "30s" |
| 52 | paths = ["rules/dev/.+"] |
| 53 | } |
| 54 | |
| 55 | rule { |
| 56 | cost {} |
| 57 | } |
| 58 | ``` |
| 59 | |
| 60 | To add memory usage estimate we first need to get average bytes per sample. |
| 61 | This 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 | |
| 66 | Since Go uses garbage collector RSS memory will be more than the sum of all |
| 67 | memory allocations. RSS usage will be "worst case" while "Go alloc" best case, |
| 68 | while real memory usage will be somewhere in between, depending on many factors |
| 69 | like 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 | |
| 81 | You can disable this check globally by adding this config block: |
| 82 | |
| 83 | ```js |
| 84 | checks { |
| 85 | disabled = ["query/cost"] |
| 86 | } |
| 87 | ``` |
| 88 | |
| 89 | Or you can disable it per rule by adding a comment to it: |
| 90 | |
| 91 | `# pint disable query/cost` |
| 92 | |
| 93 | If you want to disable only individual instances of this check |
| 94 | you can add a more specific comment. |
| 95 | |
| 96 | ### If `maxSeries` is set |
| 97 | |
| 98 | `# pint disable query/cost($prometheus:$maxSeries)` |
| 99 | |
| 100 | Where `$prometheus` is the name of Prometheus server to disable. |
| 101 | |
| 102 | Example: |
| 103 | |
| 104 | `# pint disable query/cost(dev:5000)` |
| 105 | |
| 106 | ### If `maxSeries` is NOT set |
| 107 | |
| 108 | `# pint disable query/cost($prometheus)` |
| 109 | |
| 110 | Where `$prometheus` is the name of Prometheus server to disable. |
| 111 | |
| 112 | Example: |
| 113 | |
| 114 | `# pint disable query/cost(dev)` |
| 115 | |