Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
walnuss0815 opened this issue Jan 24, 2025 · 1 comment
Open

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

walnuss0815 opened this issue Jan 24, 2025 · 1 comment
Labels
proposal A proposal for new functionality.

Comments

@walnuss0815
Copy link

walnuss0815 commented Jan 24, 2025

Background

Currently the discovered pod metadata labels (discovered_labels, see https://grafana.com/docs/alloy/latest/reference/components/loki/loki.source.podlogs/#podlogsspec) are only available in the RelabelConfig of the PodLogs CR. I would like to archive that the discovered labels/discovered_labels from loki.source.podlogs are available in a loki.relabel component, so I can relabel the logs without appending common relabeling rules to every PodLogs CR.

I've attached the current configuration below.

Alloy component graph: loki.source.podlogs --> loki.relabel --> loki.write

config.alloy
loki.source.podlogs "podlogs" {
  clustering {
    enabled = true
  }
  forward_to = [loki.relabel.podlogs.receiver]
}

loki.relabel "podlogs" {
  forward_to = [loki.write.local.receiver]
  rule {
    action = "replace"
    source_labels = ["__meta_kubernetes_namespace"]
    target_label = "namespace"
  }
  rule {
    action = "replace"
    source_labels = ["__meta_kubernetes_pod_name"]
    target_label = "pod"
  }
  rule {
    action = "replace"
    source_labels = ["__meta_kubernetes_pod_container_name"]
    target_label = "container_name"
  }
  rule {
    action = "replace"
    source_labels = ["__meta_kubernetes_pod_node_name"]
    target_label = "node"
  }
  rule {
    action = "replace"
    source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_instance"]
    target_label = "instance"
  }
  rule {
    action = "replace"
    source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"]
    target_label = "app"
  }
}

loki.write "local" {
  endpoint {
    url = "http://loki-gateway.loki:80/loki/api/v1/push"
  }
}
example-podlogs.yaml
apiVersion: monitoring.grafana.com/v1alpha2
kind: PodLogs
metadata:
  name: example
  namespace: example
spec:
  selector: {}
  namespaceSelector:
    matchLabels:
      kubernetes.io/metadata.name: example

Proposal

I suggest to make it possible to keep discovered labels from loki.source.podlogs, so they are available in the component the logs are being forwarded to. There are at least two options:

Option 1

Add a boolean option to loki.source.podlogs to keep and forward all discovered labels.

Option 2

Add a block for relabing rules to loki.source.podlogs. The relabeling rules the could be merged with the rules from the PodLogs CR or could be applied beforehand.

@walnuss0815 walnuss0815 added the proposal A proposal for new functionality. label Jan 24, 2025
@QuentinBisson
Copy link
Contributor

The code is here

discoveredPod.Containers = append(discoveredPod.Containers, DiscoveredContainer{

I would be able to contribute a solution but I need to know what the maintainers would like to do here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal A proposal for new functionality.
Projects
Status: Incoming
Development

No branches or pull requests

2 participants