Skip to content

feat(loki.source.podlogs): add preserve_discovered_labels option#4606

Merged
kalleep merged 9 commits intografana:mainfrom
QuentinBisson:feature/preserve-discovered-labels-2526
Nov 3, 2025
Merged

feat(loki.source.podlogs): add preserve_discovered_labels option#4606
kalleep merged 9 commits intografana:mainfrom
QuentinBisson:feature/preserve-discovered-labels-2526

Conversation

@QuentinBisson
Copy link
Contributor

PR Description

Add a new preserve_discovered_labels parameter to loki.source.podlogs component that allows discovered Kubernetes metadata labels to be preserved and forwarded to downstream components like loki.relabel.

When enabled, this option preserves _meta_kubernetes* labels that would normally be stripped after relabeling, enabling component chaining where pod metadata can be accessed by downstream relabeling components.

Which issue(s) this PR fixes

Fixes #2526

Notes to the Reviewer

Because loki.write drops any labels that starts with __ but the __tenant_id_ label, this should not impact downstream Loki but would definitely help loki.source.podlogs users/

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

Add a new preserve_discovered_labels parameter to loki.source.podlogs component
that allows discovered Kubernetes metadata labels to be preserved and forwarded
to downstream components like loki.relabel.

When enabled, this option preserves __meta_kubernetes_* labels that would normally
be stripped after relabeling, enabling component chaining where pod metadata can
be accessed by downstream relabeling components.

Fixes grafana#2526
@QuentinBisson QuentinBisson requested review from a team and clayton-cornell as code owners October 13, 2025 15:18
Comment on lines +299 to +301


When `preserve_discovered_labels` is disabled (the default), `loki.source.podlogs` doesn't export any fields.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
When `preserve_discovered_labels` is disabled (the default), `loki.source.podlogs` doesn't export any fields.
When `preserve_discovered_labels` is disabled (the default), `loki.source.podlogs` doesn't export any fields.

Remove empty lines.

Do we need to document what happens when preserve_discovered_labels is enabled? What is exported when it's enabled?

@QuentinBisson
Copy link
Contributor Author

Thank you @clayton-cornell :)

@clayton-cornell
Copy link
Contributor

Still wondering about this one: Do we need to document what happens when preserve_discovered_labels is enabled? What is exported when it's enabled?

@QuentinBisson
Copy link
Contributor Author

The discovered Labels are send downstream components like Loki process (which is not the case by default) but are dropped by either loki.process or loki.write upon complétion of the pipeline

@clayton-cornell clayton-cornell added the type/docs Docs Squad label across all Grafana Labs repos label Oct 27, 2025
@clayton-cornell clayton-cornell requested a review from a team October 27, 2025 21:23
@icelynjennings
Copy link

Thank you!!! Much needed. Happy to help test on live clusters.

@QuentinBisson
Copy link
Contributor Author

@kalleep I think the changelog of my previous PR was not set in the correct place so I updated it here if that's alright?

Copy link
Contributor

@kalleep kalleep left a comment

Choose a reason for hiding this comment

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

Because loki.write drops any labels that starts with __ but the _tenant_id label, this should not impact downstream Loki but would definitely help loki.source.podlogs users/

This is not true but there is a pr up to fix this that I have should take another look at https://github.com/grafana/alloy/pull/4601/files.

Otherwise this looks good except there is still an unresolved comment from @clayton-cornell

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
@QuentinBisson
Copy link
Contributor Author

Oh i think i might have mixed components up. I remember one of them used to drop the __meta, but maybe it was the loki.source.api. Sorry about the confusion

@kalleep
Copy link
Contributor

kalleep commented Oct 30, 2025

Oh i think i might have mixed components up. I remember one of them used to drop the __meta, but maybe it was the loki.source.api. Sorry about the confusion

Well it's documented that we do drop all internal labels https://grafana.com/docs/alloy/latest/reference/components/loki/loki.write/#technical-details but we don't do it 🙈

@QuentinBisson
Copy link
Contributor Author

Oh that makes sense. But you might want to not drop the __tenant label though

@kalleep
Copy link
Contributor

kalleep commented Oct 30, 2025

Oh that makes sense. But you might want to not drop the __tenant label though

Nope we don't want to do that. As I said I need to take a look at that pr :)

@QuentinBisson
Copy link
Contributor Author

Thank you for your awesome help :)

@clayton-cornell
Copy link
Contributor

There's a couple doc suggestions that look like they were resolved without applying the change - capitalizing Pod. This is a doc standard across the Grafana docs when referencing a Kubernetes Pod. If you take a look at the Kubernetes docs, you can see it's capitalized there too, and we should follow the upstream naming.

QuentinBisson and others added 3 commits October 30, 2025 22:58
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
@QuentinBisson
Copy link
Contributor Author

QuentinBisson commented Oct 30, 2025

Sorry @clayton-cornell , I don't know what happened. I think I merged them all

@clayton-cornell
Copy link
Contributor

I think I merged them all

All good :-) multiple eyes on a PR and we get it all sorted

@kalleep
Copy link
Contributor

kalleep commented Oct 31, 2025

Just some lint issue and merge conflict with changelog but then we should be good to go 👍

@QuentinBisson
Copy link
Contributor Author

@kalleep it should be fixed now :)

@kalleep kalleep merged commit 9d60ad3 into grafana:main Nov 3, 2025
38 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age type/docs Docs Squad label across all Grafana Labs repos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loki.source.podlogs: Add option to keep discovered labels

4 participants