- Table: the simplest query type for showing data in table format. Works well as a catch-all for both simple and complex queries containing aggregate functions.
- Logs: optimized for building queries for logs. Works best in explore view with defaults configured.
- Time Series: best used for building time series queries. Allows selecting a dedicated time column and adding aggregate functions.
- Traces: optimized for searching/viewing traces. Works best in explore view with defaults configured.
- SQL Editor: the SQL Editor can be used when you want full control over the query. In this mode, any SQL query can be executed.
Query types
The Query Type setting will change the layout of the query builder to match the type of query being built. The query type also determines which panel is used when visualizing data.Table
The most flexible query type is the table query. This is a catch-all for the other query builders designed to handle simple and aggregate queries.
This query type will render the data as a table.
Logs
The logs query type offers a query builder focused on querying logs data. Defaults can be configured in the data source’s log configuration to allow the query builder to be pre-loaded with a default database/table and columns. OpenTelemetry can also be enabled to auto select the columns according to a schema version. Time and Level filters are added by default, along with an Order By for the Time column. These filters are tied to their respective fields, and will update as the columns are changed. The Level filter is excluded from the SQL by default, changing it from theIS ANYTHING option will enable it.
The logs query type supports data links.
This query type will render the data in the logs panel along with a logs histogram panel at the top. Extra columns that are selected in the query can be viewed in the expanded log row:
Time series
The time series query type is similar to table, but with a focus on time series data. The two views are mostly the same, with these notable differences:- A dedicated Time field.
- In Aggregate mode, a time interval macro is automatically applied along with a Group By for the Time field.
- In Aggregate mode, the “Columns” field is hidden.
- A time range filter and Order By are automatically added for the Time field.
This query type will render the data with the time series panel.
Traces
The trace query type offers a query builder for easily searching and viewing traces. It is designed for OpenTelemetry data, but columns can be selected to render traces from a different schema. Defaults can be configured in the data source’s trace configuration to allow the query builder to be pre-loaded with a default database/table and columns. If defaults are configured, the column selection will be collapsed by default. OpenTelemetry can also be enabled to auto select the columns according to a schema version. Default filters are added with the intent to show only top level spans. An Order By for the Time and Duration Time columns is also included. These filters are tied to their respective fields, and will update as the columns are changed. The Service Name filter is excluded from the SQL by default, changing it from theIS ANYTHING option will enable it.
The trace query type supports data links.
This query type will render the data with the table view for Trace Search mode, and the trace panel for Trace ID mode.
SQL editor
For queries that are too complex for the query builder, you can use the SQL Editor. This gives you full control over the query by allowing you to write and run plain ClickHouse SQL. The SQL editor can be opened by selecting “SQL Editor” at the top of the query editor. Macro functions can still be used in this mode. You can switch between query types to get a visualization that best fits your query. This switch also has an effect even in dashboard view, notably with time series data.Data links
Grafana data links can be used to link to new queries. This feature has been enabled within the ClickHouse plugin for linking a trace to logs and vice versa. It works best with OpenTelemetry configured for both logs and traces in the data source’s configExample of trace links in a table
Example of trace links in logs
How to make a data link
You can make a data link by selecting a column namedtraceID in your query. This name is case insensitive, and supports adding an underscore before the “ID”. For example: traceId, TraceId, TRACE_ID, and tracE_iD would all be valid.
If OpenTelemetry is enabled in a log or trace query, a trace ID column will be included automatically.
By including a trace ID column, the “View Trace” and “View Logs” links will be attached to the data.
Linking abilities
With the data links present, you can open traces and logs using the provided trace ID. “View Trace” will open a split panel with the trace, and “View Logs” will open a logs query filtered by the trace ID. If the link is clicked from a dashboard instead of the explore view, the link will be opened in a new tab in the explore view. Having defaults configured for both logs and traces is required when crossing query types (logs to traces and traces to logs). Defaults aren’t required when opening a link of the same query type since the query can be simply copied.Example of viewing a trace (right panel) from a logs query (left panel)
Macros
Macros are a simple way to add dynamic SQL to your query. Before a query gets sent to the ClickHouse server, the plugin will expand the macro and replace it will the full expression. Queries from both the SQL Editor and Query Builder can use macros.Using macros
Macros can be included anywhere in the query, multiple times if needed. Here is an example of using the$__timeFilter macro:
Input:
log_time column.
The plugin also supports notation using braces {}. Use this notation when queries are needed inside parameters.