grafana/grafana
TSDB query backends
pkg/tsdb/ hosts the Go-side query implementations for the datasource plugins that ship with Grafana. Each pkg/tsdb/<name>/ is paired with a frontend plugin in public/app/plugins/datasource/<name>/.
Tour
| Backend | Frontend plugin | Notes |
|---|---|---|
prometheus/ |
prometheus (in packages/grafana-prometheus) |
The most-used datasource. Streams instant + range queries via the Prometheus HTTP API. |
loki/ |
loki |
LogQL queries. Includes log line iteration, labels, log volume. |
tempo/ |
tempo |
Distributed traces (via the Tempo API and TraceQL). |
jaeger/ |
jaeger |
Jaeger traces. |
zipkin/ |
zipkin |
Zipkin traces. |
cloudwatch/ |
cloudwatch |
AWS CloudWatch metrics, logs, and X-Ray. |
azuremonitor/ |
azuremonitor |
Azure metrics, logs, traces, resource graph. |
cloud-monitoring/ |
cloud-monitoring |
Google Cloud Monitoring (Stackdriver). |
mysql/ |
mysql |
MySQL/MariaDB SQL queries. |
mssql/ |
mssql |
Microsoft SQL Server. |
grafana-postgresql-datasource/ |
grafana-postgresql-datasource |
PostgreSQL. |
influxdb/ |
influxdb |
InfluxDB v1 (InfluxQL) and v2/v3 (Flux/SQL). |
opentsdb/ |
opentsdb |
OpenTSDB. |
graphite/ |
graphite |
Graphite. |
parca/ |
parca |
Parca profiles. |
grafana-pyroscope-datasource/ |
grafana-pyroscope-datasource |
Pyroscope continuous profiling. |
grafana-testdata-datasource/ |
grafana-testdata-datasource |
Test data generator (used in dev / e2e). |
grafanads/ |
"-- Grafana --" datasource | Built-in query types: random walk, dashboard list, annotations. |
In addition, pkg/expr/ registers itself as the __expr__ datasource so that expression queries can flow through the same orchestration pipeline.
Standard structure of a backend
A typical backend has:
pkg/tsdb/<name>/
├── plugin.go # ResourceHandler / DataHandler / StreamHandler registration
├── service.go # ProvideService(...) constructor
├── client.go # Upstream client (HTTP/SDK)
├── querydata.go # QueryData implementation (the hot path)
├── healthcheck.go # Datasource health check
├── resource.go # Custom REST resources (e.g. metric metadata)
├── kinds/ # CUE schemas (for query types)
└── *_test.go # Unit testsThe plugin SDK (grafana-plugin-sdk-go) provides the gRPC plumbing; backends only need to implement the handlers.
Cross-cutting tools
- Macros / variables — datasources that support templating (Prometheus interval/range, SQL
${date}, …) implement macro expansion before sending queries upstream. Helpers inpkg/tsdb/grafana-postgresql-datasource/sqleng/andpkg/tsdb/prometheus/intervalv2/are the typical reference points. - Auth helpers — Azure SDK credentials, AWS SDK config, GCP service-account JWT all live near their datasources. Shared OAuth refresh helpers in
pkg/services/oauthtoken/are reused for upstreams that need Grafana's signed-in OAuth identity. - Streaming — Loki and Live use the SDK's
StreamHandlerto stream live tail / live updates over gRPC and on to the WebSocket.
SQL datasources
mysql, mssql, grafana-postgresql-datasource, and influxdb (v1) all use a shared SQL engine helper that handles row → DataFrame conversion, time formatting, and macro expansion. Look for the sqleng package within each datasource for the shared base and per-dialect overrides.
Adding a new built-in backend
- Create
pkg/tsdb/<name>/withservice.go,plugin.go, and your handlers. - Add a
ProvideServiceconstructor and a wire set; reference it frompkg/server/wire.go. - Register the plugin id in
pkg/services/pluginsintegration/pluginstore/(it's auto-registered for built-ins, but you may need to add it to a list of "core plugins"). - Create the matching frontend plugin under
public/app/plugins/datasource/<name>/. - Add e2e and unit tests.
In practice, new datasources are created as external plugins these days — they don't need to live in this repo unless they ship with Grafana itself.
See also
- Datasources & queries — orchestration above this layer.
- Plugin host — how plugins are loaded and dispatched.
- Built-in plugins — the matching frontend plugins.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.