cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/index.md
134lines · modecode
| 1 | --- |
| 2 | layout: default |
| 3 | title: Documentation |
| 4 | nav_order: 1 |
| 5 | has_children: true |
| 6 | --- |
| 7 | |
| 8 | # pint |
| 9 | |
| 10 | pint is a Prometheus rule linter. |
| 11 | |
| 12 | ## Usage |
| 13 | |
| 14 | There are three modes it works in: |
| 15 | |
| 16 | - CI PR linting |
| 17 | - Ad-hoc linting of a selected files or directories |
| 18 | - A daemon that continuously checks selected files or directories and expose metrics describing |
| 19 | all discovered problems. |
| 20 | |
| 21 | ### Pull Requests |
| 22 | |
| 23 | Run it with `pint ci`. |
| 24 | |
| 25 | It currently supports git for which it will find all commits on the current branch that are not |
| 26 | present in the parent branch and scan all modified files included in those changes. |
| 27 | |
| 28 | Results can optionally be reported using |
| 29 | [BitBucket API](https://docs.atlassian.com/bitbucket-server/rest/7.8.0/bitbucket-code-insights-rest.html) |
| 30 | or [GitHub API](https://docs.github.com/en/rest) to generate a report with any found issues. |
| 31 | If you are using BitBucket API then each issue will create an inline annotation in BitBucket with a description of |
| 32 | the issue. If you are using GitHub API then each issue will appear as a comment on your pull request. |
| 33 | |
| 34 | Exit code will be one (1) if any issues were detected with severity `Bug` or higher. This permits running |
| 35 | `pint` in your CI system whilst at the same you will get detailed reports on your source control system. |
| 36 | |
| 37 | ### Ad-hoc |
| 38 | |
| 39 | Lint specified files and report any found issue. |
| 40 | |
| 41 | You can lint selected files: |
| 42 | |
| 43 | ```shell |
| 44 | pint lint rules.yml |
| 45 | ``` |
| 46 | |
| 47 | or directories: |
| 48 | |
| 49 | ```shell |
| 50 | pint lint path/to/dir |
| 51 | ``` |
| 52 | |
| 53 | or both: |
| 54 | |
| 55 | ```shell |
| 56 | pint lint path/to/dir file.yml path/file.yml path/dir |
| 57 | ``` |
| 58 | |
| 59 | ### Daemon |
| 60 | |
| 61 | Run the daemon: |
| 62 | |
| 63 | ```shell |
| 64 | pint watch rules.yml |
| 65 | ``` |
| 66 | |
| 67 | By default it will start a HTTP server on port `8080` and run all checks every |
| 68 | 10 minutes. This can be customized by passing extra flags to the `watch` command. |
| 69 | Run `pint watch -h` to see all available flags. |
| 70 | |
| 71 | Query `/metrics` to see all expose metrics, example with default flags: |
| 72 | |
| 73 | ```shell |
| 74 | curl -s http://localhost:8080/metrics |
| 75 | ``` |
| 76 | |
| 77 | Or setup Prometheus scrape job: |
| 78 | |
| 79 | ```yaml |
| 80 | scrape_configs: |
| 81 | - job_name: pint |
| 82 | static_configs: |
| 83 | - targets: ['localhost:8080'] |
| 84 | ``` |
| 85 | |
| 86 | Available metrics: |
| 87 | |
| 88 | - `pint_problem` - exported for every problem detected by pint. |
| 89 | To avoid exposing too many metrics at once pass `--max-problems` flag to watch command. |
| 90 | When this flag is set pint will expose only up to `--max-problems` value number of |
| 91 | `pint_problem` metrics. |
| 92 | - `pint_problems` - this metric is the total number of all problems detected by pint, |
| 93 | including those not exported due to the `--max-problems` flag. |
| 94 | |
| 95 | ## Release Notes |
| 96 | |
| 97 | See [changelog](changelog.md) for history of changes. |
| 98 | |
| 99 | ## Quick start |
| 100 | |
| 101 | Requirements: |
| 102 | |
| 103 | - [Git](https://git-scm.com/) |
| 104 | - [Go](https://golang.org/) - current stable release |
| 105 | |
| 106 | Steps: |
| 107 | |
| 108 | 1. Download a binary from [Releases](https://github.com/cloudflare/pint/releases) page |
| 109 | or build from source: |
| 110 | |
| 111 | ```shell |
| 112 | git clone https://github.com/cloudflare/pint.git |
| 113 | cd pint |
| 114 | make |
| 115 | ``` |
| 116 | |
| 117 | 2. Run a simple syntax check on Prometheus |
| 118 | [alerting](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/) |
| 119 | or [recording](https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/) |
| 120 | rules file(s). |
| 121 | |
| 122 | ```shell |
| 123 | ./pint lint /etc/prometheus/*.rules.yml |
| 124 | ``` |
| 125 | |
| 126 | 3. Configuration file is optional, but without it pint will only run very basic |
| 127 | syntax checks. See [configuration](configuration.md) for details on |
| 128 | config syntax. |
| 129 | By default pint will try to load configuration from `.pint.hcl`, you can |
| 130 | specify a different path using `--config` flag: |
| 131 | |
| 132 | ```shell |
| 133 | ./pint --config /etc/pint.hcl lint /etc/prometheus/rules/*.yml |
| 134 | ``` |
| 135 | |