-
Notifications
You must be signed in to change notification settings - Fork 343
fix: Strip trailing slash for connections #752
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
4 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,5 @@ | ||
| --- | ||
| "@hyperdx/app": patch | ||
| --- | ||
|
|
||
| Removes trailing slash for connection urls |
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
165 changes: 165 additions & 0 deletions
165
packages/app/src/components/__tests__/ConnectionForm.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,165 @@ | ||
| import React from 'react'; | ||
| import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
|
|
||
| import { Connection } from '../../connection'; | ||
| import { ConnectionForm } from '../ConnectionForm'; | ||
|
|
||
| import '@testing-library/jest-dom'; | ||
|
|
||
| // --- Mocks --- | ||
| const mockCreateMutate = jest.fn(); | ||
| const mockUpdateMutate = jest.fn(); | ||
| jest.mock('@/connection', () => ({ | ||
| ...jest.requireActual('@/connection'), | ||
| useCreateConnection: () => ({ | ||
| mutate: mockCreateMutate, | ||
| isPending: false, | ||
| }), | ||
| useUpdateConnection: () => ({ | ||
| mutate: mockUpdateMutate, | ||
| isPending: false, | ||
| }), | ||
|
|
||
| useDeleteConnection: () => ({ | ||
| mutate: jest.fn(), | ||
| isPending: false, | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('@mantine/notifications', () => ({ | ||
| notifications: { | ||
| show: jest.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| const mockTestConnectionMutateAsync = jest.fn(); | ||
| jest.mock('@/api', () => ({ | ||
| ...(jest.requireActual('@/api') ?? {}), | ||
| useTestConnection: () => ({ | ||
| mutateAsync: mockTestConnectionMutateAsync.mockResolvedValue({ | ||
| success: true, | ||
| }), | ||
| }), | ||
| })); | ||
|
|
||
| // --- Test Suite --- | ||
|
|
||
| describe('ConnectionForm', () => { | ||
| const baseConnection: Connection = { | ||
| id: '', | ||
| name: 'Test Connection', | ||
| host: 'http://localhost:8123', | ||
| username: 'default', | ||
| password: '', | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| mockCreateMutate.mockClear(); | ||
| mockUpdateMutate.mockClear(); | ||
| mockTestConnectionMutateAsync.mockClear(); | ||
| ( | ||
| jest.requireMock('@mantine/notifications') as any | ||
| ).notifications.show.mockClear(); | ||
| }); | ||
|
|
||
| it('should save connection with trailing slash removed from host when creating', async () => { | ||
| renderWithMantine( | ||
| <ConnectionForm connection={baseConnection} isNew={true} />, | ||
| ); | ||
|
|
||
| const hostInput = screen.getByPlaceholderText('http://localhost:8123'); | ||
| const nameInput = screen.getByPlaceholderText('My Clickhouse Server'); | ||
| const submitButton = screen.getByRole('button', { name: 'Create' }); | ||
|
|
||
| await fireEvent.change(nameInput, { target: { value: 'Test Name' } }); | ||
| await fireEvent.change(hostInput, { | ||
| target: { value: 'http://example.com:8123/' }, | ||
| }); // Host with trailing slash | ||
|
|
||
| fireEvent.click(submitButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockCreateMutate).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| // Check the arguments passed to the mutate function | ||
| expect(mockCreateMutate).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| connection: expect.objectContaining({ | ||
| host: 'http://example.com:8123', | ||
| name: 'Test Name', | ||
| }), | ||
| }), | ||
| expect.anything(), | ||
| ); | ||
| }); | ||
|
|
||
| it('should save connection with trailing slash removed from host when updating', async () => { | ||
| const existingConnection = { | ||
| ...baseConnection, | ||
| id: 'existing-id', | ||
| host: 'http://old.com/', | ||
| }; | ||
| renderWithMantine( | ||
| <ConnectionForm connection={existingConnection} isNew={false} />, | ||
| ); | ||
|
|
||
| const hostInput = screen.getByPlaceholderText('http://localhost:8123'); | ||
| const submitButton = screen.getByRole('button', { name: 'Save' }); | ||
|
|
||
| // Update host | ||
| await fireEvent.change(hostInput, { | ||
| target: { value: 'http://updated.com:8123/' }, | ||
| }); | ||
|
|
||
| fireEvent.click(submitButton); | ||
|
|
||
| // Wait for mutate to be called and assert | ||
| await waitFor(() => { | ||
| expect(mockUpdateMutate).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| // Check the arguments passed to the mutate function | ||
| expect(mockUpdateMutate).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| id: 'existing-id', | ||
| connection: expect.objectContaining({ | ||
| host: 'http://updated.com:8123', | ||
| }), | ||
| }), | ||
| expect.anything(), | ||
| ); | ||
| }); | ||
|
|
||
| it('should use stripped host for test connection', async () => { | ||
| renderWithMantine( | ||
| <ConnectionForm connection={baseConnection} isNew={true} />, | ||
| ); | ||
| const hostInput = screen.getByPlaceholderText('http://localhost:8123'); | ||
|
|
||
| const nameInput = screen.getByPlaceholderText('My Clickhouse Server'); | ||
| const testButton = screen.getByRole('button', { name: 'Test Connection' }); | ||
|
|
||
| await fireEvent.change(nameInput, { target: { value: 'Test Name' } }); | ||
| await fireEvent.change(hostInput, { | ||
| target: { value: 'http://test.com:8123/' }, | ||
| }); | ||
|
|
||
| // Ensure form state is valid before clicking test | ||
| await waitFor(() => expect(testButton).not.toBeDisabled()); | ||
|
|
||
| fireEvent.click(testButton); | ||
|
|
||
| await waitFor(() => | ||
| expect(mockTestConnectionMutateAsync).toHaveBeenCalled(), | ||
| ); | ||
|
|
||
| // Assert that the mock API call received the stripped host | ||
| expect(mockTestConnectionMutateAsync).toHaveBeenCalledTimes(1); | ||
| expect(mockTestConnectionMutateAsync).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| host: 'http://test.com:8123', | ||
| }), | ||
| ); | ||
| }); | ||
| }); |
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
98 changes: 49 additions & 49 deletions
98
smoke-tests/otel-collector/data/auto-parse/default/input.json
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 |
|---|---|---|
| @@ -1,53 +1,53 @@ | ||
| { | ||
| "resourceLogs": [ | ||
| "resourceLogs": [ | ||
| { | ||
| "resource": { | ||
| "attributes": [ | ||
| { | ||
| "key": "suite-id", | ||
| "value": { | ||
| "stringValue": "auto-parse" | ||
| } | ||
| }, | ||
| { | ||
| "key": "test-id", | ||
| "value": { | ||
| "stringValue": "default" | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "scopeLogs": [ | ||
| { | ||
| "resource": { | ||
| "attributes": [ | ||
| { | ||
| "key": "suite-id", | ||
| "value": { | ||
| "stringValue": "auto-parse" | ||
| } | ||
| }, | ||
| { | ||
| "key": "test-id", | ||
| "value": { | ||
| "stringValue": "default" | ||
| } | ||
| } | ||
| ] | ||
| "scope": {}, | ||
| "logRecords": [ | ||
| { | ||
| "timeUnixNano": "1901999580000000000", | ||
| "body": { | ||
| "stringValue": "[note] this is very much not JSON even though it starts with an array char" | ||
| } | ||
| }, | ||
| "scopeLogs": [ | ||
| { | ||
| "scope": {}, | ||
| "logRecords": [ | ||
| { | ||
| "timeUnixNano": "1901999580000000000", | ||
| "body": { | ||
| "stringValue": "[note] this is very much not JSON even though it starts with an array char" | ||
| } | ||
| }, | ||
| { | ||
| "timeUnixNano": "1901999580000000001", | ||
| "body": { | ||
| "stringValue": "{note} this is very much not JSON even though it starts with an object char" | ||
| } | ||
| }, | ||
| { | ||
| "timeUnixNano": "1901999580000000002", | ||
| "body": { | ||
| "stringValue": "NOTE: this is very much not JSON" | ||
| } | ||
| }, | ||
| { | ||
| "timeUnixNano": "1901999580000000003", | ||
| "body": { | ||
| "stringValue": "this has some {Key {Value { '{' } } invalid JSON in it" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| { | ||
| "timeUnixNano": "1901999580000000001", | ||
| "body": { | ||
| "stringValue": "{note} this is very much not JSON even though it starts with an object char" | ||
| } | ||
| }, | ||
| { | ||
| "timeUnixNano": "1901999580000000002", | ||
| "body": { | ||
| "stringValue": "NOTE: this is very much not JSON" | ||
| } | ||
| }, | ||
| { | ||
| "timeUnixNano": "1901999580000000003", | ||
| "body": { | ||
| "stringValue": "this has some {Key {Value { '{' } } invalid JSON in it" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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.
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.
Probably out of scope. I wonder if we should handle this on the API side to always remove the trailing slash before any update/insert operations since I suspect the clickhouse client would throw with the malformed host
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.
We definitely should also be handling this in the API, but it was a slippery slope exclusively making that solution. I'll add in the API side as well.