Alerting: Fix file import/export of recording rules with target datasource uid (#115663)

Alerting: Fix export of recording rules with target datasource uid
This commit is contained in:
Alexander Akhmetov
2025-12-23 11:26:15 +01:00
committed by GitHub
parent 096208202e
commit 84120fb210
13 changed files with 426 additions and 59 deletions
@@ -173,4 +173,49 @@ resource "grafana_rule_group" "rule_group_d3e8424bfbf66bc3" {
from = "condition"
}
}
rule {
name = "recording rule with target"
data {
ref_id = "query"
relative_time_range {
from = 18000
to = 10800
}
datasource_uid = "000000002"
model = "{\"expr\":\"rate(http_requests_total[5m])\",\"hide\":false,\"interval\":\"\",\"intervalMs\":1000,\"legendFormat\":\"\",\"maxDataPoints\":100,\"refId\":\"query\"}"
}
data {
ref_id = "reduced"
relative_time_range {
from = 18000
to = 10800
}
datasource_uid = "__expr__"
model = "{\"expression\":\"query\",\"hide\":false,\"intervalMs\":1000,\"maxDataPoints\":100,\"reducer\":\"mean\",\"refId\":\"reduced\",\"type\":\"reduce\"}"
}
data {
ref_id = "condition"
relative_time_range {
from = 18000
to = 10800
}
datasource_uid = "__expr__"
model = "{\"expression\":\"$reduced > 5\",\"hide\":false,\"intervalMs\":1000,\"maxDataPoints\":100,\"refId\":\"condition\",\"type\":\"math\"}"
}
is_paused = false
record {
metric = "http_requests_rate"
from = "condition"
target_datasource_uid = "000000003"
}
}
}
@@ -233,6 +233,67 @@
"metric": "test_metric",
"from": "condition"
}
},
{
"title": "recording rule with target",
"data": [
{
"refId": "query",
"relativeTimeRange": {
"from": 18000,
"to": 10800
},
"datasourceUid": "000000002",
"model": {
"expr": "rate(http_requests_total[5m])",
"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 5",
"hide": false,
"intervalMs": 1000,
"maxDataPoints": 100,
"refId": "condition",
"type": "math"
}
}
],
"isPaused": false,
"record": {
"metric": "http_requests_rate",
"from": "condition",
"targetDatasourceUid": "000000003"
}
}
]
}
@@ -187,3 +187,48 @@ groups:
record:
metric: test_metric
from: condition
- title: recording rule with target
data:
- refId: query
relativeTimeRange:
from: 18000
to: 10800
datasourceUid: "000000002"
model:
expr: rate(http_requests_total[5m])
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 > 5
hide: false
intervalMs: 1000
maxDataPoints: 100
refId: condition
type: math
isPaused: false
record:
metric: http_requests_rate
from: condition
targetDatasourceUid: "000000003"
@@ -240,6 +240,71 @@
"from": "condition"
}
}
},
{
"grafana_alert": {
"title": "recording rule with target",
"data": [
{
"refId": "query",
"queryType": "",
"relativeTimeRange": {
"from": 18000,
"to": 10800
},
"datasourceUid": "000000002",
"model": {
"expr": "rate(http_requests_total[5m])",
"hide": false,
"interval": "",
"intervalMs": 1000,
"legendFormat": "",
"maxDataPoints": 100,
"refId": "query"
}
},
{
"refId": "reduced",
"queryType": "",
"relativeTimeRange": {
"from": 18000,
"to": 10800
},
"datasourceUid": "__expr__",
"model": {
"expression": "query",
"hide": false,
"intervalMs": 1000,
"maxDataPoints": 100,
"reducer": "mean",
"refId": "reduced",
"type": "reduce"
}
},
{
"refId": "condition",
"queryType": "",
"relativeTimeRange": {
"from": 18000,
"to": 10800
},
"datasourceUid": "__expr__",
"model": {
"expression": "$reduced > 5",
"hide": false,
"intervalMs": 1000,
"maxDataPoints": 100,
"refId": "condition",
"type": "math"
}
}
],
"record": {
"metric": "http_requests_rate",
"from": "condition",
"target_datasource_uid": "000000003"
}
}
}
]
}