Skip to content

fix: apply source query settings to metric metadata lookups - #3766

Open
karl-power wants to merge 2 commits into
mainfrom
claude/hdx-6052-metric-source-query-settings
Open

karl-power wants to merge 2 commits into
mainfrom
claude/hdx-6052-metric-source-query-settings

Conversation

@karl-power

@karl-power karl-power commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Metric metadata lookups now apply the source's query settings, so settings like force_optimize_skip_unused_shards=0 reach them. Without this, the metric browser showed "Could not load metrics" on sharded metric tables whose server profile sets force_optimize_skip_unused_shards=1, while chart queries on the same source worked.

  • Added querySettingsToClickHouseSettings() in common-utils to turn a source's querySettings into client settings.
  • Metadata.getMetricNames and Metadata.streamDistinctIndexValues accept querySettings; useMetricNames passes the source's settings to both and keys on them.
  • useMetricCatalog (metric browser), useFetchMetricAttributeValues, useFetchMetricResourceAttrs and useFetchMetricMetadata apply the source's settings.
  • useAvailableMetricNames and KubernetesFilters set source on their chart config so useGetKeyValues applies the source's settings.
  • Each lookup's own settings are merged after the source's, so a source can't override its timeout behaviour.

How to reproduce

The original error needs a Distributed metrics table with a sharding key and force_optimize_skip_unused_shards=1 in the user's profile. The steps below check that the setting is sent instead, which works on any setup.

Starting point: yarn dev with a metrics source.

On main:

  1. In Team settings → Sources, edit the metrics source and under "Query Settings" click "Add Setting", then add force_optimize_skip_unused_shards = 0 and save.
  2. Open the browser DevTools Network tab.
  3. Create a dashboard tile, pick the metrics source, and open the metric name dropdown.
  4. Open the ClickHouse request whose body contains mergeTreeIndex (or GROUP BY MetricName after typing a search): force_optimize_skip_unused_shards is not in its URL parameters.
  5. Click "Browse metrics": the catalog requests also lack the setting.

On this branch:

  1. Repeat the steps above: every request carries force_optimize_skip_unused_shards=0.

How to test on Vercel preview

N/A — non-UI change

References

  • Linear Issue: Fixes HDX-6052
  • Related PRs:

