Skip to content

Commit b2c4f3c

Browse files
authored
Improve allocation strategy documentation (#2848)
1 parent da48d65 commit b2c4f3c

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

apis/v1alpha1/opentelemetrycollector_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ type OpenTelemetryTargetAllocator struct {
317317
// AllocationStrategy determines which strategy the target allocator should use for allocation.
318318
// The current options are least-weighted, consistent-hashing and per-node. The default is
319319
// consistent-hashing.
320+
// WARNING: The per-node strategy currently ignores targets without a Node, like control plane components.
320321
// +optional
321322
// +kubebuilder:default:=consistent-hashing
322323
AllocationStrategy OpenTelemetryTargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"`

apis/v1beta1/opentelemetrycollector_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ type TargetAllocatorEmbedded struct {
143143
// AllocationStrategy determines which strategy the target allocator should use for allocation.
144144
// The current options are least-weighted, consistent-hashing and per-node. The default is
145145
// consistent-hashing.
146+
// WARNING: The per-node strategy currently ignores targets without a Node, like control plane components.
146147
// +optional
147148
// +kubebuilder:default:=consistent-hashing
148149
AllocationStrategy TargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"`

apis/v1beta1/targetallocator_types.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ type TargetAllocatorSpec struct {
6161
// CollectorSelector is the selector for Collector Pods the target allocator will allocate targets to.
6262
CollectorSelector metav1.LabelSelector `json:"collectorSelector,omitempty"`
6363
// AllocationStrategy determines which strategy the target allocator should use for allocation.
64-
// The current options are least-weighted and consistent-hashing. The default option is consistent-hashing
64+
// The current options are least-weighted, consistent-hashing and per-node. The default is
65+
// consistent-hashing.
66+
// WARNING: The per-node strategy currently ignores targets without a Node, like control plane components.
6567
// +optional
6668
// +kubebuilder:default:=consistent-hashing
6769
AllocationStrategy TargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"`

cmd/otel-allocator/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,33 @@ sequenceDiagram
3030
OTel Collectors ->>Metrics Targets: 5. Scrape Metrics target
3131
```
3232

33+
### Allocation strategies
34+
35+
Several target allocation strategies are available. Some strategies may only make sense for a given Collector deployment
36+
mode. For example, the `per-node` strategy only works correctly with a Collector deployed as a DaemonSet.
37+
38+
#### `consistent-hashing`
39+
40+
A consistent hashing strategy implementing the [following algorithm][consistent_hashing]. Only the target url is hashed
41+
to prevent label changes from causing targets to be moved between collectors. This strategy consistently assigns
42+
targets to the same collectors, but will experience rebalancing when the collector count changes.
43+
44+
This is the default.
45+
46+
#### `least-weighted`
47+
48+
A strategy that simply assigns the target to the collector with the least number of targets. It achieves more stability
49+
in target assignment when collector count changes, but at the cost of less even distribution of targets.
50+
51+
#### `per-node`
52+
53+
This strategy assigns each target to the collector running on the same Node the target is. As such, it only makes sense
54+
to use it with a collector running as a DaemonSet.
55+
56+
> [!WARNING]
57+
> The per-node strategy ignores targets not assigned to a Node, like for example control plane components.
58+
59+
[consistent_hashing]: https://blog.research.google/2017/04/consistent-hashing-with-bounded-loads.html
3360
## Discovery of Prometheus Custom Resources
3461

3562
The Target Allocator also provides for the discovery of [Prometheus Operator CRs](https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/getting-started.md), namely the [ServiceMonitor and PodMonitor](https://github.com/open-telemetry/opentelemetry-operator/tree/main/cmd/otel-allocator#target-allocator). The ServiceMonitors and the PodMonitors purpose is to inform the Target Allocator (or PrometheusOperator) to add a new job to their scrape configuration. The Target Allocator then provides the jobs to the OTel Collector [Prometheus Receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/prometheusreceiver/README.md).

docs/api.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -21565,7 +21565,8 @@ TargetAllocator indicates a value which determines whether to spawn a target all
2156521565
<td>
2156621566
AllocationStrategy determines which strategy the target allocator should use for allocation.
2156721567
The current options are least-weighted, consistent-hashing and per-node. The default is
21568-
consistent-hashing.<br/>
21568+
consistent-hashing.
21569+
WARNING: The per-node strategy currently ignores targets without a Node, like control plane components.<br/>
2156921570
<br/>
2157021571
<i>Enum</i>: least-weighted, consistent-hashing, per-node<br/>
2157121572
<i>Default</i>: consistent-hashing<br/>

0 commit comments

Comments
 (0)