Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"history": "^4.10.1",
"hotkeys-js": "^3.13.9",
"lodash": "^4.17.21",
"lz-string": "^1.5.0",
"monaco-editor": "^0.52.2",
"numeral": "^2.0.6",
"path-to-regexp": "^3.3.0",
Expand Down
16 changes: 16 additions & 0 deletions src/utils/__test__/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ describe('getLogsLink', () => {
);
});

test('should generate monitoring URL when monium_cluster is present', () => {
const loggingData = {
url: 'https://logging.url/projects/some_project/logs',
monium_cluster: 'ydb-ru-prestable',
};

const result = getLogsLink({
logging: JSON.stringify(loggingData),
dbName: 'testdb',
});

expect(result).toBe(
'https://logging.url/projects/kikimr/logs?query=%7Bproject+%3D+%22kikimr%22%2C+service+%3D+%22ydb%22%2C+cluster+%3D+%22ydb-ru-prestable%22%2C+database+%3D+%22testdb%22%7D&from=now-1d&to=now&columns=level%2Ctime%2Cmessage%2Chost&groupByField=level&chartType=line&linesMode=single',
);
});

test('should return empty string for invalid data', () => {
expect(
getLogsLink({
Expand Down
44 changes: 43 additions & 1 deletion src/utils/logs.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,60 @@
const DEFAULT_PROJECT = 'kikimr';
const DEFAULT_SERVICE = 'ydb';
const DEFAULT_TIME_RANGE = {
from: 'now-1d',
to: 'now',
};
const DEFAULT_COLUMNS = 'level,time,message,host';
const DEFAULT_GROUP_BY = 'level';
const DEFAULT_CHART_TYPE = 'line';
const DEFAULT_LINES_MODE = 'single';

interface GetLogsLinkProps {
dbName: string;
logging: string;
}

export type GetLogsLink = (props: GetLogsLinkProps) => string;

interface ParsedLogging {
url: string;
monium_cluster?: string;
}

function getBaseUrl(urlString: string): string {
const url = new URL(urlString);
return `${url.protocol}//${url.hostname}`;
}

export function getLogsLink({dbName, logging}: GetLogsLinkProps): string {
try {
const data = JSON.parse(logging);
const data = JSON.parse(logging) as ParsedLogging;

if (typeof data === 'object' && 'url' in data) {
const logUrl = data.url;
if (!logUrl) {
return '';
}

if (data.monium_cluster) {
const baseUrl = getBaseUrl(logUrl);
const url = new URL(`${baseUrl}/projects/${DEFAULT_PROJECT}/logs`);

const query = `{project = "${DEFAULT_PROJECT}", service = "${DEFAULT_SERVICE}", cluster = "${data.monium_cluster}", database = "${dbName}"}`;

url.searchParams.set('query', query);
url.searchParams.set('from', DEFAULT_TIME_RANGE.from);
url.searchParams.set('to', DEFAULT_TIME_RANGE.to);
url.searchParams.set('columns', DEFAULT_COLUMNS);
url.searchParams.set('groupByField', DEFAULT_GROUP_BY);
url.searchParams.set('chartType', DEFAULT_CHART_TYPE);
url.searchParams.set('linesMode', DEFAULT_LINES_MODE);

// debug-only
console.log('Monium_cluster branch');
return url.toString();
}

const url = new URL(logUrl);

const queryParam = url.searchParams.get('query');
Expand All @@ -28,6 +68,8 @@ export function getLogsLink({dbName, logging}: GetLogsLinkProps): string {
url.searchParams.set('query', updatedQuery);
}

// debug-only
console.log('Url parsing branch');
return url.toString();
}
} catch {}
Expand Down
Loading