SQL Expressions: Make SQL Expressions work with Alerting (#101820)

Initial support for alerting with SQL expressions

- When `format` is set to `alerting`, SQL expressions output in a format suitable for alerting evaluation.
- Outstanding TODOs:
  - Deduplicate output rows
  - Add more tests
  - Fix broken alerting UI rendering (likely due to shape change to undocumented full-long format)
- Basic usage:
  - SQL must return one numeric column and one or more string columns.
  - Each row may become an alert.
  - The alert fires if the numeric value is non-zero.
  - String columns are treated as labels.

---------

Co-authored-by: Konrad Lalik <konradlalik@gmail.com>
Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
Co-authored-by: Sam Jewell <sam.jewell@grafana.com>
This commit is contained in:
Kyle Brandt
2025-04-02 09:39:36 -04:00
committed by GitHub
parent 192d3783d5
commit c6e52c4766
19 changed files with 409 additions and 357 deletions
+10 -9
View File
@@ -16,8 +16,8 @@
"type": "__expr__",
"uid": "TheUID"
},
"type": "math",
"expression": "$A - $B"
"expression": "$A - $B",
"type": "math"
},
{
"refId": "C",
@@ -25,12 +25,12 @@
"type": "__expr__",
"uid": "TheUID"
},
"type": "reduce",
"expression": "$A",
"reducer": "max",
"settings": {
"mode": "dropNN"
}
},
"type": "reduce"
},
{
"refId": "D",
@@ -38,11 +38,11 @@
"type": "__expr__",
"uid": "TheUID"
},
"expression": "$A",
"window": "1d",
"downsampler": "last",
"expression": "$A",
"type": "resample",
"upsampler": "pad",
"type": "resample"
"window": "1d"
},
{
"refId": "E",
@@ -79,7 +79,6 @@
"type": "__expr__",
"uid": "TheUID"
},
"expression": "A",
"conditions": [
{
"evaluator": {
@@ -90,6 +89,7 @@
}
}
],
"expression": "A",
"type": "threshold"
},
{
@@ -98,7 +98,6 @@
"type": "__expr__",
"uid": "TheUID"
},
"expression": "B",
"conditions": [
{
"evaluator": {
@@ -147,6 +146,7 @@
}
}
],
"expression": "B",
"type": "threshold"
},
{
@@ -156,6 +156,7 @@
"uid": "TheUID"
},
"expression": "SELECT * FROM A limit 1",
"format": "",
"type": "sql"
}
]