Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

parsing logic and test updated

nityanandagohain8e4fbbe77004
diff --git a/pkg/query-service/app/logs/parser.go b/pkg/query-service/app/logs/parser.go
index 1bbab36466..4c8649b5fd 100644
--- a/pkg/query-service/app/logs/parser.go
+++ b/pkg/query-service/app/logs/parser.go
@@ -21,7 +21,7 @@ var operatorMapping = map[string]string{
"ncontains": "NOT ILIKE",
}
-var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?)?(([\w.-]+ (in|nin) \(["\w.,' \-><]+\))|([\w.-]+ (gt|lt|gte|lte|contains|ncontains) ("|')?\S+("|')?))`)
+var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?)?(([\w.-]+ (in|nin) \([\S ]+\))|([\w.]+ (gt|lt|gte|lte) (')?[\S]+(')?)|([\w.]+ (contains|ncontains)) (')?[\S ]+(')?)`)
var operatorRegex, _ = regexp.Compile(`(?i)(?: )(in|nin|gt|lt|gte|lte|contains|ncontains)(?: )`)
func ParseLogFilterParams(r *http.Request) (*model.LogsFilterParams, error) {
@@ -108,13 +108,15 @@ func parseLogQuery(query string) ([]string, error) {
for _, v := range filterTokens {
op := strings.TrimSpace(operatorRegex.FindString(v))
+ opLower := strings.ToLower(op)
- if strings.ToLower(op) == "contains" {
+ if opLower == "contains" || opLower == "ncontains" {
searchString := strings.TrimSpace(strings.Split(v, op)[1])
- sqlQueryTokens = append(sqlQueryTokens, fmt.Sprintf(`AND body ILIKE '%%%s%%' `, searchString[1:len(searchString)-1]))
- } else if strings.ToLower(op) == "ncontains" {
- searchString := strings.TrimSpace(strings.Split(v, op)[1])
- sqlQueryTokens = append(sqlQueryTokens, fmt.Sprintf(`AND body NOT ILIKE '%%%s%%' `, searchString[1:len(searchString)-1]))
+ f := fmt.Sprintf(`body %s '%%%s%%' `, operatorMapping[opLower], searchString[1:len(searchString)-1])
+ if strings.HasPrefix(strings.ToLower(v), "and") {
+ f = "AND " + f
+ }
+ sqlQueryTokens = append(sqlQueryTokens, f)
} else {
symbol := operatorMapping[strings.ToLower(op)]
sqlQueryTokens = append(sqlQueryTokens, strings.Replace(v, " "+op+" ", " "+symbol+" ", 1)+" ")
diff --git a/pkg/query-service/app/logs/parser_test.go b/pkg/query-service/app/logs/parser_test.go
index d1467b4ee3..b06b2ccec5 100644
--- a/pkg/query-service/app/logs/parser_test.go
+++ b/pkg/query-service/app/logs/parser_test.go
@@ -22,6 +22,11 @@ var correctQueriesTest = []struct {
`searchstring`,
[]string{`body ILIKE '%searchstring%' `},
},
+ {
+ `fulltext with quotes and space`,
+ `FULLTEXT contains 'Hello, "World"'`,
+ []string{`body ILIKE '%Hello, "World"%' `},
+ },
{
`filters with lt,gt,lte,gte operators`,
`id lt 100 and id gt 50 and code lte 500 and code gte 400`,
@@ -197,8 +202,8 @@ func TestGenerateSQLQuery(t *testing.T) {
}
query := "id lt 100 and id gt 50 and code lte 500 and code gte 400"
- tsStart := int64(1657689292000)
- tsEnd := int64(1657689294000)
+ tsStart := uint64(1657689292000)
+ tsEnd := uint64(1657689294000)
idStart := "2BsKLKv8cZrLCn6rkOcRGkdjBdM"
idEnd := "2BsKG6tRpFWjYMcWsAGKfSxoQdU"
sqlWhere := "id < 100 and id > 50 and attributes_int64_value[indexOf(attributes_int64_key, 'code')] <= 500 and attributes_int64_value[indexOf(attributes_int64_key, 'code')] >= 400 and timestamp >= '1657689292000' and timestamp <= '1657689294000' and id > '2BsKLKv8cZrLCn6rkOcRGkdjBdM' and id < '2BsKG6tRpFWjYMcWsAGKfSxoQdU' "