Skip to content

Commit 641168c

Browse files
committed
fix: review fixes
1 parent 77201df commit 641168c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/utils/__test__/logs.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {getLogsLink} from '../logs';
33
describe('getLogsLink', () => {
44
test('should insert dbName into logs URL query', () => {
55
const loggingData = {
6-
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',
6+
url: 'https://logging.url/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',
77
};
88

99
const result = getLogsLink({
@@ -12,16 +12,14 @@ describe('getLogsLink', () => {
1212
});
1313

1414
// The URL should contain the dbName in the query parameter
15-
expect(result).toContain('database+%3D+%22testdb%22');
16-
// Original query parts should still be present
17-
expect(result).toContain('project+%3D+%22kikimr%22');
18-
expect(result).toContain('service+%3D+%22ydb%22');
19-
expect(result).toContain('cluster+%3D+%22ydb-ru-prestable%22');
15+
expect(result).toBe(
16+
'https://logging.url/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%2C+database+%3D+%22testdb%22%7D',
17+
);
2018
});
2119

2220
test('should handle empty query parameters', () => {
2321
const loggingData = {
24-
url: 'https://monitoring.yandex-team.ru/projects/kikimr/logs?from=now-1h&to=now&query=%7B%7D',
22+
url: 'https://logging.url/projects/kikimr/logs?from=now-1h&to=now&query=%7B%7D',
2523
};
2624

2725
const result = getLogsLink({
@@ -30,7 +28,9 @@ describe('getLogsLink', () => {
3028
});
3129

3230
// Should add dbName to empty query
33-
expect(result).toContain('database+%3D+%22testdb%22');
31+
expect(result).toBe(
32+
'https://logging.url/projects/kikimr/logs?from=now-1h&to=now&query=%7Bdatabase+%3D+%22testdb%22%7D',
33+
);
3434
});
3535

3636
test('should return empty string for invalid data', () => {

src/utils/logs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ export function getLogsLink({dbName, logging}: GetLogsLinkProps): string {
2121
if (queryParam) {
2222
const decodedQuery = decodeURIComponent(queryParam);
2323

24+
// gets content between curly braces and replaces with {content, database = dbName}
2425
const updatedQuery = decodedQuery.replace(/\{([^}]*)\}/, (_match, contents) => {
2526
const trimmedContents = contents.trim();
26-
return `{${trimmedContents}${trimmedContents ? ', ' : ''}database = "${dbName}", level = "ERROR"}`;
27+
if (trimmedContents) {
28+
return `{${trimmedContents}, database = "${dbName}"}`;
29+
} else {
30+
return `{database = "${dbName}"}`;
31+
}
2732
});
2833

2934
url.searchParams.set('query', updatedQuery);

0 commit comments

Comments
 (0)