Is there a way to use Grafana Alloy deployed as a DaemonSet which scrapes logs for each namespace found it would use that name-space as a tenant-id to send to Loki?
Yes. loki.source.kubernetes
has a meta label for namespace (loki.source.kubernetes | Grafana Alloy documentation), and loki.write
supports headers, which you can use to specify the tenant id with.
Thank you for your response. Does it assign the tenant-id dynamically when it sends it to loki? I have a running multi-tenant apps in my cluster therefore need the daemon-set to find all namespaces and its logs then for each namespace it finds use that namespace as a tenant-id header.
I see, apologies I misunderstood your post.
No, I don’t think you can dynamically assign the tenant ID. Your best bet is probably creating multiple loki.write
blocks and route your logs with hardcoded values.
I would also encourage you to perhaps consider just using labels for to separate your namespaces.
@rws198240 It should be possible with the stage.tenant block
loki.process "pod_logs" {
...
stage.tenant {
source = "namespace"
}
}
That looks like the solution indeed.