grafana/pkg/services/ngalert/api
George Robinson 19ebb079ba
Alerting: Add limits and filters to Prometheus Rules API (#66627)
This commit adds support for limits and filters to the Prometheus Rules
API.

Limits:

It adds a number of limits to the Grafana flavour of the Prometheus Rules
API:

- `limit` limits the maximum number of Rule Groups returned
- `limit_rules` limits the maximum number of rules per Rule Group
- `limit_alerts` limits the maximum number of alerts per rule

It sorts Rule Groups and rules within Rule Groups such that data in the
response is stable across requests. It also returns summaries (totals)
for all Rule Groups, individual Rule Groups and rules.

Filters:

Alerts can be filtered by state with the `state` query string. An example
of an HTTP request asking for just firing alerts might be
`/api/prometheus/grafana/api/v1/rules?state=alerting`.

A request can filter by two or more states by adding additional `state`
query strings to the URL. For example `?state=alerting&state=normal`.

Like the alert list panel, the `firing`, `pending` and `normal` state are
first compared against the state of each alert rule. All other states are
ignored. If the alert rule matches then its alert instances are filtered
against states once more.

Alerts can also be filtered by labels using the `matcher` query string.
Like `state`, multiple matchers can be provided by adding additional
`matcher` query strings to the URL.

The match expression should be parsed using existing regular expression
and sent to the API as URL-encoded JSON in the format:

{
    "name": "test",
    "value": "value1",
    "isRegex": false,
    "isEqual": true
}

The `isRegex` and `isEqual` options work as follows:

| IsEqual | IsRegex  | Operator |
| ------- | -------- | -------- |
| true    | false    |    =     |
| true    | true     |    =~    |
| false   | true     |    !~    |
| false   | false    |    !=    |
2023-04-17 17:45:06 +01:00
..
test-data Expressions: Fixes the issue showing expressions editor (#62510) 2023-01-31 18:50:10 +01:00
tooling Alerting: Add limits and filters to Prometheus Rules API (#66627) 2023-04-17 17:45:06 +01:00
api_alertmanager_guards_test.go Alerting: decouple api models from domain\dto models: separate Provenance status + converters (#63594) 2023-02-27 17:57:15 -05:00
api_alertmanager_guards.go Alerting: decouple api models from domain\dto models: separate Provenance status + converters (#63594) 2023-02-27 17:57:15 -05:00
api_alertmanager_test.go Alerting: use alerting GrafanaReceiver and BuildReceiverConfiguration in Grafana (#65224) 2023-04-13 12:25:32 -04:00
api_alertmanager.go Alerting: use alerting GrafanaReceiver and BuildReceiverConfiguration in Grafana (#65224) 2023-04-13 12:25:32 -04:00
api_configuration_test.go Chore: Rename Id to ID in alerting models (#62777) 2023-02-02 17:22:43 +01:00
api_configuration.go Chore: Remove Result field from datasources (#63048) 2023-02-09 15:49:44 +01:00
api_prometheus_test_fixtures.go Expressions: Fixes the issue showing expressions editor (#62510) 2023-01-31 18:50:10 +01:00
api_prometheus_test.go Alerting: Add limits and filters to Prometheus Rules API (#66627) 2023-04-17 17:45:06 +01:00
api_prometheus.go Alerting: Add limits and filters to Prometheus Rules API (#66627) 2023-04-17 17:45:06 +01:00
api_provisioning_test.go Alerting: introduce AlertQuery in definitions package (#63825) 2023-03-27 11:55:13 -04:00
api_provisioning.go Alerting: Remove dependency on alerting package in definitions (#65390) 2023-03-29 13:34:59 -04:00
api_ruler_history.go Alerting: Create new state history "fanout" backend that dispatches to multiple other backends at once (#64774) 2023-03-17 12:41:18 -05:00
api_ruler_test.go Alerting: Update scheduler to get updates only from database (#64635) 2023-03-14 18:02:51 -04:00
api_ruler_validation_test.go Alerting: introduce AlertQuery in definitions package (#63825) 2023-03-27 11:55:13 -04:00
api_ruler_validation.go Alerting: introduce AlertQuery in definitions package (#63825) 2023-03-27 11:55:13 -04:00
api_ruler.go Alerting: Tiny refactor on the eval and schedule packages (#66130) 2023-04-06 16:02:28 +01:00
api_testing_test.go Alerting: introduce AlertQuery in definitions package (#63825) 2023-03-27 11:55:13 -04:00
api_testing.go Alerting: Tiny refactor on the eval and schedule packages (#66130) 2023-04-06 16:02:28 +01:00
api.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00
authorization_test.go Alerting: Add endpoint to revert to a previous alertmanager configuration (#65751) 2023-04-05 14:10:03 -04:00
authorization.go Alerting: Add endpoint to revert to a previous alertmanager configuration (#65751) 2023-04-05 14:10:03 -04:00
compat_test.go Alerting: introduce AlertQuery in definitions package (#63825) 2023-03-27 11:55:13 -04:00
compat.go Alerting: Remove dependency on alerting package in definitions (#65390) 2023-03-29 13:34:59 -04:00
configuration.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
errors.go Alerting: Update forking request handlers to use the same errors (#52965) 2022-08-02 09:33:59 -04:00
forking_alertmanager.go Alerting: Add endpoint to revert to a previous alertmanager configuration (#65751) 2023-04-05 14:10:03 -04:00
forking_prometheus.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
forking_ruler.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
generated_base_api_alertmanager.go Alerting: Add endpoint to revert to a previous alertmanager configuration (#65751) 2023-04-05 14:10:03 -04:00
generated_base_api_configuration.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
generated_base_api_history.go Alerting: Add endpoint for querying state history (#62166) 2023-02-02 11:34:00 -06:00
generated_base_api_prometheus.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
generated_base_api_provisioning.go Alerting: Create endpoints for exporting in provisioning file format (#58623) 2023-01-27 11:39:16 -05:00
generated_base_api_ruler.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
generated_base_api_testing.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
lotex_am.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
lotex_prom.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
lotex_ruler_test.go Chore: Rename Id to ID in alerting models (#62777) 2023-02-02 17:22:43 +01:00
lotex_ruler.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
persist.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00
promql_compat_test.go Alerting: Update prometheus version (#65688) 2023-03-31 16:34:35 +02:00
promql_compat.go Alerting: Update prometheus version (#65688) 2023-03-31 16:34:35 +02:00
provisioning.go Alerting: Create endpoints for exporting in provisioning file format (#58623) 2023-01-27 11:39:16 -05:00
ruler_history.go Alerting: Add endpoint for querying state history (#62166) 2023-02-02 11:34:00 -06:00
testing_api.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
testing.go Chore: Fix goimports grouping in alerting (#62424) 2023-01-30 09:55:35 +01:00
util_test.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
util.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00