|
| 1 | +# Configs API |
| 2 | + |
| 3 | +The configs service provides an API-driven multi-tenant approach to handling various configuration files for prometheus. The service hosts an API where users can read and write Prometheus rule files, Alertmanager configuration files, and Alertmanager templates to a database. |
| 4 | + |
| 5 | +Each tenant will have it's own set of rule files, Alertmanager config, and templates. A POST operation will effectively replace the existing copy with the configs provided in the request body. |
| 6 | + |
| 7 | +## Configs Format |
| 8 | + |
| 9 | +At the current time of writing, the API is part-way through a migration from a single Configs service that handled all three sets of data to a split API ([Tracking issue](https://github.com/cortexproject/cortex/issues/619)). All APIs take and return all sets of data. |
| 10 | + |
| 11 | +The following schema is used both when retrieving the current configs from the API and when setting new configs via the API. |
| 12 | + |
| 13 | +### Schema: |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "id": 99, |
| 18 | + "rule_format_version": "2", |
| 19 | + "config": { |
| 20 | + "alertmanager_config": "<standard alertmanager.yaml config>", |
| 21 | + "rules_files": { |
| 22 | + "rules.yaml": "<standard rules.yaml config>", |
| 23 | + "rules2.yaml": "<standard rules.yaml config>" |
| 24 | + }, |
| 25 | + "template_files": { |
| 26 | + "templates.tmpl": "<standard template file>", |
| 27 | + "templates2.tmpl": "<standard template file>" |
| 28 | + } |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +### Formatting |
| 34 | + |
| 35 | +`id` - should be incremented every time data is updated; Cortex will use the config with the highest number. |
| 36 | + |
| 37 | +`rule_format_version` - allows compatibility for tenants with config in Prometheus V1 format. Pass "1" or "2" according to which Prometheus version you want to match. |
| 38 | + |
| 39 | +`config.alertmanager_config` - The contents of the alertmanager config file should be as described [here](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/), encoded as a single string to fit within the overall JSON payload. |
| 40 | + |
| 41 | +`config.rules_files` - The contents of a rules file should be as described [here](http://prometheus.io/docs/prometheus/latest/configuration/recording_rules/), encoded as a single string to fit within the overall JSON payload. |
| 42 | + |
| 43 | +`config.template_files` - The contents of a template file should be as described [here](https://prometheus.io/docs/alerting/notification_examples/#defining-reusable-templates), encoded as a single string to fit within the overall JSON payload. |
| 44 | + |
| 45 | +## Endpoints |
| 46 | + |
| 47 | +### Manage Alertmanager |
| 48 | + |
| 49 | +`GET /api/prom/configs/alertmanager` - Get current Alertmanager config |
| 50 | + |
| 51 | +- Normal Response Codes: OK(200) |
| 52 | +- Error Response Codes: Unauthorized(401), NotFound(404) |
| 53 | + |
| 54 | +`POST /api/prom/configs/alertmanager` - Replace current Alertmanager config |
| 55 | + |
| 56 | +- Normal Response Codes: NoContent(204) |
| 57 | +- Error Response Codes: Unauthorized(401), BadRequest(400) |
| 58 | + |
| 59 | +`POST /api/prom/configs/alertmanager/validate` - Validate Alertmanager config |
| 60 | + |
| 61 | +Normal Response: OK(200) |
| 62 | +```json |
| 63 | +{ |
| 64 | + "status": "success" |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +Error Response: BadRequest(400) |
| 69 | +```json |
| 70 | +{ |
| 71 | + "status": "error", |
| 72 | + "error": "error message" |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +### Manage Rules |
| 77 | + |
| 78 | +`GET /api/prom/configs/rules` - Get current rule files |
| 79 | + |
| 80 | +- Normal Response Codes: OK(200) |
| 81 | +- Error Response Codes: Unauthorized(400), NotFound(404) |
| 82 | + |
| 83 | +`POST /api/prom/configs/rules` - Replace current rule files |
| 84 | + |
| 85 | +- Normal Response Codes: NoContent(204) |
| 86 | +- Error Response Codes: Unauthorized(401), BadRequest(400) |
| 87 | + |
| 88 | +### Manage Templates |
| 89 | + |
| 90 | +`GET /api/prom/configs/templates` - Get current templates |
| 91 | + |
| 92 | +- Normal Response Codes: OK(200) |
| 93 | +- Error Response Codes: Unauthorized(401), NotFound(404) |
| 94 | + |
| 95 | +`POST /api/prom/configs/templates` - Replace current templates |
| 96 | + |
| 97 | +- Normal Response Codes: NoContent(204) |
| 98 | +- Error Response Codes: Unauthorized(401), BadRequest(400) |
| 99 | + |
| 100 | +### Deactivate/Restore Configs |
| 101 | + |
| 102 | +`DELETE /api/prom/configs/deactivate` - Disable configs for a tenant |
| 103 | + |
| 104 | +- Normal Response Codes: OK(200) |
| 105 | +- Error Response Codes: Unauthorized(401), NotFound(404) |
| 106 | + |
| 107 | +`POST /api/prom/configs/restore` - Re-enable configs for a tenant |
| 108 | + |
| 109 | +- Normal Response Codes OK(200) |
| 110 | +- Error Response Codes: Unauthorized(401), NotFound(404) |
| 111 | + |
| 112 | +These API endpoints will disable/enable the current Rule and Alertmanager configuration for a tenant. |
| 113 | + |
| 114 | +Note that setting a new config will effectively "re-enable" the Rules and Alertmanager configuration for a tenant. |
0 commit comments