Repository navigation
feat: auto-detect a PromQL source during onboarding #3310
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,8 @@ | ||
| --- | ||
| '@hyperdx/common-utils': patch | ||
| '@hyperdx/app': patch | ||
| --- | ||
|
|
||
| feat: auto-detect a PromQL source during onboarding | ||
|
|
||
| When PromQL is enabled (`NEXT_PUBLIC_ENABLE_PROMQL=true`), onboarding source auto-detection now also creates a PromQL source for a ClickHouse TimeSeries engine table. It prefers `prometheus.metrics` (the table the ClickHouse Prometheus docs suggest), then a table named `metrics_ts`, and otherwise picks the only TimeSeries table on the connection. A service with only a TimeSeries table is no longer sent to manual source setup. |
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
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
176 changes: 176 additions & 0 deletions
176
packages/app/src/components/__tests__/OnboardingModal.test.tsx
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,176 @@ | ||
| import { SourceKind, TSourceNoId } from '@hyperdx/common-utils/dist/types'; | ||
| import { notifications } from '@mantine/notifications'; | ||
| import { screen } from '@testing-library/react'; | ||
|
|
||
| import OnboardingModal from '@/components/OnboardingModal'; | ||
|
|
||
| const mockConfig = { IS_PROMQL_ENABLED: true }; | ||
| jest.mock('@/config', () => ({ | ||
| IS_CLICKHOUSE_BUILD: false, | ||
| IS_LOCAL_MODE: false, | ||
| get IS_PROMQL_ENABLED() { | ||
| return mockConfig.IS_PROMQL_ENABLED; | ||
| }, | ||
| })); | ||
|
|
||
| const mockCreateSource = jest.fn(); | ||
| const mockUpdateSource = jest.fn(); | ||
| // Stable references: new objects on every render would re-run the modal's | ||
| // effects, which depend on them. | ||
| const mockSourcesResult = { data: [] }; | ||
| const mockCreateSourceMutation = { mutateAsync: mockCreateSource }; | ||
| const mockUpdateSourceMutation = { mutateAsync: mockUpdateSource }; | ||
| jest.mock('@/source', () => ({ | ||
| pickTimeSeriesTable: jest.requireActual('@/source').pickTimeSeriesTable, | ||
| PROMQL_TIMESTAMP_EXPRESSION: | ||
| jest.requireActual('@/source').PROMQL_TIMESTAMP_EXPRESSION, | ||
| inferTableSourceConfig: async ({ kind }: { kind: SourceKind }) => ({ | ||
| kind, | ||
| timestampValueExpression: 'Timestamp', | ||
| defaultTableSelectExpression: 'Timestamp, Body', | ||
| }), | ||
| useSources: () => mockSourcesResult, | ||
| useCreateSource: () => mockCreateSourceMutation, | ||
| useUpdateSource: () => mockUpdateSourceMutation, | ||
| useDeleteSource: () => ({ mutateAsync: jest.fn() }), | ||
| })); | ||
|
|
||
| const mockConnectionsResult = { | ||
| data: [{ id: 'conn-1', name: 'Default', host: 'http://localhost:8123' }], | ||
| }; | ||
| jest.mock('@/connection', () => ({ | ||
| useConnections: () => mockConnectionsResult, | ||
| useCreateConnection: () => ({ mutate: jest.fn() }), | ||
| })); | ||
|
|
||
| const mockMetadata = { | ||
| getOtelTables: jest.fn(), | ||
| getTimeSeriesTables: jest.fn(), | ||
| }; | ||
| jest.mock('@/hooks/useMetadata', () => ({ | ||
| useMetadataWithSettings: () => mockMetadata, | ||
| })); | ||
|
|
||
| jest.mock('@/theme/ThemeProvider', () => ({ | ||
| useBrandDisplayName: () => 'HyperDX', | ||
| })); | ||
| jest.mock('@/components/ConnectionForm', () => ({ | ||
| ConnectionForm: () => null, | ||
| })); | ||
| jest.mock('@/components/Sources/SourceForm', () => ({ | ||
| TableSourceForm: () => null, | ||
| })); | ||
| jest.mock('@/components/Sources/SourcesList', () => ({ | ||
| SourcesList: () => null, | ||
| })); | ||
|
|
||
| const OTEL_LOGS_ONLY = { | ||
| database: 'otel', | ||
| tables: { logs: 'otel_logs', metrics: {} }, | ||
| }; | ||
|
|
||
| const createdKinds = () => | ||
| mockCreateSource.mock.calls.map( | ||
| ([{ source }]: [{ source: TSourceNoId }]) => source.kind, | ||
| ); | ||
|
|
||
| describe('OnboardingModal auto-detection', () => { | ||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| // The notifications store is global, so earlier tests' toasts linger. | ||
| notifications.clean(); | ||
| jest.clearAllMocks(); | ||
| mockConfig.IS_PROMQL_ENABLED = true; | ||
| mockCreateSource.mockImplementation( | ||
| async ({ source }: { source: TSourceNoId }) => ({ | ||
| ...source, | ||
| id: `${source.kind}-id`, | ||
| }), | ||
| ); | ||
| mockUpdateSource.mockResolvedValue(undefined); | ||
| mockMetadata.getOtelTables.mockResolvedValue(OTEL_LOGS_ONLY); | ||
| mockMetadata.getTimeSeriesTables.mockResolvedValue([ | ||
| { databaseName: 'default', tableName: 'metrics_ts' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('creates a PromQL source for a detected TimeSeries table', async () => { | ||
| renderWithMantine(<OnboardingModal />); | ||
|
|
||
| await screen.findByText('Automatically detected and created 2 sources.'); | ||
| expect(mockMetadata.getTimeSeriesTables).toHaveBeenCalledWith({ | ||
| connectionId: 'conn-1', | ||
| }); | ||
| expect(createdKinds()).toEqual([SourceKind.Log, SourceKind.Promql]); | ||
| expect(mockCreateSource).toHaveBeenLastCalledWith({ | ||
| source: { | ||
| kind: SourceKind.Promql, | ||
| name: 'PromQL', | ||
| connection: 'conn-1', | ||
| from: { databaseName: 'default', tableName: 'metrics_ts' }, | ||
| timestampValueExpression: 'timestamp', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('skips PromQL detection when PromQL is disabled', async () => { | ||
| mockConfig.IS_PROMQL_ENABLED = false; | ||
|
|
||
| renderWithMantine(<OnboardingModal />); | ||
|
|
||
| await screen.findByText('Automatically detected and created 1 source.'); | ||
| expect(mockMetadata.getTimeSeriesTables).not.toHaveBeenCalled(); | ||
| expect(createdKinds()).toEqual([SourceKind.Log]); | ||
| }); | ||
|
|
||
| it('creates a PromQL source when no OTel tables exist', async () => { | ||
| mockMetadata.getOtelTables.mockResolvedValue(null); | ||
|
|
||
| renderWithMantine(<OnboardingModal />); | ||
|
|
||
| await screen.findByText('Automatically detected and created 1 source.'); | ||
| expect(createdKinds()).toEqual([SourceKind.Promql]); | ||
| }); | ||
|
|
||
| it('keeps the other sources when the PromQL source fails', async () => { | ||
| jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
| mockCreateSource.mockImplementation( | ||
| async ({ source }: { source: TSourceNoId }) => { | ||
| if (source.kind === SourceKind.Promql) { | ||
| throw new Error('boom'); | ||
| } | ||
| return { ...source, id: `${source.kind}-id` }; | ||
| }, | ||
| ); | ||
|
|
||
| renderWithMantine(<OnboardingModal />); | ||
|
|
||
| await screen.findByText('Automatically detected and created 1 source.'); | ||
| expect(createdKinds()).toEqual([SourceKind.Log, SourceKind.Promql]); | ||
| }); | ||
|
|
||
| it('keeps OTel detection when TimeSeries detection fails', async () => { | ||
| jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
| mockMetadata.getTimeSeriesTables.mockRejectedValue(new Error('boom')); | ||
|
|
||
| renderWithMantine(<OnboardingModal />); | ||
|
|
||
| await screen.findByText('Automatically detected and created 1 source.'); | ||
| expect(createdKinds()).toEqual([SourceKind.Log]); | ||
| }); | ||
|
|
||
| it('falls back to manual setup when nothing is detected', async () => { | ||
| mockMetadata.getOtelTables.mockResolvedValue(null); | ||
| mockMetadata.getTimeSeriesTables.mockResolvedValue([]); | ||
|
|
||
| renderWithMantine(<OnboardingModal />); | ||
|
|
||
| await screen.findByText( | ||
| 'Lets set up a source table to query telemetry from.', | ||
| ); | ||
| expect(mockCreateSource).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.