[BUG] clickhouse: FORMAT substring check, envelope fallback and swallowed errors

Open
#842 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Yash121l is already working on this.

Since Oct 11, 2026.

  • #867 by @Yash121l — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript
Domain
databases

Research direction

Start in clickhouse/src/model/click-house-client.ts at the FORMAT check, response parsing, and non-OK response handling. Trace the callers that discard status and inspect buildTimeSeries() to understand how non-array responses become empty series. Done means trailing FORMAT clauses are handled correctly, malformed envelopes do not become empty data, and query errors are visible to the panel.

Written by the indexing model from the issue text.

Description

Summary

Three related problems in clickhouse/src/model/click-house-client.ts make the plugin either send a malformed request or fail silently, so the panel shows an empty chart with no reason.

1. The FORMAT detection is a substring test on the whole query

clickhouse/src/model/click-house-client.ts:60-62

let finalQuery = replaceTimeRangePlaceholders(params.query.trim(), params.start, params.end);
if (!finalQuery.toUpperCase().includes('FORMAT')) {
  finalQuery += ' FORMAT JSON';
}

includes('FORMAT') matches anywhere, not just as a trailing ClickHouse format clause. The query is then fetched with Accept unspecified and parsed with response.json() (line 86), so any of the following end in the catch at line 92 → ClickHouse query failed:

  • a column, alias or CTE named format (SELECT format, count() ...),
  • IF(x, 'format', 'other') / position(haystack, 'FORMAT') / any string literal containing the word,
  • a real clause that is not the last token, e.g. SELECT ... FORMAT Pretty used deliberately.

A trailing check (/FORMAT\s*\w*$/i, or always appending when the query does not end with one) would be enough.

2. A response without a data field degrades to a silent empty chart
const body = await response.json();
return { status: 'success', data: body.data || body };

When body.data is undefined the whole ClickHouse envelope (meta, rows, statistics, …) is returned instead of an array. buildTimeSeries() then does Object.keys(data[0] ?? {}), gets [], and returns an empty series list — indistinguishable from a genuinely empty result.

3. Errors are indistinguishable from "no data"
if (!response.ok) {
  console.error('ClickHouse error response:', errorText);
  return { status: 'error', data: [] };
}

The status is dropped by every caller, and ClickHouseQueryResponse.warnings? is never populated. A 500, a bad FORMAT, a permission error and an empty result all render as the same neutral "No data available" with nothing in the panel, the console being the only trace. Surfacing the message (e.g. via the result metadata, or a thrown error the panel can render) would turn hours of dead-end debugging into a one-line answer.

Environment
  • @perses-dev/clickhouse-plugin 0.6.0 and 0.7.0-beta.6 — identical code.
  • 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.