Repository navigation
Commit 022fe89
authored
fix: scope ClickHouse settings cache key by connectionId in NodeClickhouseClient (#2271)
## Summary
- Fix MCP server queries failing with `Setting query_plan_optimize_lazy_materialization is neither a builtin setting` when querying ClickHouse instances that don't support that setting
- Forward `connectionId` in `NodeClickhouseClient.__query()` to `processClickhouseSettings()`, matching the browser client's behavior
- Guard the `metadata.getSettings()` lookup on `connectionId` presence inside `processClickhouseSettings()`, so default settings and externally-provided settings always apply even when `connectionId` is absent
## Problem
`NodeClickhouseClient.__query()` did not destructure or forward `connectionId` to `processClickhouseSettings()`. This caused `metadata.getSettings()` to always use the cache key `"undefined.availableSettings"`.
All `NodeClickhouseClient` instances on the API server (MCP tools, alert checkers, external API charts, etc.) share a single global `MetadataCache` with no TTL. When the first Node-side query hit a ClickHouse that **has** `query_plan_optimize_lazy_materialization` in `system.settings`, that Map was cached under `"undefined.availableSettings"`. Subsequent queries to a **different** ClickHouse (e.g. an older version) reused the stale cache, `applySettingIfAvailable` saw the setting as available, and ClickHouse rejected it.
The browser client was unaffected because `BrowserClickhouseClient.__query()` already passes `connectionId`, scoping the cache key correctly as `"<connectionId>.availableSettings"`.
## Approach
The `connectionId` guard is placed **inside** `processClickhouseSettings()` around only the `metadata.getSettings()` call, rather than wrapping the entire function at the call site. This ensures:
- **Default settings** (`allow_experimental_analyzer`, `max_execution_time`, `output_format_json_quote_64bit_integers`, etc.) always apply
- **Externally-provided** `clickhouse_settings` always flow through
- **Server-specific optimization settings** (lazy materialization, skip indexes, etc.) are only looked up when `connectionId` is present, preventing the `"undefined.availableSettings"` cache key collision
## Changes
| File | Change |
|------|--------|
| `packages/common-utils/src/clickhouse/node.ts` | Destructure `connectionId` from `QueryInputs` and forward it to `processClickhouseSettings()` |
| `packages/common-utils/src/clickhouse/index.ts` | Guard `metadata.getSettings()` on `connectionId` presence inside `processClickhouseSettings()` — returns `undefined` serverSettings when missing, so defaults still apply |
| `packages/common-utils/src/core/metadata.ts` | Make `connectionId` required (`string`, was `string?`) in `getSettings()` to prevent future callers from passing `undefined` |
| `packages/common-utils/src/__tests__/clickhouse.test.ts` | Add `connectionId: 'test-conn'` to tests exercising the server settings lookup path |1 parent d3a5a57 commit 022fe89
5 files changed
Lines changed: 29 additions & 5 deletions
File tree
- .changeset
- packages/common-utils/src
- __tests__
- clickhouse
- core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
| 475 | + | |
475 | 476 | | |
476 | 477 | | |
477 | 478 | | |
| |||
504 | 505 | | |
505 | 506 | | |
506 | 507 | | |
| 508 | + | |
507 | 509 | | |
508 | 510 | | |
509 | 511 | | |
| |||
531 | 533 | | |
532 | 534 | | |
533 | 535 | | |
| 536 | + | |
534 | 537 | | |
535 | 538 | | |
536 | 539 | | |
| |||
582 | 585 | | |
583 | 586 | | |
584 | 587 | | |
| 588 | + | |
585 | 589 | | |
586 | 590 | | |
587 | 591 | | |
| |||
602 | 606 | | |
603 | 607 | | |
604 | 608 | | |
605 | | - | |
606 | | - | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
607 | 619 | | |
608 | 620 | | |
609 | 621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
532 | 532 | | |
533 | 533 | | |
534 | 534 | | |
535 | | - | |
536 | | - | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
537 | 542 | | |
538 | 543 | | |
539 | 544 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
845 | 845 | | |
846 | 846 | | |
847 | 847 | | |
848 | | - | |
| 848 | + | |
849 | 849 | | |
850 | 850 | | |
851 | 851 | | |
| |||
0 commit comments