Skip to content

Show stream labels in context modal#673

Open
arturminchukov wants to merge 4 commits into
mainfrom
665-show-stream-labels-in-context-modal
Open

Show stream labels in context modal#673
arturminchukov wants to merge 4 commits into
mainfrom
665-show-stream-labels-in-context-modal

Conversation

@arturminchukov

@arturminchukov arturminchukov commented Jun 17, 2026

Copy link
Copy Markdown
Member

Related issue: #665

Describe Your Changes

  1. Add parsing streams (was removed in the last commit) on the backend part to set streamId and stream labels to custom metadata.
  2. Moved the code related to Context to a separate class.
  3. Added stream labels to context modal. Now it is possible to widen stream fields to view logs from other pods/services.
image

Context for all pods:
image

Checklist

The following checks are mandatory:


Summary by cubic

Show stream labels in the “Show context” modal so you can widen context by toggling labels and view logs across pods/services. Backend parses _stream and sends per‑row labels/ids via meta.custom to power the selector. Addresses #665.

  • New Features

    • Added a stream label selector to the context modal; each label is a toggleable chip.
    • Context query uses _stream_id by default, or _stream:{...} from enabled labels when some are toggled off.
    • Safeguards: at least one label stays enabled; label keys with spaces are quoted; values are escaped.
    • Works for both instant and streaming responses; supports Explore and Dashboards.
  • Refactors

    • Backend: parse _stream per row into meta.custom.streams and meta.custom.streamIds; remove _stream from log labels.
    • Frontend: moved context logic into a new LogContextProvider; added LogContextUI and a shared ToggleChip component.
    • Kept meta.custom intact in frame processing, passing through streams/streamIds.
    • Expanded tests for response parsing, stream selector parsing (incl. invalid cases), frame processing, and the new provider/UI.

Written for commit f17238a. Summary will update on new commits.

Review in cubic

…stom

- Parse `_stream` per row into a label->value map and ship it, together with
  the per-row `_stream_id`, in frame meta.custom for the "Show context"
  stream label selector
- Drop `_stream` from the log labels now that it is carried in meta.custom
- Apply to both the instant and streaming response paths
- Refactor datasource class, move out the LogContextProvider in the separate class
- Render each stream label of the log row as a toggleable chip; toggling a
  label off widens the context search from `_stream_id` to a `_stream:{...}`
  selector built from the still-enabled labels
@arturminchukov arturminchukov linked an issue Jun 17, 2026 that may be closed by this pull request
@arturminchukov arturminchukov self-assigned this Jun 18, 2026

@Loori-R Loori-R left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. I left a few questions.

value.Del(streamField)
stf, err := utils.ParseStreamFields(rowStream)
if err != nil {
return newResponseError(fmt.Errorf("error parse _stream field: %s", err), backend.StatusInternal)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid _stream now fails the whole logs response. Since it is only needed for the context selector, can we skip meta.custom.streams for this row instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just partially reverted the changes as it was early - https://github.com/VictoriaMetrics/victorialogs-datasource/blob/v0.28.0/pkg/plugin/response.go#L122 . We also threw an error.
IMO, the _stream field should always be in the log. So if something is wrong with the _stream field, it will be better to throw an error. So it could be fixed.

// parse `_stream` into a per-row label map for the log context UI and
// drop it from the row so it does not show up among the log labels
rowStream := string(value.GetStringBytes(streamField))
value.Del(streamField)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code remove the _stream field from the response? If yes, could this break existing Explore/table views, field overrides, or Grafana transformations that reference _stream?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't affect the backward compatibility, as in the current release, this field is also removed on the backend side.

Comment on lines +49 to +56
getRowStreamId = (row: LogRowModel): string => {
const streamIds = row.dataFrame.meta?.custom?.streamIds;
if (streamIds && streamIds.length > 0 && streamIds[row.rowIndex]) {
return streamIds[row.rowIndex];
}

return '';
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous _stream_id fallback from row.labels was removed here. Is that intentional? If meta.custom.streamIds is missing, the context query now uses _stream_id:"".

@arturminchukov arturminchukov Jun 19, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!
But I think that from the DS backend we should get streamId every time and need to move this logic to the DS backend.
I thought that _stream_id should always be. But also need to handle edge cases correctly where the user manually removed system fields (_stream, _stream_id) via a query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show stream labels in context modal

2 participants