Skip to content

Commit

Permalink
fix(chstorage.q.logs): fix body tag matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Dec 1, 2023
1 parent 5312701 commit e1f81a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions integration/lokie2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ func runTest(
// By trace id.
{`{trace_id="af36000000000000c517000000000003"}`, 1},
{`{trace_id="AF36000000000000C517000000000003"}`, 1},
{`{trace_id=~"AF3600.+000C517000.+00003"}`, 1},
{`{trace_id="badbadbadbadbadbaddeadbeafbadbad"}`, 0},
{`{trace_id=~"bad.+"}`, 0},
// By severity.
{`{level="Info"}`, 121},
{`{level="INFO"}`, 121},
// All by service name.
{`{service_name="testService"}`, len(set.Records)},
{`{service_name=~"test.+"}`, len(set.Records)},
// Effectively match GET.
{`{http_method="GET"}`, 21},
{`{http_method=~".*GET.*"}`, 21},
Expand Down Expand Up @@ -189,6 +192,8 @@ func runTest(
{`{http_method=~".+"} |= "HEAD" |= " 500 "`, 2},
{`{http_method=~".+"} |~ "DELETE"`, 20},
{`{http_method=~".+"} |~ "HEAD" |= " 500 "`, 2},
{`{http_method=~".+"} |~ "(GET|HEAD)"`, 43},
{`{http_method=~".+"} |~ "GE.+"`, 21},
// Try to not use offloading.
{`{http_method=~".+"} | line_format "{{ __line__ }}" |= "DELETE"`, 20},
{`{http_method=~".+"} | line_format "{{ __line__ }}" |= "HEAD" |= " 500 "`, 2},
Expand Down
12 changes: 6 additions & 6 deletions internal/chstorage/querier_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,14 @@ func (q *Querier) SelectLogs(ctx context.Context, start, end otelstorage.Timesta
case logql.OpEq, logql.OpNotEq:
fmt.Fprintf(&query, "trace_id = unhex(%s)", singleQuoted(m.Value))
case logql.OpRe, logql.OpNotRe:
fmt.Fprintf(&query, "hex(trace_id) REGEXP %s", singleQuoted(m.Value))
fmt.Fprintf(&query, "match(hex(trace_id), %s)", singleQuoted(m.Value))
}
case logstorage.LabelSpanID:
switch m.Op {
case logql.OpEq, logql.OpNotEq:
fmt.Fprintf(&query, "span_id = unhex(%s)", singleQuoted(m.Value))
case logql.OpRe, logql.OpNotRe:
fmt.Fprintf(&query, "hex(span_id) REGEXP %s", singleQuoted(m.Value))
fmt.Fprintf(&query, "match(hex(span_id), %s)", singleQuoted(m.Value))
}
case logstorage.LabelSeverity:
switch m.Op {
Expand All @@ -373,15 +373,15 @@ func (q *Querier) SelectLogs(ctx context.Context, start, end otelstorage.Timesta
case logql.OpEq, logql.OpNotEq:
fmt.Fprintf(&query, "positionUTF8(body, %s) > 0", singleQuoted(m.Value))
case logql.OpRe, logql.OpNotRe:
fmt.Fprintf(&query, "service_name REGEXP %s", singleQuoted(m.Value))
fmt.Fprintf(&query, "match(body, %s)", singleQuoted(m.Value))
}
case logstorage.LabelServiceName, logstorage.LabelServiceNamespace, logstorage.LabelServiceInstanceID:
// Materialized from resource.service.{name,namespace,instance_id}.
switch m.Op {
case logql.OpEq, logql.OpNotEq:
fmt.Fprintf(&query, "%s = %s", labelName, singleQuoted(m.Value))
case logql.OpRe, logql.OpNotRe:
fmt.Fprintf(&query, "%s REGEXP %s", labelName, singleQuoted(m.Value))
fmt.Fprintf(&query, "match(%s, %s)", labelName, singleQuoted(m.Value))
}
default:
// Search in all attributes.
Expand All @@ -398,7 +398,7 @@ func (q *Querier) SelectLogs(ctx context.Context, start, end otelstorage.Timesta
case logql.OpEq, logql.OpNotEq:
fmt.Fprintf(&query, "JSONExtractString(%s, %s) = %s", column, singleQuoted(labelName), singleQuoted(m.Value))
case logql.OpRe, logql.OpNotRe:
fmt.Fprintf(&query, "JSONExtractString(%s, %s) REGEXP %s", column, singleQuoted(labelName), singleQuoted(m.Value))
fmt.Fprintf(&query, "match(JSONExtractString(%s, %s), %s)", column, singleQuoted(labelName), singleQuoted(m.Value))
}
}
}
Expand Down Expand Up @@ -432,7 +432,7 @@ func (q *Querier) SelectLogs(ctx context.Context, start, end otelstorage.Timesta
}
}
case logql.OpRe, logql.OpNotRe:
fmt.Fprintf(&query, "body REGEXP %s", singleQuoted(m.Value))
fmt.Fprintf(&query, "match(body, %s)", singleQuoted(m.Value))
}
query.WriteByte(')')
}
Expand Down

0 comments on commit e1f81a2

Please sign in to comment.