Skip to content

Commit c673abc

Browse files
feat(ClusterInfo): add slo logs link
1 parent 5c722dd commit c673abc

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

src/containers/Cluster/ClusterInfo/utils.tsx

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ export const getInfo = (cluster: TClusterInfo, additionalInfo: InfoItem[]) => {
7878
/**
7979
* parses stringified json in format {url: "href"}
8080
*/
81-
function prepareClusterLink(rawLink?: string) {
81+
function prepareClusterCoresLink(rawCoresString?: string) {
8282
try {
83-
const linkObject = parseJson(rawLink) as unknown;
83+
const linkObject = parseJson(rawCoresString) as unknown;
8484

8585
if (
8686
linkObject &&
@@ -95,26 +95,56 @@ function prepareClusterLink(rawLink?: string) {
9595
return undefined;
9696
}
9797

98+
/**
99+
* parses stringified json in format {url: "href", slo_logs_url: "href"}
100+
*/
101+
function prepareClusterLoggingLinks(rawLoggingString?: string) {
102+
try {
103+
const linkObject = parseJson(rawLoggingString) as unknown;
104+
105+
if (linkObject && typeof linkObject === 'object') {
106+
const logsUrl =
107+
'url' in linkObject && typeof linkObject.url === 'string'
108+
? linkObject.url
109+
: undefined;
110+
const sloLogsUrl =
111+
'slo_logs_url' in linkObject && typeof linkObject.slo_logs_url === 'string'
112+
? linkObject.slo_logs_url
113+
: undefined;
114+
return {logsUrl, sloLogsUrl};
115+
}
116+
} catch {}
117+
118+
return {};
119+
}
120+
98121
export function useClusterLinks() {
99122
const {cores, logging} = useClusterBaseInfo();
100123

101124
return React.useMemo(() => {
102125
const result: ClusterLink[] = [];
103126

104-
const coresLink = prepareClusterLink(cores);
105-
const loggingLink = prepareClusterLink(logging);
127+
const coresUrl = prepareClusterCoresLink(cores);
128+
const {logsUrl, sloLogsUrl} = prepareClusterLoggingLinks(logging);
106129

107-
if (coresLink) {
130+
if (coresUrl) {
108131
result.push({
109132
title: i18n('link_cores'),
110-
url: coresLink,
133+
url: coresUrl,
111134
});
112135
}
113136

114-
if (loggingLink) {
137+
if (logsUrl) {
115138
result.push({
116139
title: i18n('link_logging'),
117-
url: loggingLink,
140+
url: logsUrl,
141+
});
142+
}
143+
144+
if (sloLogsUrl) {
145+
result.push({
146+
title: i18n('link_slo-logs'),
147+
url: sloLogsUrl,
118148
});
119149
}
120150

src/containers/Cluster/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"links": "Links",
1212
"link_cores": "Coredumps",
1313
"link_logging": "Logging",
14+
"link_slo-logs": "Slo Logs",
1415
"context_cores": "cores",
1516
"title_cpu": "CPU",
1617
"title_storage": "Storage",

0 commit comments

Comments
 (0)