cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/query/cost.md
111lines · 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 | `pint` will try to estimate the number of bytes needed per single time series |
| 16 | and use that to estimate the amount of memory needed for all time series |
| 17 | returned by given query. |
| 18 | The `bytes per time series` number is calculated using this query: |
| 19 | |
| 20 | ``` |
| 21 | avg(avg_over_time(go_memstats_alloc_bytes[2h]) / avg_over_time(prometheus_tsdb_head_series[2h])) |
| 22 | ``` |
| 23 | |
| 24 | Since Go uses garbage collector total Prometheus process memory will be more than the |
| 25 | sum of all memory allocations, depending on many factors like memory pressure, |
| 26 | Go version, GOGC settings etc. The estimate `pint` gives you should be considered |
| 27 | `best case` scenario. |
| 28 | |
| 29 | ## Configuration |
| 30 | |
| 31 | Syntax: |
| 32 | |
| 33 | ```js |
| 34 | cost { |
| 35 | severity = "bug|warning|info" |
| 36 | maxSeries = 5000 |
| 37 | } |
| 38 | ``` |
| 39 | |
| 40 | - `severity` - set custom severity for reported issues, defaults to a warning. |
| 41 | This is only used when query result series exceed `maxSeries` value (if set). |
| 42 | If `maxSeries` is not set or when results count is below it pint will still |
| 43 | report it as information. |
| 44 | - `maxSeries` - if set and number of results for given query exceeds this value |
| 45 | it will be reported as a bug (or custom severity if `severity` is set). |
| 46 | |
| 47 | ## How to enable it |
| 48 | |
| 49 | This check is not enabled by default as it requires explicit configuration |
| 50 | to work. |
| 51 | To enable it add one or more `prometheus {...}` blocks and a `rule {...}` block |
| 52 | with this checks config. |
| 53 | |
| 54 | Examples: |
| 55 | |
| 56 | All rules from files matching `rules/dev/.+` pattern will be tested against |
| 57 | `dev` server. Results will be reported as information regardless of results. |
| 58 | |
| 59 | ```js |
| 60 | prometheus "dev" { |
| 61 | uri = "https://prometheus-dev.example.com" |
| 62 | timeout = "30s" |
| 63 | include = ["rules/dev/.+"] |
| 64 | } |
| 65 | |
| 66 | rule { |
| 67 | cost {} |
| 68 | } |
| 69 | ``` |
| 70 | |
| 71 | ## How to disable it |
| 72 | |
| 73 | You can disable this check globally by adding this config block: |
| 74 | |
| 75 | ```js |
| 76 | checks { |
| 77 | disabled = ["query/cost"] |
| 78 | } |
| 79 | ``` |
| 80 | |
| 81 | You can also disable it for all rules inside given file by adding |
| 82 | a comment anywhere in that file. Example: |
| 83 | |
| 84 | `# pint file/disable query/cost` |
| 85 | |
| 86 | Or you can disable it per rule by adding a comment to it. Example: |
| 87 | |
| 88 | `# pint disable query/cost` |
| 89 | |
| 90 | If you want to disable only individual instances of this check |
| 91 | you can add a more specific comment. |
| 92 | |
| 93 | ### If `maxSeries` is set |
| 94 | |
| 95 | `# pint disable query/cost($prometheus:$maxSeries)` |
| 96 | |
| 97 | Where `$prometheus` is the name of Prometheus server to disable. |
| 98 | |
| 99 | Example: |
| 100 | |
| 101 | `# pint disable query/cost(dev:5000)` |
| 102 | |
| 103 | ### If `maxSeries` is NOT set |
| 104 | |
| 105 | `# pint disable query/cost($prometheus)` |
| 106 | |
| 107 | Where `$prometheus` is the name of Prometheus server to disable. |
| 108 | |
| 109 | Example: |
| 110 | |
| 111 | `# pint disable query/cost(dev)` |