Skip to content

Commit 329a605

Browse files
committed
NETOBSERV-2485: health, improve API to customize links
1 parent 215e805 commit 329a605

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

web/src/components/health/health-helper.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ type HealthMetadata = {
4242
nodeLabels?: string[];
4343
namespaceLabels?: string[];
4444
links: { name: string; url: string }[];
45-
trafficLinkFilter?: string;
45+
trafficLink?: TrafficLink;
46+
};
47+
48+
type TrafficLink = {
49+
extraFilter: string;
50+
backAndForth: boolean;
51+
filterDestination: boolean;
4652
};
4753

4854
type ScoreDetail = {
@@ -56,6 +62,11 @@ const getHealthMetadata = (annotations: PrometheusLabels): HealthMetadata => {
5662
upperBound: '100',
5763
upperBoundF: 100,
5864
unit: '%',
65+
trafficLink: {
66+
extraFilter: '',
67+
backAndForth: true,
68+
filterDestination: false
69+
},
5970
links: []
6071
};
6172
if ('netobserv_io_network_health' in annotations) {
@@ -64,6 +75,7 @@ const getHealthMetadata = (annotations: PrometheusLabels): HealthMetadata => {
6475
// Setup defaults and derived
6576
md.unit = md.unit || defaultMetadata.unit;
6677
md.upperBound = md.upperBound || defaultMetadata.upperBound;
78+
md.trafficLink = md.trafficLink || defaultMetadata.trafficLink;
6779
md.links = md.links || defaultMetadata.links;
6880
md.thresholdF = md.threshold ? parseFloat(md.threshold) || 0 : 0;
6981
md.upperBoundF = parseFloat(md.upperBound) || defaultMetadata.upperBoundF;
@@ -246,18 +258,20 @@ export const getAlertLink = (a: AlertWithRuleName): string => {
246258
export const getTrafficLink = (kind: string, resourceName: string, a: AlertWithRuleName): string => {
247259
const filters: string[] = [];
248260
let params = '';
261+
const side = a.metadata.trafficLink?.filterDestination ? 'dst' : 'src';
262+
const bnf = a.metadata.trafficLink?.backAndForth !== false;
249263
switch (kind) {
250264
case 'Namespace':
251-
filters.push(`src_namespace="${resourceName}"`);
252-
params += '&bnf=true';
265+
filters.push(`${side}_namespace="${resourceName}"`);
266+
params += `&bnf=${bnf}`;
253267
break;
254268
case 'Node':
255-
filters.push(`src_node="${resourceName}"`);
256-
params += '&bnf=true';
269+
filters.push(`${side}_node="${resourceName}"`);
270+
params += `&bnf=${bnf}`;
257271
break;
258272
}
259-
if (a.metadata.trafficLinkFilter) {
260-
filters.push(a.metadata.trafficLinkFilter);
273+
if (a.metadata.trafficLink?.extraFilter) {
274+
filters.push(a.metadata.trafficLink.extraFilter);
261275
}
262276
return `/netflow-traffic?filters=${encodeURIComponent(filters.join(';'))}${params}`;
263277
};

0 commit comments

Comments
 (0)