Skip to content

Commit 3c49e87

Browse files
Merge pull request #192 from shwetaap/COO1315
COO-1315: Update Query string when multiple namespaces are selected in Network Traffic
2 parents 0577883 + 782c3da commit 3c49e87

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

web/src/__tests__/netflow.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ describe('NetflowNode.fromQuery', () => {
4343
end: '2025-03-25T22:00:00.000Z',
4444
},
4545
},
46+
{
47+
url: `netflow-traffic?tenant=network&filters=${encodeURIComponent(
48+
'dst_kind=Pod;src_namespace="openshift-oauth-apiserver","tracing-app-k6"',
49+
)}&startTime=1742896800&endTime=1742940000`,
50+
query: 'netflow:network:{DstK8S_Type="Pod",SrcK8S_Namespace=~"openshift-oauth-apiserver|tracing-app-k6"}',
51+
constraint: {
52+
start: '2025-03-25T10:00:00.000Z',
53+
end: '2025-03-25T22:00:00.000Z',
54+
},
55+
},
4656
])(`from $query`, ({ query, url, constraint }) =>
4757
expect(
4858
new NetflowDomain().queryToLink(Query.parse(query), Constraint.fromAPI(constraint)),
@@ -63,6 +73,12 @@ describe('NetflowNode.fromURL', () => {
6373
url: 'netflow-traffic?timeRange=300&limit=5&match=all&packetLoss=all&recordType=flowLog&filters=flow_layer%3Dapp%3Bdst_kind%3DPod%3Bsrc_kind%3DPod&bnf=false',
6474
query: 'netflow:network:{DstK8S_Type="Pod",SrcK8S_Type="Pod"}',
6575
},
76+
{
77+
url: `netflow-traffic?tenant=network&filters=${encodeURIComponent(
78+
'dst_kind=Pod;dst_namespace=hostpath-provisioner;src_namespace="openshift-oauth-apiserver","tracing-app-k6"',
79+
)}`,
80+
query: 'netflow:network:{DstK8S_Type="Pod",DstK8S_Namespace="hostpath-provisioner",SrcK8S_Namespace=~"openshift-oauth-apiserver|tracing-app-k6"}',
81+
},
6682
])(`from $url`, ({ query, url }) =>
6783
expect(new NetflowDomain().linkToQuery(new URIRef(url))).toEqual(Query.parse(query)),
6884
);

web/src/korrel8r/netflow.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,21 @@ export class NetflowDomain extends Domain {
4040
?.split(';')
4141
.map((filter) => {
4242
const [, key, operator, value] = filter.match(/^\s*([^!=\s]+)\s*(!?=~?)\s*(.+)\s*$/) || [];
43-
// Removes surrounding quotes
43+
44+
if (!key || !linkToQueryName[key]) return '';
45+
46+
// Check if value contains multiple comma-separated quoted strings like "val1","val2"
47+
const quotedValues = value?.match(/"([^"]+)"/g);
48+
if (quotedValues && quotedValues.length > 1) {
49+
// Extract the actual values (remove quotes)
50+
const values = quotedValues.map(v => v.slice(1, -1));
51+
// Convert to LogQL regex syntax with OR operator
52+
return `${linkToQueryName[key]}=~"${values.join('|')}"`;
53+
}
54+
55+
// Single value - removes surrounding quotes
4456
const trimmedValue = value?.replace(/^"(.*)"$/, '$1');
45-
return linkToQueryName[key] ? `${linkToQueryName[key]}${operator}"${trimmedValue}"` : '';
57+
return `${linkToQueryName[key]}${operator}"${trimmedValue}"`;
4658
})
4759
.filter((s) => s)
4860
.join(',');
@@ -61,7 +73,17 @@ export class NetflowDomain extends Domain {
6173
const [, key, operator, value] =
6274
filter.match(/^\s*([^!=\s]+)\s*(!?=~?)\s*"(.+)"\s*$/) || [];
6375
if (!key) throw this.badQuery(query, 'bad selector format');
64-
return queryToURLName[key] ? `${queryToURLName[key]}${operator}${value}` : '';
76+
77+
// Convert LogQL regex pattern to URL format for netflow
78+
if (queryToURLName[key]) {
79+
// If operator is =~ and value contains |, convert to comma-separated quoted format
80+
if (operator === '=~' && value.includes('|')) {
81+
const values = value.split('|').map(v => `"${v}"`).join(',');
82+
return `${queryToURLName[key]}=${values}`;
83+
}
84+
return `${queryToURLName[key]}${operator}${value}`;
85+
}
86+
return '';
6587
})
6688
.filter((s) => s)
6789
.join(';');

0 commit comments

Comments
 (0)