-
Notifications
You must be signed in to change notification settings - Fork 1
Alerting
leoswing edited this page May 25, 2026
·
1 revision
CompareQueries supports Grafana Alerting via backend query execution.
This page explains how to configure alerts with CompareQueries, common pitfalls, and troubleshooting steps.
- Supported in CompareQueries backend-enabled versions (2.1.0+).
- Works on Grafana 11/12/13+ (with recommended Target Datasource flow).
- Alerting does not use panel-level
-- Mixed --query composition.
In dashboards, CompareQueries is often used in a -- Mixed -- panel.
In alert rules, execution is backend-driven, so you should configure the CompareQueries query directly with:
- Target Datasource
- Embedded target query
- One or more time shifts
CompareQueries will execute shifted queries in backend and return merged series for alert expressions.
- Create or open a CompareQueries datasource in
Connections -> Data sources. - Keep
AuthenticationasNo Authenticationby default. - If backend/alert requests fail auth, switch to
Basic authenticationand set:-
Service Account Token(Viewer or above) - optional
Grafana URL(only if auto-detection is wrong)
-
- Go to
Alerting -> Alert rules -> New alert rule. - Add a query using CompareQueries datasource.
- In CompareQueries query editor:
- Select
Target Datasource - Build target query inline
- Add time shift rows (for example
1d,1w)
- Select
- Add alert expressions, typically:
ReduceThreshold
- Use Preview alert rule condition to validate query and expression output.
- Keep one base row with empty
Amount(current window). - Add shifted rows (
1d,1w, etc.) for comparisons. - Use clear aliases so downstream expressions are readable.
- If needed, enable Process TimeShift to align shifted timestamps to current window for direct comparison.
Default recommendation:
- Start with
No Authentication. - Move to
Basic authenticationonly when backend/alerting calls fail auth.
When using Basic authentication:
- Use a Grafana Service Account token.
- Keep token in secure configuration.
- Set
Grafana URLonly when environment auto-detection fails (reverse proxy, nonstandard routing, etc.).
Check:
- Target datasource query itself returns data for the alert evaluation window.
- Time shift values are valid (
1d,1w,30m, etc.). - Alias/series selection in expressions matches returned series.
Check:
- CompareQueries datasource auth mode.
- Service account token validity and role.
- Grafana URL setting (if required in your deployment).
Likely cause:
- Panel behavior relied on
-- Mixed --composition. - Alerting requires backend execution path with direct CompareQueries query definition.
Rebuild the query in the alert rule using Target Datasource flow.
Try:
- Enabling/disabling
Process TimeShiftdepending on whether you need aligned timestamps. - Reducing expression complexity first (single series) before adding multi-series comparisons.
- Prefer simple, deterministic query+expression chains in alerts.
- Validate alert logic with Preview before enabling notifications.
- For production, avoid relying on anonymous access behavior from local/dev environments.
- Query A (CompareQueries):
- Base: current period
- Shifted:
1d
- Expression B (
Reduce): aggregate target series - Expression C (
Threshold): trigger when delta exceeds limit
Quick StartTroubleshootingFAQ-
Developer Guide(advanced backend logs and diagnostics)