Alerting: Add contact point provisioning file export (#71692)

* Add contact point provisioning file export apis

* Regenerate api

* docs

* frontend

* add mock to tests

* Fix missing row-level export button on viewer role w/ prov. read

* Address review comments

---------

Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
This commit is contained in:
Matthew Jacobson
2023-07-20 14:35:56 -04:00
committed by GitHub
parent a7c639f16e
commit 13121d3234
25 changed files with 1154 additions and 193 deletions

View File

@ -60,12 +60,13 @@ title: 'Alerting Provisioning HTTP API '
Contact point provisioning is for Grafana-managed alerts only.
| Method | URI | Name | Summary |
| ------ | ----------------------------------------- | --------------------------------------------------------- | --------------------------------- |
| DELETE | /api/v1/provisioning/contact-points/{UID} | [route delete contactpoints](#route-delete-contactpoints) | Delete a contact point. |
| GET | /api/v1/provisioning/contact-points | [route get contactpoints](#route-get-contactpoints) | Get all the contact points. |
| POST | /api/v1/provisioning/contact-points | [route post contactpoints](#route-post-contactpoints) | Create a contact point. |
| PUT | /api/v1/provisioning/contact-points/{UID} | [route put contactpoint](#route-put-contactpoint) | Update an existing contact point. |
| Method | URI | Name | Summary |
| ------ | ------------------------------------------ | ----------------------------------------------------------------- | ------------------------------------------------------ |
| DELETE | /api/v1/provisioning/contact-points/{UID} | [route delete contactpoints](#route-delete-contactpoints) | Delete a contact point. |
| GET | /api/v1/provisioning/contact-points | [route get contactpoints](#route-get-contactpoints) | Get all the contact points. |
| GET | /api/v1/provisioning/contact-points/export | [route get contactpoints export](#route-get-contactpoints-export) | Export all contact points in provisioning file format. |
| POST | /api/v1/provisioning/contact-points | [route post contactpoints](#route-post-contactpoints) | Create a contact point. |
| PUT | /api/v1/provisioning/contact-points/{UID} | [route put contactpoint](#route-put-contactpoint) | Update an existing contact point. |
### Notification policies
@ -258,11 +259,11 @@ GET /api/v1/provisioning/alert-rules/{UID}/export
#### Parameters
| Name | Source | Type | Go type | Separator | Required | Default | Description |
| -------- | ------- | -------- | -------- | --------- | :------: | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| UID | `path` | string | `string` | | ✓ | | Alert rule UID |
| download | `query` | boolean | `bool` | | | | Whether to initiate a download of the file or not. |
| format | `query` | `string` | string | | | `"yaml"` | Format of the downloaded file, either yaml or json. Accept header can also be used, but the query parameter will take precedence. |
| Name | Source | Type | Go type | Separator | Required | Default | Description |
| -------- | ------- | ------- | -------- | --------- | :------: | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| UID | `path` | string | `string` | | ✓ | | Alert rule UID |
| download | `query` | boolean | `bool` | | | | Whether to initiate a download of the file or not. |
| format | `query` | string | `string` | | | `"yaml"` | Format of the downloaded file, either yaml or json. Accept header can also be used, but the query parameter will take precedence. |
#### All responses
@ -337,12 +338,12 @@ GET /api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group}/export
#### Parameters
| Name | Source | Type | Go type | Separator | Required | Default | Description |
| --------- | ------- | -------- | -------- | --------- | :------: | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| FolderUID | `path` | string | `string` | | ✓ | | |
| Group | `path` | string | `string` | | ✓ | | |
| download | `query` | boolean | `bool` | | | | Whether to initiate a download of the file or not. |
| format | `query` | `string` | string | | | `"yaml"` | Format of the downloaded file, either yaml or json. Accept header can also be used, but the query parameter will take precedence. |
| Name | Source | Type | Go type | Separator | Required | Default | Description |
| --------- | ------- | ------- | -------- | --------- | :------: | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| FolderUID | `path` | string | `string` | | ✓ | | |
| Group | `path` | string | `string` | | ✓ | | |
| download | `query` | boolean | `bool` | | | | Whether to initiate a download of the file or not. |
| format | `query` | string | `string` | | | `"yaml"` | Format of the downloaded file, either yaml or json. Accept header can also be used, but the query parameter will take precedence. |
#### All responses
@ -397,10 +398,10 @@ GET /api/v1/provisioning/alert-rules/export
#### Parameters
| Name | Source | Type | Go type | Separator | Required | Default | Description |
| -------- | ------- | -------- | ------- | --------- | :------: | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| download | `query` | boolean | `bool` | | | | Whether to initiate a download of the file or not. |
| format | `query` | `string` | string | | | `"yaml"` | Format of the downloaded file, either yaml or json. Accept header can also be used, but the query parameter will take precedence. |
| Name | Source | Type | Go type | Separator | Required | Default | Description |
| -------- | ------- | ------- | -------- | --------- | :------: | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| download | `query` | boolean | `bool` | | | | Whether to initiate a download of the file or not. |
| format | `query` | string | `string` | | | `"yaml"` | Format of the downloaded file, either yaml or json. Accept header can also be used, but the query parameter will take precedence. |
#### All responses
@ -453,6 +454,46 @@ Status: OK
[ContactPoints](#contact-points)
### <span id="route-get-contactpoints-export"></span> Export all contact points in provisioning file format. (_RouteGetContactpointsExport_)
```
GET /api/v1/provisioning/contact-points/export
```
#### Parameters
| Name | Source | Type | Go type | Separator | Required | Default | Description |
| -------- | ------- | ------- | -------- | --------- | :------: | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| decrypt | `query` | boolean | `bool` | | | | Whether any contained secure settings should be decrypted or left redacted. Redacted settings will contain RedactedValue instead. Currently, only org admin can view decrypted secure settings. |
| download | `query` | boolean | `bool` | | | | Whether to initiate a download of the file or not. |
| format | `query` | string | `string` | | | `"yaml"` | Format of the downloaded file, either yaml or json. Accept header can also be used, but the query parameter will take precedence. |
| name | `query` | string | `string` | | | | Filter by name |
#### All responses
| Code | Status | Description | Has headers | Schema |
| ------------------------------------------ | --------- | ------------------ | :---------: | ---------------------------------------------------- |
| [200](#route-get-contactpoints-export-200) | OK | AlertingFileExport | | [schema](#route-get-contactpoints-export-200-schema) |
| [403](#route-get-contactpoints-export-403) | Forbidden | PermissionDenied | | [schema](#route-get-contactpoints-export-403-schema) |
#### Responses
##### <span id="route-get-contactpoints-export-200"></span> 200 - AlertingFileExport
Status: OK
###### <span id="route-get-contactpoints-export-200-schema"></span> Schema
[AlertingFileExport](#alerting-file-export)
##### <span id="route-get-contactpoints-export-403"></span> 403 - PermissionDenied
Status: Forbidden
###### <span id="route-get-contactpoints-export-403-schema"></span> Schema
[PermissionDenied](#permission-denied)
### <span id="route-get-mute-timing"></span> Get a mute timing. (_RouteGetMuteTiming_)
```
@ -1092,9 +1133,10 @@ Status: Accepted
| annotations | map of string | `map[string]string` | | | | |
| condition | string | `string` | | | | |
| dasboardUid | string | `string` | | | | |
| data | [][alertqueryexport](#alert-query-export) | `[]*AlertQueryExport` | | | | |
| data | [][AlertQueryExport](#alert-query-export) | `[]*AlertQueryExport` | | | | |
| execErrState | string | `string` | | | | |
| for | [Duration](#duration) | `Duration` | | | | |
| isPaused | boolean | `bool` | | | | |
| labels | map of string | `map[string]string` | | | | |
| noDataState | string | `string` | | | | |
| panelId | int64 (formatted integer) | `int64` | | | | |
@ -1113,7 +1155,7 @@ Status: Accepted
| --------- | ------------------------------------------------- | ------------------------- | :------: | ------- | ----------- | ------- |
| folderUid | string | `string` | | | | |
| interval | int64 (formatted integer) | `int64` | | | | |
| rules | [][provisionedalertrule](#provisioned-alert-rule) | `[]*ProvisionedAlertRule` | | | | |
| rules | [][ProvisionedAlertRule](#provisioned-alert-rule) | `[]*ProvisionedAlertRule` | | | | |
| title | string | `string` | | | | |
{{% /responsive-table %}}
@ -1130,7 +1172,7 @@ Status: Accepted
| interval | [Duration](#duration) | `Duration` | | | | |
| name | string | `string` | | | | |
| orgId | int64 (formatted integer) | `int64` | | | | |
| rules | [][alertruleexport](#alert-rule-export) | `[]*AlertRuleExport` | | | | |
| rules | [][AlertRuleExport](#alert-rule-export) | `[]*AlertRuleExport` | | | | |
{{% /responsive-table %}}
@ -1140,16 +1182,27 @@ Status: Accepted
{{% responsive-table %}}
| Name | Type | Go type | Required | Default | Description | Example |
| ---------- | -------------------------------------------------- | ------------------------- | :------: | ------- | ----------- | ------- |
| apiVersion | int64 (formatted integer) | `int64` | | | | |
| groups | [][alertrulegroupexport](#alert-rule-group-export) | `[]*AlertRuleGroupExport` | | | | |
| Name | Type | Go type | Required | Default | Description | Example |
| ------------- | -------------------------------------------------- | ------------------------- | :------: | ------- | ----------- | ------- |
| apiVersion | int64 (formatted integer) | `int64` | | | | |
| contactPoints | [][ContactPointExport](#contact-point-export) | `[]*ContactPointExport` | | | | |
| groups | [][AlertRuleGroupExport](#alert-rule-group-export) | `[]*AlertRuleGroupExport` | | | | |
{{% /responsive-table %}}
### <span id="contact-point-export"></span> ContactPointExport
**Properties**
| Name | Type | Go type | Required | Default | Description | Example |
| --------- | ------------------------------------ | ------------------- | :------: | ------- | ----------- | ------- |
| name | string | `string` | | | | |
| orgId | int64 (formatted integer) | `int64` | | | | |
| receivers | [][ReceiverExport](#receiver-export) | `[]*ReceiverExport` | | | | |
### <span id="contact-points"></span> ContactPoints
[][embeddedcontactpoint](#embedded-contact-point)
[][EmbeddedContactPoint](#embedded-contact-point)
### <span id="duration"></span> Duration
@ -1213,7 +1266,7 @@ Status: Accepted
> provides a Matches method to match a LabelSet against all Matchers in the
> slice. Note that some users of Matchers might require it to be sorted.
[][matcher](#matcher)
[][Matcher](#matcher)
### <span id="mute-time-interval"></span> MuteTimeInterval
@ -1224,13 +1277,13 @@ Status: Accepted
| Name | Type | Go type | Required | Default | Description | Example |
| -------------- | -------------------------------- | ----------------- | :------: | ------- | ----------- | ------- |
| name | string | `string` | | | | |
| time_intervals | [][timeinterval](#time-interval) | `[]*TimeInterval` | | | | |
| time_intervals | [][TimeInterval](#time-interval) | `[]*TimeInterval` | | | | |
{{% /responsive-table %}}
### <span id="mute-timings"></span> MuteTimings
[][mutetimeinterval](#mute-time-interval)
[][MuteTimeInterval](#mute-time-interval)
### <span id="notification-template"></span> NotificationTemplate
@ -1260,7 +1313,7 @@ Status: Accepted
### <span id="notification-templates"></span> NotificationTemplates
[][notificationtemplate](#notification-template)
[][NotificationTemplate](#notification-template)
### <span id="object-matchers"></span> ObjectMatchers
@ -1268,6 +1321,10 @@ Status: Accepted
#### Inlined models
### <span id="permission-denied"></span> PermissionDenied
[interface{}](#interface)
### <span id="provenance"></span> Provenance
| Name | Type | Go type | Default | Description | Example |
@ -1284,11 +1341,12 @@ Status: Accepted
| ------------ | ---------------------------- | ------------------- | :------: | ------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| annotations | map of string | `map[string]string` | | | | `{"runbook_url":"https://supercoolrunbook.com/page/13"}` |
| condition | string | `string` | ✓ | | | `A` |
| data | [][alertquery](#alert-query) | `[]*AlertQuery` | ✓ | | | `[{"datasourceUid":"__expr__","model":{"conditions":[{"evaluator":{"params":[0,0],"type":"gt"},"operator":{"type":"and"},"query":{"params":[]},"reducer":{"params":[],"type":"avg"},"type":"query"}],"datasource":{"type":"__expr__","uid":"__expr__"},"expression":"1 == 1","hide":false,"intervalMs":1000,"maxDataPoints":43200,"refId":"A","type":"math"},"queryType":"","refId":"A","relativeTimeRange":{"from":0,"to":0}}]` |
| data | [][AlertQuery](#alert-query) | `[]*AlertQuery` | ✓ | | | `[{"datasourceUid":"__expr__","model":{"conditions":[{"evaluator":{"params":[0,0],"type":"gt"},"operator":{"type":"and"},"query":{"params":[]},"reducer":{"params":[],"type":"avg"},"type":"query"}],"datasource":{"type":"__expr__","uid":"__expr__"},"expression":"1 == 1","hide":false,"intervalMs":1000,"maxDataPoints":43200,"refId":"A","type":"math"},"queryType":"","refId":"A","relativeTimeRange":{"from":0,"to":0}}]` |
| execErrState | string | `string` | ✓ | | | |
| folderUID | string | `string` | ✓ | | | `project_x` |
| for | [Duration](#duration) | `Duration` | ✓ | | | |
| id | int64 (formatted integer) | `int64` | | | | |
| isPaused | boolean | `bool` | | | | `false` |
| labels | map of string | `map[string]string` | | | | `{"team":"sre-team-1"}` |
| noDataState | string | `string` | ✓ | | | |
| orgID | int64 (formatted integer) | `int64` | ✓ | | | |
@ -1302,7 +1360,18 @@ Status: Accepted
### <span id="provisioned-alert-rules"></span> ProvisionedAlertRules
[][provisionedalertrule](#provisioned-alert-rule)
[][ProvisionedAlertRule](#provisioned-alert-rule)
### <span id="receiver-export"></span> ReceiverExport
**Properties**
| Name | Type | Go type | Required | Default | Description | Example |
| --------------------- | ------------- | -------- | :------: | ------- | ----------- | ------- |
| disableResolveMessage | boolean | `bool` | | | | |
| settings | [JSON](#json) | `JSON` | | | | |
| type | string | `string` | | | | |
| uid | string | `string` | | | | |
### <span id="regexp"></span> Regexp
@ -1350,7 +1419,7 @@ Status: Accepted
| provenance | [Provenance](#provenance) | `Provenance` | | | | |
| receiver | string | `string` | | | | |
| repeat_interval | string | `string` | | | | |
| routes | [][route](#route) | `[]*Route` | | | | |
| routes | [][Route](#route) | `[]*Route` | | | | |
{{% /responsive-table %}}
@ -1368,7 +1437,7 @@ Status: Accepted
| days_of_month | []string | `[]string` | | | | |
| location | string | `string` | | | | |
| months | []string | `[]string` | | | | |
| times | [][timerange](#time-range) | `[]*TimeRange` | | | | |
| times | [][TimeRange](#time-range) | `[]*TimeRange` | | | | |
| weekdays | []string | `[]string` | | | | |
| years | []string | `[]string` | | | | |