-
Notifications
You must be signed in to change notification settings - Fork 457
fix(common-utils): guard metadata rollup queries against invalid date… #2941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Vansh98789
wants to merge
6
commits into
hyperdxio:main
Choose a base branch
from
Vansh98789:fix/invalid-date-metadata-rollup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−5
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1ecf4d6
fix(common-utils): guard metadata rollup queries against invalid date…
Vansh98789 65102f3
Merge branch 'main' into fix/invalid-date-metadata-rollup
Vansh98789 b1ee8b4
Merge branch 'main' into fix/invalid-date-metadata-rollup
teeohhem 9d3f605
fix(common-utils,app): include call-site context in invalid date rang…
Vansh98789 7e5e9f7
Merge branch 'fix/invalid-date-metadata-rollup' of https://github.com…
Vansh98789 7e7736a
Merge branch 'main' into fix/invalid-date-metadata-rollup
Vansh98789 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@hyperdx/common-utils": patch | ||
| --- | ||
|
|
||
| Skip metadata key/value rollup queries when the date range contains an Invalid Date instead of binding NaN timestamps as ClickHouse `Int64` params, which failed with `BAD_QUERY_PARAMETER` (457). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { Metadata, MetadataCache } from '@/core/metadata'; | ||
| import { isDateRangeValid } from '@/core/utils'; | ||
| import type { BaseClickhouseClient } from '@/clickhouse'; | ||
| const invalidDate = new Date('not-a-date'); | ||
|
|
||
| describe('isDateRangeValid', () => { | ||
| it('accepts valid date ranges', () => { | ||
| expect( | ||
| isDateRangeValid([ | ||
| new Date('2026-08-01T00:00:00Z'), | ||
| new Date('2026-08-02T00:00:00Z'), | ||
| ]), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects a range with an invalid start', () => { | ||
| expect(isDateRangeValid([invalidDate, new Date()])).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects a range with an invalid end', () => { | ||
| expect(isDateRangeValid([new Date(), invalidDate])).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getMapKeys date range guard', () => { | ||
| it('returns [] and never queries ClickHouse for an invalid date range', async () => { | ||
| const query = jest | ||
| .fn() | ||
| .mockRejectedValue(new Error('should not be called')); | ||
| const metadata = new Metadata( | ||
| query as unknown as BaseClickhouseClient, | ||
| new MetadataCache(), | ||
| ); | ||
|
|
||
| const keys = await metadata.getMapKeys({ | ||
| databaseName: 'db', | ||
| tableName: 'tbl', | ||
| column: 'attributes', | ||
| connectionId: 'conn', | ||
| metadataMVs: { granularity: 'minute' } as any, | ||
| dateRange: [invalidDate, invalidDate], | ||
| }); | ||
|
|
||
| expect(keys).toEqual([]); | ||
| expect(query).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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:
Let me know if there's another producer you've seen in the query_log this doesn't cover.