@karl-power
karl-power requested a review from a team as a code owner November 23, 2026 10:08
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 23, 2026 10:28am UTC
hyperdx-storybook Ready Ready Preview Nov 23, 2026 10:28am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 32516df

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Patch
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Additional context: spans packages but only 53 prod lines — under the 100-line cross-layer bar

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 10
  • Production lines changed: 53 (+ 404 in test files, excluded from tier calculation)
  • Branch: claude/hdx-6052-metric-source-query-settings
  • Author: karl-power

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 108 in total (1.13%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

2 finding(s): 🔴 0 P0/P1 · 🟡 0 P2 · 🔵 2 P3

No inline comments. 2 P3 folded at the bottom.

🔵 2 P3 — no action needed before merge
  • 🔵 P3 packages/common-utils/src/core/utils.ts:65 — New querySettingsToClickHouseSettings duplicates the conversion already inline in mcpQuerySettings → packages/api/src/mcp/tools/trace/shared.ts:40 already does Object.fromEntries(querySettings.map(s => [s.setting, s.value])). That is the same operation, and the repo's REQUIRED DRY rule applies. Make mcpQuerySettings call querySettingsToClickHouseSettings(querySettings) so the conversion lives in one place.
  • 🔵 P3 packages/app/src/hooks/__tests__/useFetchMetricResourceAttrs.test.tsx:19 — Identical source fixture, wrapper and settingsSent helper copied into four new test blocks → useFetchMetricAttributeValues.test.tsx, useFetchMetricMetadata.test.tsx, useFetchMetricResourceAttrs.test.tsx and useMetricCatalog.test.ts each redefine the same TMetricSource fixture with querySettings, the same QueryClient wrapper and the same settingsSent helper. Move these into one shared test helper module, or put the three useFetchMetric* cases in a single file, so the fixture has one source of truth.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 469 passed • 1 skipped • 1175s

Status Count
✅ Passed 469
❌ Failed 0
⚠️ Flaky 15
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

Metric name, catalog, attribute, and Kubernetes facet lookups ignored the
source's query settings, so settings like
force_optimize_skip_unused_shards=0 never reached them and the metric
browser failed on sharded tables.

Refs HDX-6052
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This is a focused, well-tested 53-line change that plumbs a metric source's querySettings into the metric metadata lookups (names, catalog, attribute values, resource attrs, metadata). The core invariant — source settings merged before each lookup's pinned timeout/row-cap so a source cannot widen its own timeout — holds on every path that pins one, and the useFetchMetricAttributeValues test even asserts timeout_overflow_mode: 'break' while the source requests 'throw', locking that behaviour. Cache invalidation is correct: hooks that key on individual fields (useFetchMetricMetadata) add querySettings explicitly, while hooks keying on the whole tableSource/source object get it transitively. No P0/P1 issues surfaced.

🟡 P2 — recommended

  • packages/app/src/hooks/useMetricCatalog.ts:145 — the "source can't override the pinned bound" invariant is asserted only on the useFetchMetricAttributeValues path; useMetricCatalog (pins max_execution_time: MAX_EXEC_SECONDS) and Metadata.getMetricNames (pins max_rows_to_read: '0') also spread source settings before their pins but have no test guarding that ordering, so a future reorder could silently let a source clobber those caps.
    • Fix: Add a test on each pinning path that sets the pinned key in the source querySettings and asserts the lookup's pinned value still wins.
🔵 P3 nitpicks (4)
  • packages/common-utils/src/core/utils.ts:65 — the new exported querySettingsToClickHouseSettings has no dedicated unit test for undefined/empty input or duplicate setting keys; it is exercised only indirectly through hook and streamDistinctIndexValues tests.
    • Fix: Add a direct unit test covering undefined, empty-array, multi-setting, and duplicate-key inputs.
  • packages/app/src/hooks/useMetricCatalog.ts:152 — the { ...querySettingsToClickHouseSettings(src), max_execution_time, timeout_overflow_mode } merge shape is repeated in useFetchMetricAttributeValues.tsx and Metadata.getMetricNames.
    • Fix: Extract a small helper that merges source settings under a fixed set of pinned bounds so the ordering lives in one place.
  • packages/common-utils/src/core/utils.ts:65 — utils.ts now holds two parallel converters for the same input: joinQuerySettings (renders a numeric SQL SETTINGS clause) and querySettingsToClickHouseSettings (string-valued clickhouse_settings object), which a future caller could confuse.
    • Fix: Add a one-line doc comment on each noting which transport path it targets and why values differ (SQL literal vs HTTP param).
  • packages/common-utils/src/core/metadata.ts:1171 — streamDistinctIndexValues spreads source querySettings after this.getClickHouseSettings() with no subsequent re-pin, unlike the other lookups, so on this path a source could override a base setting; low impact today since nothing load-bearing is pinned, but it diverges from the stated invariant.
    • Fix: If any base setting here must be authoritative, re-pin it after the source spread; otherwise add a comment noting the intentional difference.

Reviewers (9): correctness, testing, maintainability, project-standards, kieran-typescript, api-contract, adversarial, security, performance.

Testing gaps: The merge-order invariant is verified on only one of the three paths that pin a bound after the source spread; the new querySettingsToClickHouseSettings helper lacks a direct unit test.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

This branch was successfully deployed

2 active deployments
Preview – hyperdx-storybook — 04321b66 Deployed Nov 23, 2026 by vercel[bot]
Preview – hyperdx-oss — 04321b66 Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant