This is documentation for the next version of Grafana Alloy Documentation. For the latest stable release, go to the latest version.
Distribute workload across cluster nodes
After you enable clustering in Alloy, you can configure individual components to distribute their workload across the cluster.
Clustering with target auto-distribution allows a fleet of Alloy instances to dynamically distribute workload and provides high availability and horizontal scalability.
Before you begin
- Configure clustering in your Alloy installation.
- Ensure that all clustered Alloy instances have the same configuration file.
Enable clustering in components
To enable workload distribution, add a clustering block with enabled = true inside each component block that should participate:
component.type "example" {
# ...component settings...
clustering {
enabled = true
}
}Note
Components don’t automatically participate in clustering. You must explicitly enable clustering in each component that should distribute workload. If cluster mode is enabled but a component doesn’t have
clustering { enabled = true }, every node runs that component’s full workload, which causes duplicate scraping, log collection, or profiling.
Components that support clustering
The following components support the clustering block:
Prometheus metrics collection components:
prometheus.operator.podmonitorsprometheus.operator.probesprometheus.operator.scrapeconfigsprometheus.operator.servicemonitorsprometheus.scrape
Pyroscope profiling components:
Loki log collection components:
Database observability components:
Example: Distribute Prometheus metrics scrape load
This example shows how to configure prometheus.scrape to distribute scrape targets across cluster nodes.
Add a
clusteringblock to yourprometheus.scrapecomponent:prometheus.scrape "default" { targets = discovery.kubernetes.pods.targets forward_to = [prometheus.remote_write.default.receiver] clustering { enabled = true } }Restart or reload Alloy for it to use the new configuration.
Validate that auto-distribution works:
Use the Alloy UI on each node, navigate to the details page for the
prometheus.scrapecomponent.Compare the Debug Info sections between two different nodes to ensure that they don’t scrape the same sets of targets.
Example: Distribute log collection
This example shows how to configure loki.source.kubernetes to distribute log collection across cluster nodes.
loki.source.kubernetes "pods" {
targets = discovery.kubernetes.pods.targets
forward_to = [loki.write.default.receiver]
clustering {
enabled = true
}
}Example: Distribute profiling targets
This example shows how to configure pyroscope.scrape to distribute profiling targets across cluster nodes.
pyroscope.scrape "default" {
targets = discovery.kubernetes.pods.targets
forward_to = [pyroscope.write.default.receiver]
clustering {
enabled = true
}
}How workload distribution works
When you enable clustering in a component:
- All cluster nodes use a consistent hashing algorithm to determine target ownership.
- Each node only processes the subset of targets it’s responsible for.
- When a node joins or leaves the cluster, targets are automatically redistributed.
- Approximately 1/N of targets are redistributed when cluster membership changes. This minimizes disruption.
Note
Target labels must be consistent across all cluster nodes. If target discovery adds node-specific labels, such as
constants.hostname, the hashing algorithm can’t consistently determine target ownership.
For more information about clustering concepts, refer to Clustering.


