Repository navigation
Commit 386c365
authored
[HDX-4769] feat(cli): terminal charting — dashboards TUI page and hdx chart command (#2629)
Linear: [HDX-4769](https://linear.app/clickhouse/issue/HDX-4769/implement-hdx-chart-render-dashboard-tiles-and-ad-hoc-charts-in-the)
## Why
When troubleshooting from the terminal — especially agent-driven investigations — there was no way to *see* the data. The CLI could search and tail events, but visualizing a metric ("did errors spike at deploy time?", "what does p95 latency look like?") required switching to the web UI. This PR brings dashboard tiles and ad-hoc charts into the terminal so an investigation loop (chart → spot the anomaly → narrow with `--where` / `hdx query` / `hdx stream`) can happen entirely in the CLI.
## What
### `hdx chart` — terminal charts for CLI/agent troubleshooting
Three modes on one command, all flowing through the **same `renderChartConfig` SQL pipeline the web dashboards use** (via `queryChartConfig` inherited from common-utils), so SQL and results match the web UI exactly — including metric-source query splitting/joining:
```bash
# 1. Saved dashboard tiles (name or ID)
hdx chart -d "Service Health" -t "P95 Latency" --since 24h
# 2. Ad-hoc builder charts
hdx chart -s Logs --where 'SeverityText:error' --group-by ServiceName --since 3h
hdx chart -s Traces --agg quantile --level 0.95 --value Duration
hdx chart -s Metrics --metric-type sum --metric-name otelcol_exporter_sent_spans
# 3. Ad-hoc raw SQL (supports $__timeFilter / $__timeInterval macros)
hdx chart -s Logs --sql 'SELECT $__timeInterval(TimestampTime) AS ts, count()
FROM default.otel_logs WHERE $__timeFilter(TimestampTime) GROUP BY ts'
```
- Display types: line, stacked bar, number, table, bar, pie, markdown (heatmap/search/patterns/PromQL show a placeholder)
- Time ranges: `--since 1h`, or `--from`/`--to` accepting ISO 8601, date-only, and relative (`now-24h`) — same parser as the TUI time-range editor
- Agent-friendly: ANSI colors auto-stripped when stdout is not a TTY (`--color auto|always|never`), `--json` emits raw rows + column metadata, actionable errors with exit 1, help text written as agent documentation
### TUI Dashboards page (`d` key)
Dashboard picker → tiles in grid order with j/k navigation, Enter for fullscreen, `t` time-range editor, `r` refresh. Only tiles scrolled into view are mounted/queried (mirrors the web's viewport-gated fetching).
### Architecture
Chart renderers are pure functions (`data + dimensions → ANSI string`) shared by the Ink TUI and the stdout command. Ports from the web app carry `@source` comments and follow the existing CLI web-alignment convention:
| CLI | Web |
|---|---|
| `shared/tileConfig.ts` | `DBDashboardPage` Tile config resolution + `ChartUtils` transforms |
| `shared/tileRender.ts` | `renderChartContent` dispatch |
| `shared/chartData.ts` | `formatResponseForTimeChart` / categorical shaping |
| `shared/formatNumber.ts` | `formatNumber` (numbro) + number-format resolution |
### Fixes along the way
- Silenced the `@clickhouse/client` internal logger (`ClickHouseLogLevel.OFF`): Ink's `patchConsole` re-enabled console output that `silenceLogs` had suppressed, spewing abort stack traces over the TUI whenever an in-flight tile query was legitimately cancelled
- Memoized ClickHouse client/metadata in `App` so re-renders don't churn data-fetch effects
- Aligned the pre-commit knip invocation with CI (exclude namespace-only findings CI doesn't count) — the hook failed on a clean checkout of `main`
## Testing
- 40 unit tests (`tileConfig` resolution incl. metric/raw-SQL/trace sampling paths, granularity parity with the web's 80-bucket cap, ad-hoc flag → config building, ANSI stripping)
- Live-verified against a real deployment: builder/metric/raw-SQL/quantile charts (incl. auto duration formatting), all display types, dashboard + tile lookup by name and ID, `--json`, all three color modes, error paths, and the TUI page via pty
- `tsc --noEmit`, `yarn ci:lint`, changeset included
New deps (CLI devDependencies, bundled): `asciichart` (zero-dep line plots), `numbro` (number formatting parity with the web).
## Demo
### Dashboard
<img width="1583" height="735" alt="image" src="https://github.com/user-attachments/assets/7c30ff91-bbb8-4ddd-870c-65ac065720d2" />
### chart command
<img width="903" height="322" alt="image" src="https://github.com/user-attachments/assets/0739a920-1dab-443e-b39a-b60b81af46b8" />1 parent 1705b37 commit 386c365
36 files changed
Lines changed: 5257 additions & 49 deletions
File tree
- .changeset
- packages/cli
- src
- __tests__
- api
- components
- EventViewer
- Tile
- termchart
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
56 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
57 | 76 | | |
58 | 77 | | |
59 | 78 | | |
| |||
112 | 131 | | |
113 | 132 | | |
114 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
115 | 184 | | |
116 | 185 | | |
117 | 186 | | |
| |||
127 | 196 | | |
128 | 197 | | |
129 | 198 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
137 | 210 | | |
138 | 211 | | |
139 | 212 | | |
| |||
163 | 236 | | |
164 | 237 | | |
165 | 238 | | |
| 239 | + | |
166 | 240 | | |
167 | 241 | | |
168 | 242 | | |
169 | 243 | | |
170 | 244 | | |
171 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
172 | 251 | | |
173 | 252 | | |
174 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
| |||
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
| 43 | + | |
| 44 | + | |
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
42 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
43 | 61 | | |
44 | 62 | | |
45 | 63 | | |
| |||
60 | 78 | | |
61 | 79 | | |
62 | 80 | | |
| 81 | + | |
| 82 | + | |
63 | 83 | | |
64 | 84 | | |
65 | 85 | | |
| |||
146 | 166 | | |
147 | 167 | | |
148 | 168 | | |
149 | | - | |
150 | | - | |
| 169 | + | |
| 170 | + | |
151 | 171 | | |
152 | 172 | | |
153 | | - | |
| 173 | + | |
154 | 174 | | |
155 | 175 | | |
156 | 176 | | |
157 | 177 | | |
158 | | - | |
159 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
160 | 189 | | |
161 | 190 | | |
162 | 191 | | |
| |||
202 | 231 | | |
203 | 232 | | |
204 | 233 | | |
| 234 | + | |
205 | 235 | | |
206 | 236 | | |
207 | 237 | | |
208 | 238 | | |
209 | 239 | | |
210 | 240 | | |
211 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
212 | 253 | | |
213 | 254 | | |
214 | 255 | | |
215 | 256 | | |
216 | | - | |
217 | | - | |
| 257 | + | |
| 258 | + | |
218 | 259 | | |
219 | 260 | | |
220 | 261 | | |
221 | 262 | | |
222 | 263 | | |
223 | 264 | | |
| 265 | + | |
224 | 266 | | |
225 | 267 | | |
226 | 268 | | |
| |||
0 commit comments