Hi!
So we are deploying Alloy helm chart to K8S cluster as daemonset and clustering mode.
Alloy pods all scrapes Kubernetes logs, only those of the same node of the alloy pods thanks to doc: discovery.kubernetes | Grafana Alloy documentation
Now the question is how to do the same to scrape a Kubernetes service (nextcloud-metrics). Without any safeguard, I got 429 too many request because all Alloy pods scrapes the same service.
I know I can do clustering mode so that Alloy distributes to all pods the scrape of nextcloud service. But is-it possible to scrape only on one Alloy pod instead of everyone? I was thinking to colocate the Alloy pod with the nextcloud pod of them metrics (assuming there is only one) but that is difficult to do, isn’t it?
Or do you consider a best-practice instead to make multiple Alloy cluster, one Daemonset for pods, and one StatefulSet for any other things: nextcloud metrics, Kubernetes events, etc.? I was searching for best-practice doc on Alloy but couldn’t find a global configuration example.
Hi.
Your most likely fix…enable clustering on the scrape component itself. Turning it on in Helm isn’t enough. Each component that should share work needs its own clustering block, otherwise every Alloy pod scrapes every target, and you get 429s.
For example:
prometheus.scrape "nextcloud" {
targets = discovery.kubernetes.nextcloud.targets
forward_to = [prometheus.remote_write.default.receiver]
clustering {
enabled = true
}
}
Each target is scraped by only one Alloy Pod. Sharding is per target, so if discovery returns a single target, a single Pod scrapes it.
Docs:
Alternatively, you can adhere to the traditional way of doing things. Deploy alloy daemonset, then deploy another set of alloy replicas (you can cluster these if you deploy more than 1), and then use the replicas to do the scraping, and the daemonset for host level metrics.
Hi, yes this is what I did and it works. My question was it there another way to not do clustering on daemonset. I guess the answer is no.
Ok thanks! So to sum-up, my choice of deployment:
- only 1 cluster alloy daemonset => service must be in clustering mode
- 1 cluster alloy daemonset + 1 cluster deployment for the service => service must still be in clustering but there are less node to distribute the service (vs daemonset cluster) so it is better.