-
Notifications
You must be signed in to change notification settings - Fork 17
feat: parse logging link as default value #2036
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 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
702cf05
feat: parse logging link as default value
astandrik 124cc57
Update src/utils/__test__/logs.test.ts
astandrik 77201df
fix: add level
astandrik 641168c
fix: review fixes
astandrik bc654d6
fix: comment fixes
astandrik 8a39923
fix: better code
astandrik 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import {getLogsLink} from '../logs'; | ||
|
|
||
| describe('getLogsLink', () => { | ||
| test('should insert dbName into logs URL query', () => { | ||
| const loggingData = { | ||
| url: 'https://monitoring.yandex-team.ru/projects/kikimr/logs?from=now-1h&to=now&query=%7Bproject+%3D+%22kikimr%22%2C+service+%3D+%22ydb%22%2C+cluster+%3D+%22ydb-ru-prestable%22%7D', | ||
| }; | ||
|
|
||
| const result = getLogsLink({ | ||
| logging: JSON.stringify(loggingData), | ||
| dbName: 'testdb', | ||
| }); | ||
|
|
||
| // The URL should contain the dbName in the query parameter | ||
| expect(result).toContain('database+%3D+%22testdb%22'); | ||
| // Original query parts should still be present | ||
| expect(result).toContain('project+%3D+%22kikimr%22'); | ||
| expect(result).toContain('service+%3D+%22ydb%22'); | ||
| expect(result).toContain('cluster+%3D+%22ydb-ru-prestable%22'); | ||
| }); | ||
|
|
||
| test('should handle empty query parameters', () => { | ||
| const loggingData = { | ||
| url: 'https://monitoring.yandex-team.ru/projects/kikimr/logs?from=now-1h&to=now&query=%7B%7D', | ||
| }; | ||
|
|
||
| const result = getLogsLink({ | ||
| logging: JSON.stringify(loggingData), | ||
| dbName: 'testdb', | ||
| }); | ||
|
|
||
| // Should add dbName to empty query | ||
| expect(result).toContain('database+%3D+%22testdb%22'); | ||
| }); | ||
|
|
||
| test('should return empty string for invalid data', () => { | ||
| expect( | ||
| getLogsLink({ | ||
| logging: 'invalid json', | ||
| dbName: 'testdb', | ||
| }), | ||
| ).toBe(''); | ||
|
|
||
| expect( | ||
| getLogsLink({ | ||
| logging: JSON.stringify({}), | ||
| dbName: 'testdb', | ||
| }), | ||
| ).toBe(''); | ||
| }); | ||
| }); | ||
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,37 @@ | ||
| interface GetLogsLinkProps { | ||
| dbName: string; | ||
| logging: string; | ||
| } | ||
|
|
||
| export type GetLogsLink = (props: GetLogsLinkProps) => string; | ||
|
|
||
| export function getLogsLink({dbName, logging}: GetLogsLinkProps): string { | ||
| try { | ||
| const data = JSON.parse(logging); | ||
|
|
||
| if (typeof data === 'object' && 'url' in data) { | ||
| const logUrl = data.url; | ||
| if (!logUrl) { | ||
| return ''; | ||
| } | ||
|
|
||
| const url = new URL(logUrl); | ||
|
|
||
| const queryParam = url.searchParams.get('query'); | ||
| if (queryParam) { | ||
| const decodedQuery = decodeURIComponent(queryParam); | ||
|
|
||
| const updatedQuery = decodedQuery.replace(/\{([^}]*)\}/, (_match, contents) => { | ||
artemmufazalov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const trimmedContents = contents.trim(); | ||
| return `{${trimmedContents}${trimmedContents ? ', ' : ''}database = "${dbName}"}`; | ||
artemmufazalov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| url.searchParams.set('query', updatedQuery); | ||
| } | ||
|
|
||
| return url.toString(); | ||
| } | ||
| } catch {} | ||
|
|
||
astandrik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return ''; | ||
| } | ||
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.