Skip to content

fix(common-utils): cast Exemplars.TimeUnix before toUnixTimestamp64Milli - #3769

Open
Achlesha wants to merge 3 commits into
ClickHouse:jordansimonovski/exemplars-overlayfrom
Achlesha:fix/exemplar-timeunix-datetime
Open

Achlesha wants to merge 3 commits into
ClickHouse:jordansimonovski/exemplars-overlayfrom
Achlesha:fix/exemplar-timeunix-datetime

Conversation

@Achlesha

Copy link
Copy Markdown

Tried this branch against a Metrics source whose otel_metrics_histogram was created by the OTel ClickHouse exporter. No markers render. The exemplar scan fails:

Code: 43. DB::Exception: A value of illegal type was provided as 1st argument 'value' to function
'toUnixTimestamp64Milli'. Expected: DateTime64, got: DateTime

renderMetricExemplarsChartConfig selects toUnixTimestamp64Milli(ex_TimeUnix). That works with the e2e schema (docker/clickhouse/local/init-db-e2e.sh:190, Array(DateTime64(9))), but not where Exemplars.TimeUnix is Array(DateTime):

  • the exporter's schema (contrib clickhouseexporter v0.159.0)
  • this repo's seed schema, docker/otel-collector/schema/seed/00003_otel_metrics.sql:21

Same result on ClickHouse 26.5 and 26.8. Casting first fixes it. It is a no-op for DateTime64 columns and keeps their precision:

-      toUnixTimestamp64Milli(ex_TimeUnix) AS timestamp,
+      toUnixTimestamp64Milli(toDateTime64(ex_TimeUnix, 9)) AS timestamp,

in packages/common-utils/src/core/renderChartConfig.ts. The matching assertion in packages/common-utils/src/__tests__/renderChartConfig.test.ts becomes toContain('toUnixTimestamp64Milli(toDateTime64(ex_TimeUnix, 9))').

With that change, markers render, the hover card shows the exemplar, and "Inspect trace" opens the trace. queryChartConfig.int.test.ts already creates an Array(DateTime) exemplar table, so an integration test of the scan there would catch this.

Quick repro:

SELECT toUnixTimestamp64Milli(toDateTime('2026-11-23 10:00:00'));                  -- Code 43
SELECT toUnixTimestamp64Milli(toDateTime64(toDateTime('2026-11-23 10:00:00'), 9)); -- ok

Screenshots or video

Before After
No markers. The console shows ClickHouseQueryError: … toUnixTimestamp64Milli … Expected: DateTime64, got: DateTime after-markers-hovercard

Exemplars.TimeUnix is Array(DateTime) in the seed schema and the OTel ClickHouse exporter; toUnixTimestamp64Milli only accepts DateTime64.
test(common-utils): expect the DateTime64 cast in the exemplar scan
@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@Achlesha is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4e114fc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions Bot added external needs-vouch Author needs a maintainer to vouch for them labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @Achlesha, thanks for the pull request!

Before we review code from a first-time contributor, a maintainer vouches for them, and you're not on our list yet. There's nothing else to file and this PR stays open — a maintainer will look at it, usually within a day or two, and vouch for you right here if it's a genuine attempt at the problem.

To make that quick, check the PR description has:

  • The issue it addresses (ideally one labelled Accepting PR) and why the change is needed
  • Steps to reproduce the problem and verify the fix, starting from https://play.hyperdx.io or yarn app:dev:local connected to the demo server
  • Before/after screenshots if anything in the UI changed

More detail in our contributing guide.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

✅ No issues found.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

The core change is sound. toUnixTimestamp64Milli(toDateTime64(ex_TimeUnix, 9)) is a widening conversion that is lossless for Array(DateTime) (second → nanosecond precision), a no-op for Array(DateTime64(9)), and introduces no timezone sensitivity since toUnixTimestamp64Milli returns absolute epoch milliseconds. The DateTime range sits entirely inside DateTime64(9)'s representable range, so no overflow edge case exists. The new integration test correctly declares and exercises the Array(DateTime) column, and its assertions check exact timestamp, value, trace id, and row count rather than truthiness.

The issues worth raising are the unrelated documentation edits bundled into this bug-fix diff, two of which are factually inconsistent with the current repository.

🟡 P2 -- recommended

  • .claude/skills/refactor-component/SKILL.md:181 -- the lint-fix instruction was changed to npx oxlint --fix and npx oxfmt, but every package in the repo lints exclusively with eslint (root package.json and packages/*/package.json lint/lint:fix scripts, plus the lint-staged hook) and no oxlint/oxfmt config exists, so an agent following this would run a tool that never applies the repo's configured import-sort and formatting rules.
    • Fix: revert the instruction to the eslint --fix command that matches the repo's actual lint tooling.
🔵 P3 nitpicks (3)
  • AGENTS.md:37 -- the diff renames the local metadata store to "DocumentDB" here and at lines 47, 465, and 479 (and in .claude/skills/playwright/SKILL.md:81, .claude/agents/playwright-test-planner.md:66, .claude/agents/playwright-test-generator.md:61), but docker-compose.yml, docker-compose.dev.yml, and docker-compose.ci.yml all run image: mongo:5.0.32-focal with service label mongodb and env HDX_DEV_MONGO_PORT, so the docs now contradict the compose files.
    • Fix: reconcile the documentation with the compose configuration so the named store matches the image actually run in local dev.
  • AGENTS.md:37 -- the MongoDB→DocumentDB and eslint→oxlint documentation renames are three independent concerns bundled into a diff whose stated purpose is a single SQL-cast fix, which hurts reviewability and clean revert/bisect.
    • Fix: move the documentation edits into a separate docs-only PR so the exemplar fix stays isolated and independently revertable.
  • packages/common-utils/src/core/renderChartConfig.ts:3691 -- the explanatory comment ("...in the seed schema and the OTel exporter's, Array(DateTime64(9)) elsewhere") elides the noun after the possessive and reads slightly ambiguously.
    • Fix: reword to spell out the contrast, e.g. "...in the seed schema and the OTel exporter's output, but Array(DateTime64(9)) elsewhere."

Reviewers (6): correctness, testing, maintainability, project-standards, kieran-typescript, previous-comments.

Testing gaps:

  • No integration test executes the generated scan against an Array(DateTime64(9)) column, so the "lossless no-op for DateTime64" half of the fix is verified only by the unit string assertion, not by a real query.
  • Fixtures use whole-second timestamps, so no test proves the toDateTime64(x, 9) path preserves sub-second precision.
  • Prior PR comments are all automation notices (Vercel, changeset-bot, contributor-vouch bot) with no actionable code feedback.

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 has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external needs-vouch Author needs a maintainer to vouch for them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant