Skip to content

Commit ab91d88

Browse files
authored
Merge pull request #87 from jpinsonneau/filters_case
NETOBSERV-176 regex case insensitive
2 parents b467794 + eaa9c6c commit ab91d88

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

pkg/loki/query.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ func (q *Query) processStreamSelector(key string, values []string) {
201201
regexStr.WriteByte('|')
202202
}
203203
//match the begining of string if quoted without a star
204+
//and case insensitive if no quotes
204205
if !strings.HasPrefix(value, `"`) {
205-
regexStr.WriteString(".*")
206+
regexStr.WriteString("(?i).*")
206207
} else if !strings.HasPrefix(value, `"*`) {
207208
regexStr.WriteString("^")
208209
}
@@ -259,8 +260,9 @@ func (q *Query) processLineFilters(key string, values []string) error {
259260
} else {
260261
regexStr.WriteString(`"`)
261262
// match start any if not quoted
263+
// and case insensitive
262264
if !strings.HasPrefix(value, `"`) {
263-
regexStr.WriteString(".*")
265+
regexStr.WriteString("(?i).*")
264266
}
265267
//inject value with regex
266268
regexStr.WriteString(valueReplacer.Replace(value))

pkg/server/server_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ func TestLokiFiltering(t *testing.T) {
263263
}{{
264264
inputPath: "?SrcPod=test-pod",
265265
outputQuery: []string{
266-
"?query={app=\"netobserv-flowcollector\"}|~`\"SrcPod\":\".*test-pod.*\"`",
266+
"?query={app=\"netobserv-flowcollector\"}|~`\"SrcPod\":\"(?i).*test-pod.*\"`",
267267
},
268268
}, {
269269
inputPath: "?SrcPod=test-pod&match=any",
270270
outputQuery: []string{
271-
"?query={app=\"netobserv-flowcollector\"}|~`\"SrcPod\":\".*test-pod.*\"`",
271+
"?query={app=\"netobserv-flowcollector\"}|~`\"SrcPod\":\"(?i).*test-pod.*\"`",
272272
},
273273
}, {
274274
inputPath: "?Proto=6&match=all",
@@ -283,45 +283,45 @@ func TestLokiFiltering(t *testing.T) {
283283
}, {
284284
inputPath: "?Proto=6&SrcPod=test",
285285
outputQuery: []string{
286-
"?query={app=\"netobserv-flowcollector\"}|~`\"Proto\":6`|~`\"SrcPod\":\".*test.*\"`",
287-
"?query={app=\"netobserv-flowcollector\"}|~`\"SrcPod\":\".*test.*\"`|~`\"Proto\":6`",
286+
"?query={app=\"netobserv-flowcollector\"}|~`\"Proto\":6`|~`\"SrcPod\":\"(?i).*test.*\"`",
287+
"?query={app=\"netobserv-flowcollector\"}|~`\"SrcPod\":\"(?i).*test.*\"`|~`\"Proto\":6`",
288288
},
289289
}, {
290290
inputPath: "?Proto=6&SrcPod=test&match=any",
291291
outputQuery: []string{
292-
"?query={app=\"netobserv-flowcollector\"}|~`(\"Proto\":6)|(\"SrcPod\":\".*test.*\")`",
293-
"?query={app=\"netobserv-flowcollector\"}|~`(\"SrcPod\":\".*test.*\")|(\"Proto\":6)`",
292+
"?query={app=\"netobserv-flowcollector\"}|~`(\"Proto\":6)|(\"SrcPod\":\"(?i).*test.*\")`",
293+
"?query={app=\"netobserv-flowcollector\"}|~`(\"SrcPod\":\"(?i).*test.*\")|(\"Proto\":6)`",
294294
},
295295
}, {
296296
inputPath: "?Proto=6&SrcPod=test&FlowDirection=1&match=any",
297297
outputQuery: []string{
298-
"?query={app=\"netobserv-flowcollector\",FlowDirection=\"1\"}|~`(\"Proto\":6)|(\"SrcPod\":\".*test.*\")`",
299-
"?query={app=\"netobserv-flowcollector\",FlowDirection=\"1\"}|~`(\"SrcPod\":\".*test.*\")|(\"Proto\":6)`",
298+
"?query={app=\"netobserv-flowcollector\",FlowDirection=\"1\"}|~`(\"Proto\":6)|(\"SrcPod\":\"(?i).*test.*\")`",
299+
"?query={app=\"netobserv-flowcollector\",FlowDirection=\"1\"}|~`(\"SrcPod\":\"(?i).*test.*\")|(\"Proto\":6)`",
300300
},
301301
}, {
302302
inputPath: "?SrcNamespace=test-namespace&match=all",
303303
outputQuery: []string{
304-
`?query={SrcNamespace=~".*test-namespace.*",app="netobserv-flowcollector"}`,
304+
`?query={SrcNamespace=~"(?i).*test-namespace.*",app="netobserv-flowcollector"}`,
305305
},
306306
}, {
307307
inputPath: "?SrcNamespace=test-namespace&match=any",
308308
outputQuery: []string{
309-
`?query={SrcNamespace=~".*test-namespace.*",app="netobserv-flowcollector"}`,
309+
`?query={SrcNamespace=~"(?i).*test-namespace.*",app="netobserv-flowcollector"}`,
310310
},
311311
}, {
312312
inputPath: "?SrcPort=8080&SrcAddr=10.128.0.1&SrcNamespace=default",
313313
outputQuery: []string{
314-
"?query={SrcNamespace=~\".*default.*\",app=\"netobserv-flowcollector\"}|~`\"SrcPort\":8080`|json|SrcAddr=ip(\"10.128.0.1\")",
314+
"?query={SrcNamespace=~\"(?i).*default.*\",app=\"netobserv-flowcollector\"}|~`\"SrcPort\":8080`|json|SrcAddr=ip(\"10.128.0.1\")",
315315
},
316316
}, {
317317
inputPath: "?SrcPort=8080&SrcAddr=10.128.0.1&SrcNamespace=default&match=any",
318318
outputQuery: []string{
319-
"?query={app=\"netobserv-flowcollector\"}|json|SrcNamespace=~\".*default.*\"+or+SrcAddr=ip(\"10.128.0.1\")+or+SrcPort=8080",
319+
"?query={app=\"netobserv-flowcollector\"}|json|SrcNamespace=~\"(?i).*default.*\"+or+SrcAddr=ip(\"10.128.0.1\")+or+SrcPort=8080",
320320
},
321321
}, {
322322
inputPath: "?SrcPort=8080&SrcAddr=10.128.0.1&SrcNamespace=default&match=any&FlowDirection=0",
323323
outputQuery: []string{
324-
"?query={app=\"netobserv-flowcollector\",FlowDirection=\"0\"}|json|SrcNamespace=~\".*default.*\"+or+SrcAddr=ip(\"10.128.0.1\")+or+SrcPort=8080",
324+
"?query={app=\"netobserv-flowcollector\",FlowDirection=\"0\"}|json|SrcNamespace=~\"(?i).*default.*\"+or+SrcAddr=ip(\"10.128.0.1\")+or+SrcPort=8080",
325325
},
326326
}, {
327327
inputPath: "?startTime=1640991600&match=all",

web/locales/en/plugin__network-observability-plugin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"Containing any alphanumeric, hyphen, underscrore or dot character": "Containing any alphanumeric, hyphen, underscrore or dot character",
2828
"Partial text like cluster, cluster-image, image-registry": "Partial text like cluster, cluster-image, image-registry",
2929
"Exact match using quotes like \"cluster-image-registry\"": "Exact match using quotes like \"cluster-image-registry\"",
30+
"Case sensitive match using quotes like \"Deployment\"": "Case sensitive match using quotes like \"Deployment\"",
3031
"Starting text like cluster, \"cluster-*\"": "Starting text like cluster, \"cluster-*\"",
3132
"Ending text like \"*-registry\"": "Ending text like \"*-registry\"",
3233
"Pattern like \"cluster-*-registry\", \"c*-*-r*y\", -i*e-": "Pattern like \"cluster-*-registry\", \"c*-*-r*y\", -i*e-",

web/src/components/filters-toolbar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ export const FiltersToolbar: React.FC<FiltersToolbarProps> = ({
357357
- ${t('Containing any alphanumeric, hyphen, underscrore or dot character')}
358358
- ${t('Partial text like cluster, cluster-image, image-registry')}
359359
- ${t('Exact match using quotes like "cluster-image-registry"')}
360+
- ${t('Case sensitive match using quotes like "Deployment"')}
360361
- ${t('Starting text like cluster, "cluster-*"')}
361362
- ${t('Ending text like "*-registry"')}
362363
- ${t('Pattern like "cluster-*-registry", "c*-*-r*y", -i*e-')}`;

0 commit comments

Comments
 (0)