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.

fix: use lower and convert re2 to string in fulltext (#8887)

Nityananda Gohain4878f725eae8
diff --git a/pkg/querybuilder/fallback_expr.go b/pkg/querybuilder/fallback_expr.go
index b940b9c0e9..852d47481f 100644
--- a/pkg/querybuilder/fallback_expr.go
+++ b/pkg/querybuilder/fallback_expr.go
@@ -6,6 +6,7 @@ import (
"fmt"
"math"
"reflect"
+ "regexp"
"strconv"
"strings"
@@ -185,3 +186,11 @@ func FormatValueForContains(value any) string {
}
}
}
+
+func FormatFullTextSearch(input string) string {
+ if _, err := regexp.Compile(input); err != nil {
+ // Not a valid regex -> treat as literal substring
+ return regexp.QuoteMeta(input)
+ }
+ return input
+}
diff --git a/pkg/querybuilder/format_test.go b/pkg/querybuilder/format_test.go
index f74adadbd1..b914a7ba6b 100644
--- a/pkg/querybuilder/format_test.go
+++ b/pkg/querybuilder/format_test.go
@@ -273,3 +273,30 @@ func TestFormatValueForContains_LargeNumberScientificNotation(t *testing.T) {
assert.Equal(t, "521509198310", result)
assert.NotEqual(t, "5.2150919831e+11", result)
}
+
+func TestFormatFullTextSearch(t *testing.T) {
+ tests := []struct {
+ input string
+ expected string
+ }{
+ // valid regex, unchanged
+ {"foo.*bar", "foo.*bar"},
+ // invalid regex, escaped
+ {"[ERROR-1234]", `\[ERROR-1234\]`},
+ // literal with +
+ {"C++ Error", `C\+\+ Error`},
+ // IP address, valid regex but unsafe chars
+ {"10.0.0.1", "10.0.0.1"},
+ // java class, '.' will still be regex wildcard
+ {"java.lang.NullPointerException", "java.lang.NullPointerException"},
+ // a-o invalid character class range
+ {"[LocalLog partition=__cluster_metadata-0,", "\\[LocalLog partition=__cluster_metadata-0,"},
+ {"[abcd]", "[abcd]"},
+ }
+ for _, tt := range tests {
+ got := FormatFullTextSearch(tt.input)
+ if got != tt.expected {
+ t.Errorf("FormatFullTextSearch(%q) = %q, want %q", tt.input, got, tt.expected)
+ }
+ }
+}
diff --git a/pkg/querybuilder/where_clause_visitor.go b/pkg/querybuilder/where_clause_visitor.go
index a14f4996bd..e87ddbad46 100644
--- a/pkg/querybuilder/where_clause_visitor.go
+++ b/pkg/querybuilder/where_clause_visitor.go
@@ -298,8 +298,9 @@ func (v *filterExpressionVisitor) VisitPrimary(ctx *grammar.PrimaryContext) any
child := ctx.GetChild(0)
if keyCtx, ok := child.(*grammar.KeyContext); ok {
// create a full text search condition on the body field
+
keyText := keyCtx.GetText()
- cond, err := v.conditionBuilder.ConditionFor(context.Background(), v.fullTextColumn, qbtypes.FilterOperatorRegexp, keyText, v.builder)
+ cond, err := v.conditionBuilder.ConditionFor(context.Background(), v.fullTextColumn, qbtypes.FilterOperatorRegexp, FormatFullTextSearch(keyText), v.builder)
if err != nil {
v.errors = append(v.errors, fmt.Sprintf("failed to build full text search condition: %s", err.Error()))
return ""
@@ -319,7 +320,7 @@ func (v *filterExpressionVisitor) VisitPrimary(ctx *grammar.PrimaryContext) any
v.errors = append(v.errors, fmt.Sprintf("unsupported value type: %s", valCtx.GetText()))
return ""
}
- cond, err := v.conditionBuilder.ConditionFor(context.Background(), v.fullTextColumn, qbtypes.FilterOperatorRegexp, text, v.builder)
+ cond, err := v.conditionBuilder.ConditionFor(context.Background(), v.fullTextColumn, qbtypes.FilterOperatorRegexp, FormatFullTextSearch(text), v.builder)
if err != nil {
v.errors = append(v.errors, fmt.Sprintf("failed to build full text search condition: %s", err.Error()))
return ""
@@ -594,7 +595,7 @@ func (v *filterExpressionVisitor) VisitFullText(ctx *grammar.FullTextContext) an
v.errors = append(v.errors, "full text search is not supported")
return ""
}
- cond, err := v.conditionBuilder.ConditionFor(context.Background(), v.fullTextColumn, qbtypes.FilterOperatorRegexp, text, v.builder)
+ cond, err := v.conditionBuilder.ConditionFor(context.Background(), v.fullTextColumn, qbtypes.FilterOperatorRegexp, FormatFullTextSearch(text), v.builder)
if err != nil {
v.errors = append(v.errors, fmt.Sprintf("failed to build full text search condition: %s", err.Error()))
return ""
diff --git a/pkg/telemetrylogs/condition_builder.go b/pkg/telemetrylogs/condition_builder.go
index 8822f28d6c..5c41938d56 100644
--- a/pkg/telemetrylogs/condition_builder.go
+++ b/pkg/telemetrylogs/condition_builder.go
@@ -64,6 +64,10 @@ func (c *conditionBuilder) conditionFor(
return sb.ILike(tblFieldName, value), nil
case qbtypes.FilterOperatorNotLike:
return sb.NotILike(tblFieldName, value), nil
+ case qbtypes.FilterOperatorRegexp:
+ return fmt.Sprintf(`match(LOWER(%s), LOWER(%s))`, tblFieldName, sb.Var(value)), nil
+ case qbtypes.FilterOperatorNotRegexp:
+ return fmt.Sprintf(`NOT match(LOWER(%s), LOWER(%s))`, tblFieldName, sb.Var(value)), nil
}
}
diff --git a/pkg/telemetrylogs/field_mapper.go b/pkg/telemetrylogs/field_mapper.go
index db76ecf437..46a5a16881 100644
--- a/pkg/telemetrylogs/field_mapper.go
+++ b/pkg/telemetrylogs/field_mapper.go
@@ -60,7 +60,6 @@ func NewFieldMapper() qbtypes.FieldMapper {
}
func (m *fieldMapper) getColumn(_ context.Context, key *telemetrytypes.TelemetryFieldKey) (*schema.Column, error) {
-
switch key.FieldContext {
case telemetrytypes.FieldContextResource:
return logsV2Columns["resources_string"], nil
diff --git a/pkg/telemetrylogs/filter_expr_logs_test.go b/pkg/telemetrylogs/filter_expr_logs_test.go
index 82886bcc40..6d6ecb1f0f 100644
--- a/pkg/telemetrylogs/filter_expr_logs_test.go
+++ b/pkg/telemetrylogs/filter_expr_logs_test.go
@@ -41,17 +41,25 @@ func TestFilterExprLogs(t *testing.T) {
// Single word searches
{
category: "Single word",
- query: "download",
+ query: "Download",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
- expectedArgs: []any{"download"},
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
+ expectedArgs: []any{"Download"},
+ expectedErrorContains: "",
+ },
+ {
+ category: "Single word invalid regex",
+ query: "'[LocalLog partition=__cluster_metadata-0,'",
+ shouldPass: true,
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
+ expectedArgs: []any{"\\[LocalLog partition=__cluster_metadata-0,"},
expectedErrorContains: "",
},
{
category: "Single word",
query: "LAMBDA",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"LAMBDA"},
expectedErrorContains: "",
},
@@ -59,7 +67,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Single word",
query: "AccessDenied",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"AccessDenied"},
expectedErrorContains: "",
},
@@ -67,7 +75,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Single word",
query: "42069",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"42069"},
expectedErrorContains: "",
},
@@ -75,7 +83,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Single word",
query: "pulljob",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"pulljob"},
expectedErrorContains: "",
},
@@ -91,7 +99,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Single word with spaces",
query: `" 504 "`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{" 504 "},
expectedErrorContains: "",
},
@@ -99,7 +107,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Single word with spaces",
query: `"Importing "`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"Importing "},
expectedErrorContains: "",
},
@@ -107,7 +115,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Single word with spaces",
query: `"Job ID"`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"Job ID"},
expectedErrorContains: "",
},
@@ -123,7 +131,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"[email protected]"},
expectedErrorContains: "",
},
@@ -131,7 +139,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "cancel_membership",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"cancel_membership"},
expectedErrorContains: "",
},
@@ -139,7 +147,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: `"ERROR: cannot execute update() in a read-only context"`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"ERROR: cannot execute update() in a read-only context"},
expectedErrorContains: "",
},
@@ -153,7 +161,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "https://example.com/user/default/0196877a-f01f-785e-a937-5da0a3efbb75",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"https://example.com/user/default/0196877a-f01f-785e-a937-5da0a3efbb75"},
expectedErrorContains: "",
},
@@ -161,7 +169,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "\"STEPS_PER_DAY\"",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"STEPS_PER_DAY"},
expectedErrorContains: "",
},
@@ -169,7 +177,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "#bvn",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"#bvn"},
expectedErrorContains: "",
},
@@ -177,7 +185,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "question?mark",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"question?mark"},
expectedErrorContains: "",
},
@@ -185,7 +193,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "backslash\\\\escape",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"backslash\\\\escape"},
expectedErrorContains: "",
},
@@ -193,7 +201,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "underscore_separator",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"underscore_separator"},
expectedErrorContains: "",
},
@@ -201,7 +209,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Special characters",
query: "\"Text with [brackets]\"",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"Text with [brackets]"},
expectedErrorContains: "",
},
@@ -211,7 +219,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Multi word",
query: "Fail to parse",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?) AND match(body, ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{"Fail", "to", "parse"},
expectedErrorContains: "",
},
@@ -219,7 +227,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Multi word",
query: "Importing file",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{"Importing", "file"},
expectedErrorContains: "",
},
@@ -227,7 +235,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Multi word",
query: "sync account status",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?) AND match(body, ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{"sync", "account", "status"},
expectedErrorContains: "",
},
@@ -235,7 +243,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Multi word",
query: "Download CSV Reports",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?) AND match(body, ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{"Download", "CSV", "Reports"},
expectedErrorContains: "",
},
@@ -243,7 +251,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Multi word",
query: "Emitted event to the Kafka topic",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?) AND match(body, ?) AND match(body, ?) AND match(body, ?) AND match(body, ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{"Emitted", "event", "to", "the", "Kafka", "topic"},
expectedErrorContains: "",
},
@@ -251,7 +259,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Multi word",
query: "\"user authentication\" failed",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{"user authentication", "failed"},
expectedErrorContains: "",
},
@@ -261,7 +269,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "ID search",
query: "250430165501118HIgesxlEb9",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"250430165501118HIgesxlEb9"},
expectedErrorContains: "",
},
@@ -269,7 +277,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "ID search",
query: "d7b9d77aefa95aef19719775c10fda60c28342f23657d1e27304d6c59a3c3004",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"d7b9d77aefa95aef19719775c10fda60c28342f23657d1e27304d6c59a3c3004"},
expectedErrorContains: "",
},
@@ -277,7 +285,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "ID search",
query: "51183870",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"51183870"},
expectedErrorContains: "",
},
@@ -285,7 +293,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "ID search",
query: "79f82635-d014-4f99-adf5-41d31d291ae3",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"79f82635-d014-4f99-adf5-41d31d291ae3"},
expectedErrorContains: "",
},
@@ -295,7 +303,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Unicode",
query: "café",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"café"},
expectedErrorContains: "",
},
@@ -303,7 +311,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Unicode",
query: "résumé",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"résumé"},
expectedErrorContains: "",
},
@@ -311,7 +319,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Unicode",
query: "Россия",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"Россия"},
expectedErrorContains: "",
},
@@ -319,7 +327,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Unicode",
query: "\"I do not like emojis ❤️\"",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"I do not like emojis ❤️"},
expectedErrorContains: "",
},
@@ -329,7 +337,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Number format",
query: "123",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"123"},
expectedErrorContains: "",
},
@@ -337,7 +345,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Number format",
query: "3.14159",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"3.14159"},
expectedErrorContains: "",
},
@@ -345,7 +353,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Number format",
query: "-42",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"-42"},
expectedErrorContains: "",
},
@@ -353,7 +361,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Number format",
query: "1e6",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"1e6"},
expectedErrorContains: "",
},
@@ -361,15 +369,15 @@ func TestFilterExprLogs(t *testing.T) {
category: "Number format",
query: "+100",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
- expectedArgs: []any{"+100"},
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
+ expectedArgs: []any{"\\+100"},
expectedErrorContains: "",
},
{
category: "Number format",
query: "0xFF",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"0xFF"},
expectedErrorContains: "",
},
@@ -379,7 +387,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "FREETEXT with conditions",
query: "critical NOT resolved status=open",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND NOT (match(body, ?)) AND (toString(attributes_number['status']) = ? AND mapContains(attributes_number, 'status') = ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND NOT (match(LOWER(body), LOWER(?))) AND (toString(attributes_number['status']) = ? AND mapContains(attributes_number, 'status') = ?))",
expectedArgs: []any{"critical", "resolved", "open", true},
expectedErrorContains: "",
},
@@ -387,7 +395,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "FREETEXT with conditions",
query: "database error type=mysql",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?) AND (attributes_string['type'] = ? AND mapContains(attributes_string, 'type') = ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)) AND (attributes_string['type'] = ? AND mapContains(attributes_string, 'type') = ?))",
expectedArgs: []any{"database", "error", "mysql", true},
expectedErrorContains: "",
},
@@ -395,7 +403,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "FREETEXT with conditions",
query: "\"connection timeout\" duration>30",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND (toFloat64(attributes_number['duration']) > ? AND mapContains(attributes_number, 'duration') = ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND (toFloat64(attributes_number['duration']) > ? AND mapContains(attributes_number, 'duration') = ?))",
expectedArgs: []any{"connection timeout", float64(30), true},
expectedErrorContains: "",
},
@@ -403,7 +411,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "FREETEXT with conditions",
query: "warning level=critical",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND (attributes_string['level'] = ? AND mapContains(attributes_string, 'level') = ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND (attributes_string['level'] = ? AND mapContains(attributes_string, 'level') = ?))",
expectedArgs: []any{"warning", "critical", true},
expectedErrorContains: "",
},
@@ -411,7 +419,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "FREETEXT with conditions",
query: "error service.name=authentication",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND (resources_string['service.name'] = ? AND mapContains(resources_string, 'service.name') = ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND (resources_string['service.name'] = ? AND mapContains(resources_string, 'service.name') = ?))",
expectedArgs: []any{"error", "authentication", true},
expectedErrorContains: "",
},
@@ -421,7 +429,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "FREETEXT with parentheses",
query: "error (status.code=500 OR status.code=503)",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND (((toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?) OR (toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?))))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND (((toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?) OR (toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?))))",
expectedArgs: []any{"error", float64(500), true, float64(503), true},
expectedErrorContains: "",
},
@@ -429,7 +437,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "FREETEXT with parentheses",
query: "(status.code=500 OR status.code=503) error",
shouldPass: true,
- expectedQuery: "WHERE ((((toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?) OR (toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?))) AND match(body, ?))",
+ expectedQuery: "WHERE ((((toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?) OR (toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?))) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{float64(500), true, float64(503), true, "error"},
expectedErrorContains: "",
},
@@ -437,7 +445,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "FREETEXT with parentheses",
query: "error AND (status.code=500 OR status.code=503)",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND (((toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?) OR (toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?))))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND (((toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?) OR (toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?))))",
expectedArgs: []any{"error", float64(500), true, float64(503), true},
expectedErrorContains: "",
},
@@ -445,7 +453,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "FREETEXT with parentheses",
query: "(status.code=500 OR status.code=503) AND error",
shouldPass: true,
- expectedQuery: "WHERE ((((toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?) OR (toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?))) AND match(body, ?))",
+ expectedQuery: "WHERE ((((toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?) OR (toFloat64(attributes_number['status.code']) = ? AND mapContains(attributes_number, 'status.code') = ?))) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{float64(500), true, float64(503), true, "error"},
expectedErrorContains: "",
},
@@ -455,7 +463,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Whitespace with FREETEXT",
query: "term1 term2",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{"term1", "term2"},
expectedErrorContains: "",
},
@@ -465,7 +473,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key token conflict",
query: "status.code",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"status.code"},
expectedErrorContains: "",
},
@@ -473,7 +481,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key token conflict",
query: "array_field",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"array_field"},
expectedErrorContains: "",
},
@@ -481,7 +489,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key token conflict",
query: "user_id.value",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"user_id.value"},
expectedErrorContains: "",
}, // Could be a key with dot notation or FREETEXT
@@ -491,7 +499,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Random cases",
query: "true",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"true"},
expectedErrorContains: "",
}, // Could be interpreted as boolean or FREETEXT
@@ -499,7 +507,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Random cases",
query: "false",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"false"},
expectedErrorContains: "",
}, // Could be interpreted as boolean or FREETEXT
@@ -507,7 +515,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Random cases",
query: "null",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"null"},
expectedErrorContains: "",
}, // Special value or FREETEXT
@@ -515,7 +523,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Random cases",
query: "123abc",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"123abc"},
expectedErrorContains: "",
}, // Starts with number but contains letters
@@ -523,7 +531,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Random cases",
query: "0x123F",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"0x123F"},
expectedErrorContains: "",
}, // Hex number format
@@ -531,7 +539,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Random cases",
query: "1.2.3",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"1.2.3"},
expectedErrorContains: "",
}, // Version number format
@@ -539,7 +547,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Random cases",
query: "a+b-c*d/e",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"a+b-c*d/e"},
expectedErrorContains: "",
}, // Mathematical expression as FREETEXT
@@ -547,7 +555,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Random cases",
query: "http://example.com/path",
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"http://example.com/path"},
expectedErrorContains: "",
}, // URL as FREETEXT
@@ -655,7 +663,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key-operator-value boundary",
query: `"not!equal"`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"not!equal"},
expectedErrorContains: "",
},
@@ -671,7 +679,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key-operator-value boundary",
query: `"greater>than"`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"greater>than"},
expectedErrorContains: "",
},
@@ -687,7 +695,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key-operator-value boundary",
query: `"less<than"`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"less<than"},
expectedErrorContains: "",
},
@@ -695,7 +703,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key-operator-value boundary",
query: "single'quote'",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{"single", "quote"},
expectedErrorContains: "",
},
@@ -703,7 +711,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key-operator-value boundary",
query: "quoted\"text\"",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND match(body, ?))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND match(LOWER(body), LOWER(?)))",
expectedArgs: []any{"quoted", "text"},
expectedErrorContains: "",
},
@@ -719,7 +727,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key-operator-value boundary",
query: "function(param)",
shouldPass: true,
- expectedQuery: "WHERE (match(body, ?) AND (match(body, ?)))",
+ expectedQuery: "WHERE (match(LOWER(body), LOWER(?)) AND (match(LOWER(body), LOWER(?))))",
expectedArgs: []any{"function", "param"},
expectedErrorContains: "",
},
@@ -727,7 +735,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key-operator-value boundary",
query: `"function(param)"`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"function(param)"},
expectedErrorContains: "",
},
@@ -743,7 +751,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "Key-operator-value boundary",
query: `"user=admin"`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{"user=admin"},
expectedErrorContains: "",
},
@@ -1357,7 +1365,7 @@ func TestFilterExprLogs(t *testing.T) {
category: "REGEXP operator",
query: `"^\[(INFO|WARN|ERROR|DEBUG)\] .+$"`,
shouldPass: true,
- expectedQuery: "WHERE match(body, ?)",
+ expectedQuery: "WHERE match(LOWER(body), LOWER(?))",
expectedArgs: []any{`^\[(INFO|WARN|ERROR|DEBUG)\] .+$`},
expectedErrorContains: "",
},
diff --git a/pkg/telemetrylogs/stmt_builder_test.go b/pkg/telemetrylogs/stmt_builder_test.go
index e22c2f249f..5e6205dde5 100644
--- a/pkg/telemetrylogs/stmt_builder_test.go
+++ b/pkg/telemetrylogs/stmt_builder_test.go
@@ -266,7 +266,7 @@ func TestStatementBuilderListQueryResourceTests(t *testing.T) {
Limit: 10,
},
expected: qbtypes.Statement{
- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND match(body, ?) AND timestamp >= ? AND timestamp < ? AND ts_bucket_start >= ? AND ts_bucket_start <= ? LIMIT ?",
+ Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE true AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND match(LOWER(body), LOWER(?)) AND timestamp >= ? AND timestamp < ? AND ts_bucket_start >= ? AND ts_bucket_start <= ? LIMIT ?",
Args: []any{uint64(1747945619), uint64(1747983448), "hello", "1747947419000000000", "1747983448000000000", uint64(1747945619), uint64(1747983448), 10},
},
expectedErr: nil,
@@ -294,7 +294,7 @@ func TestStatementBuilderListQueryResourceTests(t *testing.T) {
},
},
expected: qbtypes.Statement{
- Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE ((simpleJSONExtractString(labels, 'service.name') = ? AND labels LIKE ? AND labels LIKE ?)) AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (match(body, ?)) AND timestamp >= ? AND timestamp < ? AND ts_bucket_start >= ? AND ts_bucket_start <= ? ORDER BY `attribute_string_materialized$$key$$name` AS `materialized.key.name` desc LIMIT ?",
+ Query: "WITH __resource_filter AS (SELECT fingerprint FROM signoz_logs.distributed_logs_v2_resource WHERE ((simpleJSONExtractString(labels, 'service.name') = ? AND labels LIKE ? AND labels LIKE ?)) AND seen_at_ts_bucket_start >= ? AND seen_at_ts_bucket_start <= ?) SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string FROM signoz_logs.distributed_logs_v2 WHERE resource_fingerprint GLOBAL IN (SELECT fingerprint FROM __resource_filter) AND (match(LOWER(body), LOWER(?))) AND timestamp >= ? AND timestamp < ? AND ts_bucket_start >= ? AND ts_bucket_start <= ? ORDER BY `attribute_string_materialized$$key$$name` AS `materialized.key.name` desc LIMIT ?",
Args: []any{"cartservice", "%service.name%", "%service.name\":\"cartservice%", uint64(1747945619), uint64(1747983448), "hello", "1747947419000000000", "1747983448000000000", uint64(1747945619), uint64(1747983448), 10},
},
expectedErr: nil,