Skip to content

Detect the stream filters due filter in/out option #691

Description

@arturminchukov

Is your feature request related to a problem?

When a user clicks Filter for value / Filter out value in the log details view (Explore / Logs panel), the datasource always adds a regular field filter:

field:="value"

Regular field filters scan data blocks, so on large volumes such queries can be slow — even when the clicked field is actually a stream field (e.g. app, namespace, instance).

Describe the solution you'd like

Detect whether the clicked field is a stream field and, if so, add it as a stream filter instead:

{field="value"}

Stream filters are resolved via the stream index and are the most efficient filter type in LogsQL, so this should noticeably reduce query execution time for filter in/out actions on stream fields.

Implementation notes

  • Detection can be synchronous and free: toggleQueryFilter receives ToggleFilterAction with an optional frame: DataFrame, and the backend already attaches per-row stream label maps to every logs frame (meta.custom.streams, built from the _stream field). The clicked key is a stream field iff it is present in those maps. This is the same mechanism Loki uses to detect label types.
  • The filter chip can be marked with a flag (similar to the existing editor-only fromLevelFilter flag), and the serialization branch added in getFilterInsertValue, which already special-cases _stream / _stream_id. Both delivery paths (root-query prefix and extra_filters) accept LogsQL filters, so the stream syntax works in both.
  • Operators map 1:1 — {...} supports =, !=, =~, !~.
  • Fallback: if no frame is available in the action, keep the current behavior (regular field filter).

Things to verify

  • Filter-out semantics: {k!="v"} may also match streams without the label k (PromQL-like semantics). Compare with the current k:!="v" behavior and pick the equivalent form (possibly -{k="v"}).
  • Stream filters passed via extra_filters are optimized by the index the same way as inline ones.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions