[BUG] clickhouse: queries without a time column render as a single row in Table panels

Open
#841 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
clickhouse, typescript
Domain
data, databases

Research direction

Start in get-click-house-data.ts:26-48 and compare its output with the labels handling in get-click-house-log-data.ts:62. Update the no-timestamp result path so each input row becomes one series with non-numeric labels and a single value, while preserving the stated out-of-scope behavior for rows with several numeric columns.

Written by the indexing model from the issue text.

Description

Summary

ClickHouseTimeSeriesQuery.getTimeSeriesData() assumes every result has a time column. Queries that return no usable timestamp (normal table/aggregate SQL) produce NaN timestamps, and because Table renders one row per series while series is built one per column, a query with N rows renders as 1 row containing only the last value — and without labels, so no identity columns either.

Repro
SELECT repository,
       count()                AS jobs,
       avg(duration_seconds)  AS avg_duration
FROM   ci_runs
GROUP BY repository
ORDER BY jobs DESC
LIMIT  10

Expected (a Table panel): 10 rows, columns repository, jobs, avg_duration.

Actual: 1 row, column jobs, value = the jobs of the last row of the result.

Cause

get-click-house-data.ts:26-48:

const timestamp = new Date(row.time).getTime();   // row.time is undefined -> NaN
const value = toTimeSeriesValue(row[metricName]);
return [timestamp, value];
  • metricNames = ['repository', 'jobs', 'avg_duration'] (only time is excluded — and there is no time here at all).
  • repository → every value coerces to NaN → null → the whole "series" is filtered out at line 47.
  • jobs and avg_duration survive as two series, each with 10 points that all share timestamp = NaN.
  • labels is never set on the returned series.

Table.buildRawTableData (Table-0.13.0/lib/table-data-utils.js) then does:

const value = ts.values.at(-1)?.[1];              // -> the LAST row's value only
return { timestamp, [valueColumnName]: value, ...ts.labels };   // ts.labels is undefined

→ one output row per series, one point kept, no identity columns.

Note the log query already returns labels correctly (get-click-house-log-data.ts:62); getTimeSeriesData simply never does.

Expected fix

When the result has no column parseable as a timestamp, treat it as a set of records rather than as a time range:

  • emit one series per row,
  • labels = the non-numeric columns of that row,
  • values = [[0, <value>]] (or another sentinel) for the single numeric column.

That matches how Perses' Table consumes TimeSeries (one row per series, columns = labels + value) and is the shape a Prometheus instant query produces.

Out of scope for this issue

Results with several numeric columns per row (a 6-column Grafana table, say Quota, Limits, Requested, Used, Efficiency%) still cannot be expressed by the current Table model, which allows exactly one value column per row (value, or value #N when several query results are joined). Fixing the above makes single-value tables correct; multi-value tables likely need a Table model change and should be discussed separately.

Scope

From a replay of 215 migrated Grafana queries through the plugin's real transport: 30/30 Table queries are affected, 28 of which also collapse a dimension with ≥2 distinct values. Examples: ci-github-actions "By repository" (repository, 27 distinct), k8s-namespace-efficiency (37 distinct).

Environment
  • @perses-dev/clickhouse-plugin 0.6.0 and 0.7.0-beta.6 — identical behaviour.
  • Perses 0.54.0.
Dominant language
TypeScript
Stars
33
Forks
95
Avg merge
2d 12h
Merged PRs (30d)
40

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from perses/plugins

All issues in perses/plugins

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.