Repository navigation
Build Custom Grafana Datasource Plugin for TimescaleDB #70
Description
Problem
Currently querying the telemetry table via Grafana's TimescaleDB integration is not super useful because the telemetry data has rows from different sources and components. This means that all data is interleaved with respect to time, so the time-series graphs are unusable without complex SQL queries involving joining telemetryDefId and related fields which need to be looked up seperately.
Proposal
Build a custom Grafana datasource plugin with a Go backend and React frontend that implements a query editor for Hermes telemetry and event data stored in TimescaleDB.
Architecture
This will have two parts.
Backend (Go)
This will probably involve making a Go binary using grafana-plugin-sdk-go which:
- Connects to TimescaleDB using the connection settings in the datasource config (host, user, password, database)
- Implements the
QueryDataHandlerinterface to receive structured queries from teh frontend and translate them to SQL using the existingtelemetry,telemetryDefs,events, andeventDefstables - Return results as Grafana data frames
- Implement
CheckHealthHandlerto validate the database connection - Can also implement resource handlers (
CallResourceHandler) to provide metadata (components, channel names, sources) to the frontend to populate dropdowns
Frontend (React/TypeScript)
A React query editor using @grafana/ui and @grafana/data that provides:
- Query type selector: Telemetry vs Events
- Telemetry Query Editor
- Component dropdown (via
telemetryDefs) - Channel name dropdown (filtered by selected component)
- Source dropdown (via
DISTINCT sourceintelemetry) - Key filter (object/array channels that can produce multiple keys, e.g.
value.x,value.y) - Value type selector (integral, floating, bool, string) to control which column is returned
- Component dropdown (via
- Event query editor
Component dropdown (viaeventDefs)Event name dropdown (filtered by component)Severity filter- Source dropdown
- Config editor: Connection settings form (host, port, user, password, database, SSL mode (?))
Important
Event queries have been updated so they only require source as an (optional) option; this is because only the table view will be used and these come with built-in table filters.
Note
When selecting a source, the source column should no longer show in the table view.
Tasks
- Scaffold plugin using
create-plugin(npx @grafana/create-plugin@latest) - Implement backend datasource (Go):
CheckHealth,QueryData,CallResourcefor metadata endpoint - Implement frontend config editor (connection settings form)
- Implement frontend query editor with dropdowns for component/channel/source/key
- Support telemetry queries (time-series graphs, tables)
- Support event queries (table/log format)
- Documentation for local dev setup and usage
- Add per-query absolute time override options ("Time Override" collapsible row)
-
Figure out deployment/signing: Postponed Deploy Plugin #81
Activity