fix(common-utils): guard metadata rollup queries against invalid date… - #2941
fix(common-utils): guard metadata rollup queries against invalid date…#2941Vansh98789 wants to merge 6 commits into
Conversation
🦋 Changeset detectedLatest commit: 7e7736a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
@Vansh98789 is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThe PR prevents non-finite or out-of-range URL timestamps from becoming invalid dates and adds guards around metadata rollup queries.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains within the eligible follow-up-review scope. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| packages/app/src/timeQuery.ts | Replaces the generic float parser with a finite, Date-range-bounded epoch parser for URL-backed time state. |
| packages/common-utils/src/core/metadata.ts | Adds invalid-date guards before metadata rollup query construction and expands diagnostic context. |
| packages/common-utils/src/core/utils.ts | Adds a shared helper that validates both date-range bounds as finite timestamps. |
| packages/common-utils/src/core/tests/metadata.test.ts | Covers date-range validation and verifies that getMapKeys avoids ClickHouse for invalid dates. |
| .changeset/tidy-invalid-dates.md | Records the common-utils metadata-query fix as a patch release. |
Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/invalid-dat..." | Re-trigger Greptile
Deep ReviewScope: 5 files vs base ✅ No critical issues found. The core fix is sound: 🟡 P2 -- recommended
🔵 P3 nitpicks (5)
Reviewers (6): correctness, testing, maintainability, project-standards, kieran-typescript, previous-comments. Testing gaps:
Residual risk (out of scope for this diff): the URL-parser fix only covers the |
| 'getMapKeys: skipping metadata queries, dateRange contains an invalid date', | ||
| dateRange, | ||
| ); | ||
| return []; |
There was a problem hiding this comment.
I'm not sure if it's a good idea to return [] here, since that would produce falsy results. For this ticket, the intent is to figure out what in the app is generating the invalid date range.
There was a problem hiding this comment.
@wrn14897 Traced the root cause: parseAsFloat in timeQuery.ts only rejects NaN, not Infinity or out-of-range values. A URL like ?from=1e400 parses to Infinity, which becomes new Date(Infinity) = Invalid Date downstream - that's what's producing the "nan" Int64 param.
Two changes pushed to this branch:
- timeQuery.ts - added a parser that rejects non-finite/out-of-range from/to values at the URL-parsing stage, so the Invalid Date can't be constructed from this path anymore.
- metadata.ts - kept the return [] guard as-is per your concern, but added call-site context (database/table/column) and a stack trace to the warning, so if it ever fires again, it's traceable back to the caller instead of silent.
Let me know if there's another producer you've seen in the query_log this doesn't cover.
…e warnings; reject non-finite/out-of-range time query params
…/Vansh98789/hyperdx into fix/invalid-date-metadata-rollup
Summary
Fixes
BAD_QUERY_PARAMETER(457) failures on metadata key/value rollup queries (e.g. filter dropdowns and field lists).When a metadata query is built with an invalid date in its date range,
Date.getTime()returnsNaN. ThatNaNis serialized as the literal string"nan"and bound to a ClickHouseInt64parameter, causing the query to fail with:This happens in two places in
metadata.ts:getMapKeys— builds rollup queries fromgetAlignedDateRange(dateRange, granularity)and binds{ Int64: date.getTime() }getMetadataMVKeyValues— same pattern for batched key/value lookupsChanges
common-utils/src/core/utils.tsisDateRangeValid(dateRange)— returnsfalseif either bound'sgetTime()is not a finite numbercommon-utils/src/core/metadata.tsgetMapKeys— skips metadata queries and returns[]when the date range is invalidcommon-utils/src/core/metadata.tsgetMetadataMVKeyValues— returnsundefinedso callers fall through to the raw-table strategycommon-utils/src/core/__tests__/metadata.test.tsgetMapKeysguard.changeset/tidy-invalid-dates.mdTests
isDateRangeValidaccepts a valid rangeisDateRangeValidrejects a range with an invalid start dateisDateRangeValidrejects a range with an invalid end dategetMapKeysreturns[]and never calls ClickHouse when given an invalid rangeTest command
cd packages/common-utils npx jest src/core/__tests__/metadata.test.tsScreenshots or video
N/A — non-UI change.
How to test on Vercel preview
N/A — non-UI change.
References