grafana/pkg/services/ngalert/api/tooling
Michał Zielonka b54da68765
Alerting: fix validation of alertmanager template. (#51538)
without setting function map from alertmanager we receive error:
method=PUT path=/api/v1/provisioning/templates/slack.message status=400
level=error msg="invalid object specification: invalid template: template: :1: function \"toUpper\" not defined"

So for validation we should use the same settings as alertmanager do
for templates internally.
2022-07-14 11:54:08 +02:00
..
cmd/clean-swagger Alerting: Add support for documenting which alerting APIs are stable (#49018) 2022-05-23 14:08:27 -05:00
definitions Alerting: fix validation of alertmanager template. (#51538) 2022-07-14 11:54:08 +02:00
swagger-codegen/templates Alerting: Code-gen parsing of URL parameters and fix related bugs (#50731) 2022-06-23 15:13:39 -05:00
.gitignore Alerting: Add support for documenting which alerting APIs are stable (#49018) 2022-05-23 14:08:27 -05:00
api.json Alerting: Fix invalid swagger specification (#51907) 2022-07-13 12:34:54 +03:00
index.html Swagger: Add integrity attributes (#48396) 2022-05-02 09:49:49 +02:00
Makefile Alerting: Fix invalid swagger specification (#51907) 2022-07-13 12:34:54 +03:00
post.json Alerting: Fix invalid swagger specification (#51907) 2022-07-13 12:34:54 +03: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: Fix invalid swagger specification (#51907) 2022-07-13 12:34:54 +03: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