Skip to content
leoswing edited this page May 25, 2026 · 4 revisions

CompareQueries Datasource (Grafana Plugin)

CompareQueries is a Grafana datasource plugin that lets you compare the same query across multiple time shifts (for example: current vs yesterday, last week, or custom offsets) in a single panel.

What problem it solves

Grafana’s native time-shift is often panel-wide. CompareQueries enables query-level comparison workflows so you can:

  • Compare baseline and shifted series in one view
  • Keep native query editing for the target datasource
  • Reuse the same logic in dashboards and Grafana Alerting

Typical use cases:

  • Day-over-day and week-over-week analysis
  • Release before/after verification
  • Capacity and anomaly comparison
  • Cross-datasource observation with -- Mixed -- panels

Compatibility

  • Grafana 11 / 12 / 13+
  • Works with Prometheus, Loki, Elasticsearch, SQL, and other datasources via target datasource query editor
  • Backend execution for Grafana Alerting is supported

Important:

  • For new dashboards (especially Grafana 13+), use Target Datasource flow.
  • Legacy RefId flow is for existing Grafana 11/12 dashboards only.

Quick start (recommended flow)

  1. Install plugin from Marketplace or Grafana CLI:
    grafana-cli plugins install leoswing-comparequeries-datasource
    
  2. Add a CompareQueries datasource in Connections -> Data sources.
  3. Create a panel and set panel datasource to -- Mixed --.
  4. Add a query row and choose CompareQueries.
  5. In CompareQueries editor:
    • Select Target Datasource
    • Build the target query inline
    • Add one or more Time shift rows (1d, 1w, 30m, etc.)
  6. Optional: enable Process TimeShift to align shifted timestamps with current time window.

Datasource settings and auth

Default mode:

  • Authentication (Optional): No Authentication

Only if backend/alerting requests fail authentication:

  • Switch to Basic authentication
  • Configure:
    • Service Account Token
    • optional Grafana URL (only if auto-detection is incorrect)

Grafana Alerting

CompareQueries supports alerting through backend query execution.

Minimal alerting setup:

  1. Use CompareQueries datasource directly in alert rule query.
  2. Configure target datasource + query + time shifts.
  3. Add alert expressions (for example Reduce + Threshold).
  4. If auth errors happen, configure Basic authentication as described above.

Migration from legacy RefId flow

For existing Grafana 11/12 dashboards:

  1. Open old CompareQueries row (Reference Query refId set).
  2. Click Migrate to Target Datasource.
  3. Select original datasource.
  4. Rebuild query in embedded editor.
  5. Save dashboard.

Migration preserves time-shift rows and related options.

Links

Suggested Wiki structure (next pages)

  • Installation
  • Query Editor Guide
  • Alerting Guide
  • Migration Guide (RefId -> Target Datasource)
  • Troubleshooting / FAQ
  • Release Notes Highlights

Clone this wiki locally