Alerting: Rule Modify Export APIs (#75322)

* extend RuleStore interface to get namespace by UID
* add new export API endpoints
* implement request handlers
* update authorization and wire handlers to paths
* add folder error matchers to errorToResponse
* add tests for export methods
This commit is contained in:
Yuri Tseretyan
2023-10-02 11:47:59 -04:00
committed by GitHub
parent e877174501
commit 027bd9356f
23 changed files with 1504 additions and 122 deletions
@@ -0,0 +1,91 @@
resource "grafana_rule_group" "rule_group_0000" {
org_id = 1
name = "group101"
folder_uid = "e4584834-1a87-4dff-8913-8a4748dfca79"
interval_seconds = 10
rule {
name = "prom query with SSE - 2"
condition = "condition"
data {
ref_id = "query"
query_type = ""
relative_time_range {
from = 18000
to = 10800
}
datasource_uid = "000000002"
model = "{\n \"expr\": \"http_request_duration_microseconds_count\",\n \"hide\": false,\n \"interval\": \"\",\n \"intervalMs\": 1000,\n \"legendFormat\": \"\",\n \"maxDataPoints\": 100,\n \"refId\": \"query\"\n }"
}
data {
ref_id = "reduced"
query_type = ""
relative_time_range {
from = 18000
to = 10800
}
datasource_uid = "__expr__"
model = "{\n \"expression\": \"query\",\n \"hide\": false,\n \"intervalMs\": 1000,\n \"maxDataPoints\": 100,\n \"reducer\": \"mean\",\n \"refId\": \"reduced\",\n \"type\": \"reduce\"\n }"
}
data {
ref_id = "condition"
query_type = ""
relative_time_range {
from = 18000
to = 10800
}
datasource_uid = "__expr__"
model = "{\n \"expression\": \"$reduced > 10\",\n \"hide\": false,\n \"intervalMs\": 1000,\n \"maxDataPoints\": 100,\n \"refId\": \"condition\",\n \"type\": \"math\"\n }"
}
no_data_state = "NoData"
exec_err_state = "Alerting"
for = 0
annotations = null
labels = null
is_paused = false
}
rule {
name = "reduced testdata query - 2"
condition = "B"
data {
ref_id = "A"
query_type = ""
relative_time_range {
from = 18000
to = 10800
}
datasource_uid = "000000004"
model = "{\n \"alias\": \"just-testing\",\n \"intervalMs\": 1000,\n \"maxDataPoints\": 100,\n \"orgId\": 0,\n \"refId\": \"A\",\n \"scenarioId\": \"csv_metric_values\",\n \"stringInput\": \"1,20,90,30,5,0\"\n }"
}
data {
ref_id = "B"
query_type = ""
relative_time_range {
from = 18000
to = 10800
}
datasource_uid = "__expr__"
model = "{\n \"expression\": \"$A\",\n \"intervalMs\": 2000,\n \"maxDataPoints\": 200,\n \"orgId\": 0,\n \"reducer\": \"mean\",\n \"refId\": \"B\",\n \"type\": \"reduce\"\n }"
}
no_data_state = "NoData"
exec_err_state = "Alerting"
for = 0
annotations = null
labels = null
is_paused = false
}
}
@@ -0,0 +1,119 @@
{
"apiVersion": 1,
"groups": [
{
"orgId": 1,
"name": "group101",
"folder": "foo bar",
"interval": "10s",
"rules": [
{
"uid": "",
"title": "prom query with SSE - 2",
"condition": "condition",
"data": [
{
"refId": "query",
"relativeTimeRange": {
"from": 18000,
"to": 10800
},
"datasourceUid": "000000002",
"model": {
"expr": "http_request_duration_microseconds_count",
"hide": false,
"interval": "",
"intervalMs": 1000,
"legendFormat": "",
"maxDataPoints": 100,
"refId": "query"
}
},
{
"refId": "reduced",
"relativeTimeRange": {
"from": 18000,
"to": 10800
},
"datasourceUid": "__expr__",
"model": {
"expression": "query",
"hide": false,
"intervalMs": 1000,
"maxDataPoints": 100,
"reducer": "mean",
"refId": "reduced",
"type": "reduce"
}
},
{
"refId": "condition",
"relativeTimeRange": {
"from": 18000,
"to": 10800
},
"datasourceUid": "__expr__",
"model": {
"expression": "$reduced \u003e 10",
"hide": false,
"intervalMs": 1000,
"maxDataPoints": 100,
"refId": "condition",
"type": "math"
}
}
],
"noDataState": "NoData",
"execErrState": "Alerting",
"for": "0s",
"isPaused": false
},
{
"uid": "",
"title": "reduced testdata query - 2",
"condition": "B",
"data": [
{
"refId": "A",
"relativeTimeRange": {
"from": 18000,
"to": 10800
},
"datasourceUid": "000000004",
"model": {
"alias": "just-testing",
"intervalMs": 1000,
"maxDataPoints": 100,
"orgId": 0,
"refId": "A",
"scenarioId": "csv_metric_values",
"stringInput": "1,20,90,30,5,0"
}
},
{
"refId": "B",
"relativeTimeRange": {
"from": 18000,
"to": 10800
},
"datasourceUid": "__expr__",
"model": {
"expression": "$A",
"intervalMs": 2000,
"maxDataPoints": 200,
"orgId": 0,
"reducer": "mean",
"refId": "B",
"type": "reduce"
}
}
],
"noDataState": "NoData",
"execErrState": "Alerting",
"for": "0s",
"isPaused": false
}
]
}
]
}
@@ -0,0 +1,87 @@
apiVersion: 1
groups:
- orgId: 1
name: group101
folder: foo bar
interval: 10s
rules:
- uid: ""
title: prom query with SSE - 2
condition: condition
data:
- refId: query
relativeTimeRange:
from: 18000
to: 10800
datasourceUid: "000000002"
model:
expr: http_request_duration_microseconds_count
hide: false
interval: ""
intervalMs: 1000
legendFormat: ""
maxDataPoints: 100
refId: query
- refId: reduced
relativeTimeRange:
from: 18000
to: 10800
datasourceUid: __expr__
model:
expression: query
hide: false
intervalMs: 1000
maxDataPoints: 100
reducer: mean
refId: reduced
type: reduce
- refId: condition
relativeTimeRange:
from: 18000
to: 10800
datasourceUid: __expr__
model:
expression: $reduced > 10
hide: false
intervalMs: 1000
maxDataPoints: 100
refId: condition
type: math
noDataState: NoData
execErrState: Alerting
for: 0s
isPaused: false
- uid: ""
title: reduced testdata query - 2
condition: B
data:
- refId: A
relativeTimeRange:
from: 18000
to: 10800
datasourceUid: "000000004"
model:
alias: just-testing
intervalMs: 1000
maxDataPoints: 100
orgId: 0
refId: A
scenarioId: csv_metric_values
stringInput: 1,20,90,30,5,0
- refId: B
relativeTimeRange:
from: 18000
to: 10800
datasourceUid: __expr__
model:
expression: $A
intervalMs: 2000
maxDataPoints: 200
orgId: 0
reducer: mean
refId: B
type: reduce
noDataState: NoData
execErrState: Alerting
for: 0s
isPaused: false