{"id":42007277,"url":"https://github.com/kevinjqiu/pat","last_synced_at":"2026-01-26T02:11:40.143Z","repository":{"id":136429593,"uuid":"137370779","full_name":"kevinjqiu/pat","owner":"kevinjqiu","description":"Prometheus Alert Testing utility","archived":false,"fork":false,"pushed_at":"2018-12-17T20:25:24.000Z","size":7037,"stargazers_count":156,"open_issues_count":2,"forks_count":11,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-06-20T03:39:44.911Z","etag":null,"topics":["alerting","kubernetes","prometheus","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinjqiu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-14T14:43:28.000Z","updated_at":"2023-07-30T14:03:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"8769cd26-9828-4f7d-8c6a-a64308b3e958","html_url":"https://github.com/kevinjqiu/pat","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kevinjqiu/pat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinjqiu%2Fpat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinjqiu%2Fpat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinjqiu%2Fpat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinjqiu%2Fpat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinjqiu","download_url":"https://codeload.github.com/kevinjqiu/pat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinjqiu%2Fpat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28764847,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T00:37:26.264Z","status":"online","status_checked_at":"2026-01-26T02:00:08.215Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alerting","kubernetes","prometheus","unit-testing"],"created_at":"2026-01-26T02:11:39.544Z","updated_at":"2026-01-26T02:11:40.138Z","avatar_url":"https://github.com/kevinjqiu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"```\n ____   _  _____ \n|  _ \\ / \\|_   _|\n| |_) / _ \\ | |  \n|  __/ ___ \\| |  \n|_| /_/   \\_\\_|  \n                 \n```\n\nPrometheus Alert Testing tool\n\n[![CircleCI](https://circleci.com/gh/kevinjqiu/pat.svg?style=svg)](https://circleci.com/gh/kevinjqiu/pat)\n\n\nYou may also be interested in [PromCLI](https://github.com/kevinjqiu/promcli)\n\nBuild \u0026 Install\n===============\n\n    go get github.com/kevinjqiu/pat\n\nYou must have golang 1.9+ and [`dep`](https://github.com/golang/dep) installed.\n\nBuild from source\n-----------------\n\nCheck out this repo to $GOPATH/src/github.com/kevinjqiu/pat\n\nand then:\n\n    cd $GOPATH/src/github.com/kevinjqiu/pat \u0026\u0026 make build\n\nUsage\n=====\n\n    pat [options] \u003ctest_yaml_file_glob\u003e\n\ne.g.,\n\n    pat test/*.yaml\n\nTest File Format\n================\n\nTest files are written in yaml format. For a complete schema definition (in jsonschema format), see [here](https://github.com/kevinjqiu/pat/blob/master/pkg/schema/schema.yaml).\n\nTop level attributes\n--------------------\n\n* `name` - The name of the test case\n* [`rules`](#rules) - The rule definitions that are under test\n* [`fixtures`](#fixtures) - The fixture setup for the tests\n* [`assertions`](#assertions) - The test assertions\n\nRules\n-----\n\nThe `rules` section defines how the rules-under-test should be loaded.\nCurrently, two rules loading strategies are supported:\n\n* fromFile - load the rules from a .rules yaml file. If the path specified is not an absolute path, the rule file path will be relative to the test file.\n* fromLiteral - embed the rules under test right inside the test file.\n\n### Example\n\n```yaml\nrules:\n  fromFile: http-rules.yaml\n```\n\nor\n\n```yaml\nrules:\n  fromLiteral: |-\n    groups:\n      - name: prometheus.rules\n        rules:\n          - alert: HTTPRequestRateLow\n            expr: http_requests{group=\"canary\", job=\"app-server\"} \u003c 100\n            for: 1m\n            labels:\n              severity: critical\n```\n\nFixtures\n--------\n\nThe `fixtures` section defines a list of metrics fixtures that the tests will be using.\nEach item in the list has the following attributes:\n\n* `duration` - How long these metrics will be set to the specified value. The duration must be acceptable by Golang's [`time.ParseDuration()`](https://golang.org/pkg/time/#ParseDuration), e.g., `5m` (5 minutes), `1h` (1 hour), etc.\n* `metrics` - The metrics and their values\n\n### Example\n\n```yaml\nfixtures:\n  5m:\n    - http_requests{job=\"app-server\", instance=\"0\", group=\"blue\"}\t75\n    - http_requests{job=\"app-server\", instance=\"1\", group=\"blue\"}\t120\n```\n\nThis will create these two metrics, with the values last for 5 minutes.\n\nYou are also able to specify multiple metrics values:\n\n```yaml\n  5m:\n    - http_requests{job=\"app-server\", instance=\"0\", group=\"blue\"}\t75 100 200\n```\n\nIn this case, the metric `http_requests{job=\"app-server\", instance=\"0\", group=\"blue\"}` will be set to `75` for the first 5 minutes, `100` for the next 5 minutes and `200` for the next 5 minutes. You can use this form to easily setup long running time series.\n\nAssertions\n----------\n\nThe `assertions` section contains a list of expectations when the alert rules are evaluated at certain time.\n\n* `at` - The instant when the rules are being evaluated\n* `expected` - The list of expected alert properties\n\n### Example\n\n```yaml\nassertions:\n  - at: 0m\n    expected:\n      - alertname: HTTPRequestRateLow\n        alertstate: pending\n        job: app-server\n        severity: critical\n  - at: 5m\n    expected:\n      - alertname: HTTPRequestRateLow\n        alertstate: firing\n        job: app-server\n        severity: critical\n  - at: 10m\n    expected: []\n```\n\nIn this example, we're asserting that when the alert rules are evaluated at `0m`, with the given fixtures, we should get `HTTPRequestRateLow` alert in `pending` state, and when evaluated at `5m`, the alert should be in `firing` state. When evaluated at `10m`, we shouldn't get any alert.\n\nA Complete Example\n==================\n\nSuppose you have the following rule file that you want to be tested:\n\n```yaml\ngroups:\n  - name: prometheus.rules\n    rules:\n      - alert: HTTPRequestRateLow\n        expr: http_requests{group=\"canary\", job=\"app-server\"} \u003c 100\n        for: 1m\n        labels:\n          severity: critical\n```\n\nWrite a yaml file with your test cases:\n\n```yaml\nname: Test HTTP Requests too low alert\nrules:\n  fromFile: rules.yaml\nfixtures:\n  - duration: 5m\n    metrics:\n      - http_requests{job=\"app-server\", instance=\"0\", group=\"canary\", severity=\"overwrite-me\"}\t75 85  95 105 105  95  85\n      - http_requests{job=\"app-server\", instance=\"1\", group=\"canary\", severity=\"overwrite-me\"}\t80 90 100 110 120 130 140\nassertions:\n  - at: 0m\n    expected:\n      - alertname: HTTPRequestRateLow\n        alertstate: pending\n        group: canary\n        instance: \"0\"\n        job: app-server\n        severity: critical\n      - alertname: HTTPRequestRateLow\n        alertstate: pending\n        group: canary\n        instance: \"1\"\n        job: app-server\n        severity: critical\n    comment: |-\n      At 0m, the alerts met the threshold but has not met the duration requirement. Expect the alert to be pending\n  - at: 5m\n    expected:\n      - alertname: HTTPRequestRateLow\n        alertstate: firing\n        group: canary\n        instance: \"0\"\n        job: app-server\n        severity: critical\n      - alertname: HTTPRequestRateLow\n        alertstate: firing\n        group: canary\n        instance: \"1\"\n        job: app-server\n        severity: critical\n    comment: |-\n      At 5m, the alerts should be firing because the duration requirement is met.\n  - at: 10m\n    expected:\n      - alertname: HTTPRequestRateLow\n        alertstate: firing\n        group: canary\n        instance: \"0\"\n        job: app-server\n        severity: critical\n    comment: |-\n      At 10m, the alert should be firing only for instance 0 because instance 1 is \u003e= 100.\n  - at: 15m\n    expected: []\n    comment: |-\n      At 15m, both instances are back to normal, therefore we expect no alert.\n```\n\nRun the test:\n\n```bash\n$ ./pat examples/test.yaml\n=== RUN   Test_HTTP_Requests_too_low_alert_at_0m\n--- PASS: Test_HTTP_Requests_too_low_alert_at_0m (0.00s)\n=== RUN   Test_HTTP_Requests_too_low_alert_at_5m\n--- PASS: Test_HTTP_Requests_too_low_alert_at_5m (0.00s)\nPASS\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinjqiu%2Fpat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinjqiu%2Fpat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinjqiu%2Fpat/lists"}