grafana/pkg/services/ngalert/api/tooling
Matthew Jacobson ba3994d338
Alerting: Repurpose rule testing endpoint to return potential alerts (#69755)
* Alerting: Repurpose rule testing endpoint to return potential alerts

This feature replaces the existing no-longer in-use grafana ruler testing API endpoint /api/v1/rule/test/grafana. The new endpoint returns a list of potential alerts created by the given alert rule, including built-in + interpolated labels and annotations.

The key priority of this endpoint is that it is intended to be as true as possible to what would be generated by the ruler except that the resulting alerts are not filtered to only Resolved / Firing and ready to be sent.

This means that the endpoint will, among other things:

- Attach static annotations and labels from the rule configuration to the alert instances.
- Attach dynamic annotations from the datasource to the alert instances.
- Attach built-in labels and annotations created by the Grafana Ruler (such as alertname and grafana_folder) to the alert instances.
- Interpolate templated annotations / labels and accept allowed template functions.
2023-06-08 18:59:54 -04:00
..
cmd/clean-swagger Handle ioutil deprecations (#53526) 2022-08-10 15:37:51 +02:00
definitions Alerting: Repurpose rule testing endpoint to return potential alerts (#69755) 2023-06-08 18:59:54 -04:00
swagger-codegen/templates Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
.gitignore Alerting: Add support for documenting which alerting APIs are stable (#49018) 2022-05-23 14:08:27 -05:00
api.json Alerting: Repurpose rule testing endpoint to return potential alerts (#69755) 2023-06-08 18:59:54 -04:00
index.html Swagger: Add integrity attributes (#48396) 2022-05-02 09:49:49 +02:00
Makefile Rename Acl to ACL (#52342) 2022-07-18 15:14:58 +02:00
post.json Alerting: Repurpose rule testing endpoint to return potential alerts (#69755) 2023-06-08 18:59:54 -04:00
README.md Alerting: Add support for documenting which alerting APIs are stable (#49018) 2022-05-23 14:08:27 -05:00
spec.json Alerting: Repurpose rule testing endpoint to return potential alerts (#69755) 2023-06-08 18:59:54 -04:00

What

This aims to define the unified alerting API as code. It generates OpenAPI definitions from go structs. It also generates server/route stubs based on our documentation.

Running

make - regenerate everything - documentation and server stubs. make serve - regenerate the Swagger document, and host rendered docs on port 80. view api

Requires

Why

The current state of Swagger extraction from golang is relatively limited. It's easier to generate server stubs from an existing Swagger doc, as there are limitations with producing a Swagger doc from a hand-written API stub. The current extractor instead relies on comments describing the routes, but the comments and actual implementation may drift, which we don't want to allow.

Instead, we use a hybrid approach - we define the types in Golang, with comments describing the routes, in a standalone package with minimal dependencies. From this, we produce a Swagger doc, and then turn the Swagger doc back into a full-blown server stub.

Stability

We have some endpoints that we document publically as being stable, and others that we consider unstable. The stable endpoints are documented in api.json, where all endpoints are available in post.json.

To stabilize an endpoint, add the stable tag to its route comment:

// swagger:route GET /api/provisioning/contact-points provisioning stable RouteGetContactpoints