Grafana Associate study materials
Grafana Associate study resources

Grafana Associate: Data Sources and Queries

Grafana Associate · Work through your exam, one topic at a time.

All guide sections

Data Sources and Queries

This domain tests how you connect Grafana to a backend, write queries that respect Grafana's time model, and combine or inspect results. Expect questions on connection setup, SQL and Prometheus macros, mixed data sources, transformations, and the query inspector.

Connecting and testing

Add a source under Connections > Data sources > Add new data source. Configure the URL, authentication, TLS and database fields, then click Save & test; a successful save without a passing test usually means credentials or network reachability are wrong. Set a default data source for new panels. Provisioning YAML is used when data sources must be created repeatably. Data source permissions exist where the edition supports them.

Query editors and time macros

Each plugin exposes its own editor, but common controls include Max data points, Min interval, format (for example time series or table) and legend. SQL data sources use macros such as $__timeFilter(column), $__timeGroup(column, $__interval), $__interval, $__range, $__from and $__to. Prometheus commonly uses $__rate_interval and $__interval. A panel can use Mixed data sources, with each query targeting a different source; transformations then unify the result frames. Expressions can add math, reduce or resample steps. The Query inspector shows the request, response, and timing data.

Worked example

A SQL panel uses:

SELECT $__timeGroup(time, $__interval) AS time, avg(value) AS value FROM metrics WHERE $__timeFilter(time) GROUP BY 1 ORDER BY 1

$__timeFilter(time) expands to a bounded time predicate, so the database does the filtering. $__timeGroup buckets rows into intervals derived from the dashboard range and max data points. Aliasing the bucket as time and the aggregate as value lets Grafana render a time series. If the query returns a raw timestamp column without the alias, the panel may show a table or fail to plot.

Traps that cost marks

  • Forgetting Save & test, or assuming a saved source is reachable.
  • Applying a time macro to the wrong column type or a non-time field.
  • Using $__interval in a query without grouping, or ignoring Max data points.
  • Mixing data sources without a transformation to align fields.
  • Expecting the query inspector to edit or fix the query.