Skip to content

Conversation

@matt-gp
Copy link
Contributor

@matt-gp matt-gp commented Oct 10, 2025

PR Description

This change is to add logic so that labels that start with __ are filtered out. Labels that start with __ are used internally for things such as metadata. If a user want to preserve the contents of one of these internal labels, then can do so using relabelling to remove the __.

This change also adds tests which check various different scenarios.

Which issue(s) this PR fixes

Fixes #4412

Notes to the Reviewer

The docs already state that labels with __ get removed, so I don't see the need to update these.

PR Checklist

  • CHANGELOG.md updated
  • Tests updated

@matt-gp matt-gp requested a review from a team as a code owner October 10, 2025 20:43
@matt-gp matt-gp changed the title Loki Write: Internal Labels Loki Write: Remove Internal Labels Oct 11, 2025
@baurmatt
Copy link
Contributor

Is there a specific reason why externalLabels starting with __ should be treated differently? To my knowledge, __ is core design concept of Prometheus and labels are always treat as Prometheus-internal: https://prometheus.io/docs/concepts/data_model/

I don't see a reason why loki.write should handle this and other way.

@matt-gp
Copy link
Contributor Author

matt-gp commented Oct 13, 2025

I thought because an externalLabel is something that a user would intentionally add, then we may want to include them. Happy to remove them though if needed.

@matt-gp
Copy link
Contributor Author

matt-gp commented Oct 13, 2025

Updated to remove __ labels from externalLabels as well

@matt-gp matt-gp force-pushed the loki-meta-labels branch 2 times, most recently from f6105ff to fc2b42d Compare October 13, 2025 08:35
@matt-gp matt-gp requested a review from kalleep October 17, 2025 21:22
@matt-gp matt-gp force-pushed the loki-meta-labels branch 3 times, most recently from 263134f to 0ff2d38 Compare October 22, 2025 08:22
@matt-gp matt-gp force-pushed the loki-meta-labels branch 3 times, most recently from e349b50 to 93bb8f2 Compare October 23, 2025 08:27
@matt-gp matt-gp requested a review from kalleep October 23, 2025 09:32
@kalleep
Copy link
Contributor

kalleep commented Oct 30, 2025

After thinking about this a bit I think we should not do this directly in the component but here instead https://github.com/grafana/alloy/blob/main/internal/component/common/loki/client/batch.go#L116

Pretty sure we can just remove the without argument there and just skip any label that have __ as prefix

@matt-gp matt-gp force-pushed the loki-meta-labels branch 3 times, most recently from ca31f05 to 5b054a4 Compare October 30, 2025 19:24
@matt-gp matt-gp requested a review from kalleep October 30, 2025 19:30
This change is to add logic so that labels that start with `__` are
filtered out, unless they are `externalLabels`. Labels that start with
`__` are used internally for things such as metadata. If a user want to
preserve the contents of one of these internal labels, then can do so
using relabelling to remove the `__`.

This change also adds tests which check various different scenarios
@kalleep kalleep merged commit 802726b into grafana:main Nov 3, 2025
37 checks passed
@matt-gp matt-gp deleted the loki-meta-labels branch November 3, 2025 09:18
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.

loki.write sends __ internal labels

3 participants