grafana/pkg/services/ngalert/api/tooling
Alexander Weaver 0f56462fbe
Alerting: Provisioning message templates (#48665)
* Generate API for writing templates

* Persist templates app logic layer

* Validate templates

* Extract logic, make set and delete methods

* Drop post route for templates

* Fix response details, wire up remainder of API

* Authorize routes

* Mirror some existing tests on new APIs

* Generate mock for prov store

* Wire up prov store mock, add tests using it

* Cover cases for both storage paths

* Add happy path tests and fix bugs if file contains no template section

* Normalize template content with define statement

* Tests for deletion

* Fix linter error

* Move provenance field to DTO

* empty commit

* ID to name

* Fix in auth too
2022-05-05 15:21:42 -05:00
..
cmd/clean-swagger Fix/ngalert generation (#33172) 2021-04-20 13:12:32 -04:00
definitions Alerting: Provisioning message templates (#48665) 2022-05-05 15:21:42 -05:00
swagger-codegen/templates Alerting: Provisioning API - Notification Policies (#46755) 2022-04-05 16:48:51 -05:00
.gitignore Alerting: Unify Swagger/OpenAPI generation tooling (#46928) 2022-03-31 09:34:46 +02:00
index.html Swagger: Add integrity attributes (#48396) 2022-05-02 09:49:49 +02:00
Makefile Alerting: Unify Swagger/OpenAPI generation tooling (#46928) 2022-03-31 09:34:46 +02:00
post.json Alerting: Provisioning message templates (#48665) 2022-05-05 15:21:42 -05:00
README.md Alerting: Unify Swagger/OpenAPI generation tooling (#46928) 2022-03-31 09:34:46 +02:00
spec.json Alerting: Provisioning message templates (#48665) 2022-05-05 15:21:42 -05: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.