From 294d527a0e33f4f0189f69fb8ebd3ffa72d03e8b Mon Sep 17 00:00:00 2001 From: nityanandagohain Date: Tue, 26 Jul 2022 14:45:20 +0530 Subject: [PATCH] parser updated to support more than one contains --- pkg/query-service/app/logs/parser.go | 2 +- pkg/query-service/app/logs/parser_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/query-service/app/logs/parser.go b/pkg/query-service/app/logs/parser.go index fb819337ce..ec1fb773d4 100644 --- a/pkg/query-service/app/logs/parser.go +++ b/pkg/query-service/app/logs/parser.go @@ -31,7 +31,7 @@ const ( IDEND = "idEnd" ) -var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?)?(([\w.-]+ (in|nin) \([\S ]+\))|([\w.]+ (gt|lt|gte|lte) (')?[\S]+(')?)|([\w.]+ (contains|ncontains)) (')?[\S ]+(')?)`) +var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?)?(([\w.-]+ (in|nin) \([\S ]+\))|([\w.]+ (gt|lt|gte|lte) (')?[\S]+(')?)|([\w.]+ (contains|ncontains)) (')?[^']+(')?)`) var operatorRegex, _ = regexp.Compile(`(?i)(?: )(in|nin|gt|lt|gte|lte|contains|ncontains)(?: )`) func ParseLogFilterParams(r *http.Request) (*model.LogsFilterParams, error) { diff --git a/pkg/query-service/app/logs/parser_test.go b/pkg/query-service/app/logs/parser_test.go index 84984acb3b..517247122e 100644 --- a/pkg/query-service/app/logs/parser_test.go +++ b/pkg/query-service/app/logs/parser_test.go @@ -32,6 +32,11 @@ var correctQueriesTest = []struct { `resource contains 'Hello, "World"'`, []string{`resource ILIKE '%Hello, "World"%' `}, }, + { + `more than one continas`, + `resource contains 'Hello, "World"' and myresource contains 'abcd'`, + []string{`resource ILIKE '%Hello, "World"%' `, `AND myresource ILIKE '%abcd%' `}, + }, { `filters with lt,gt,lte,gte operators`, `id lt 100 and id gt 50 and code lte 500 and code gte 400`,