Skip to content

Commit

Permalink
Changed default allocation & filtering strategy (#2485)
Browse files Browse the repository at this point in the history
* Change default allocation strategy to consistent-hashing

* Change default filtering strategy to relabel-config

* Add changelog

* Change default allocation strategy to consistent-hashing

* Change default allocation strategy to consistent-hashing

* Fix config hash
  • Loading branch information
utr1903 authored Jan 9, 2024
1 parent 14d1b81 commit d7a0840
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 15 deletions.
16 changes: 16 additions & 0 deletions .chloggen/change-default-strategies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: target allocator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Change default allocation and filtering strategy

# One or more tracking issues related to the change
issues: [2477]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
3 changes: 2 additions & 1 deletion apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ type OpenTelemetryTargetAllocator struct {
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
// AllocationStrategy determines which strategy the target allocator should use for allocation.
// The current options are least-weighted and consistent-hashing. The default option is least-weighted
// The current options are least-weighted and consistent-hashing. The default option is consistent-hashing
// +optional
// +kubebuilder:default:=consistent-hashing
AllocationStrategy OpenTelemetryTargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"`
// FilterStrategy determines how to filter targets before allocating them among the collectors.
// The only current option is relabel-config (drops targets based on prom relabel_config).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5024,10 +5024,11 @@ spec:
type: object
type: object
allocationStrategy:
default: consistent-hashing
description: AllocationStrategy determines which strategy the
target allocator should use for allocation. The current options
are least-weighted and consistent-hashing. The default option
is least-weighted
is consistent-hashing
enum:
- least-weighted
- consistent-hashing
Expand Down
4 changes: 2 additions & 2 deletions cmd/otel-allocator/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ func (c Config) GetAllocationStrategy() string {
if c.AllocationStrategy != nil {
return *c.AllocationStrategy
}
return "least-weighted"
return "consistent-hashing"
}

func (c Config) GetTargetsFilterStrategy() string {
if c.FilterStrategy != nil {
return *c.FilterStrategy
}
return ""
return "relabel-config"
}

func LoadFromFile(file string, target *Config) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5021,10 +5021,11 @@ spec:
type: object
type: object
allocationStrategy:
default: consistent-hashing
description: AllocationStrategy determines which strategy the
target allocator should use for allocation. The current options
are least-weighted and consistent-hashing. The default option
is least-weighted
is consistent-hashing
enum:
- least-weighted
- consistent-hashing
Expand Down
8 changes: 4 additions & 4 deletions controllers/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ service:
Annotations: nil,
},
Data: map[string]string{
"targetallocator.yaml": `allocation_strategy: least-weighted
"targetallocator.yaml": `allocation_strategy: consistent-hashing
collector_selector:
matchlabels:
app.kubernetes.io/component: opentelemetry-collector
Expand Down Expand Up @@ -1377,7 +1377,7 @@ label_selector:
"app.kubernetes.io/version": "latest",
},
Annotations: map[string]string{
"opentelemetry-targetallocator-config/hash": "20c09760c240d08287ff05bd2375985220b577d938e82efd85467e17174690e0",
"opentelemetry-targetallocator-config/hash": "9126d0bb3bde858f655580a9ae6d4557c69ee430b4ab9f72e08c66334efe7989",
},
},
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -1705,7 +1705,7 @@ label_selector:
Annotations: nil,
},
Data: map[string]string{
"targetallocator.yaml": `allocation_strategy: least-weighted
"targetallocator.yaml": `allocation_strategy: consistent-hashing
collector_selector:
matchlabels:
app.kubernetes.io/component: opentelemetry-collector
Expand Down Expand Up @@ -1766,7 +1766,7 @@ label_selector:
"app.kubernetes.io/version": "latest",
},
Annotations: map[string]string{
"opentelemetry-targetallocator-config/hash": "20c09760c240d08287ff05bd2375985220b577d938e82efd85467e17174690e0",
"opentelemetry-targetallocator-config/hash": "9126d0bb3bde858f655580a9ae6d4557c69ee430b4ab9f72e08c66334efe7989",
},
},
Spec: corev1.PodSpec{
Expand Down
2 changes: 1 addition & 1 deletion controllers/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
"app.kubernetes.io/part-of": "opentelemetry",
}
taConfig["config"] = promConfig["config"]
taConfig["allocation_strategy"] = "least-weighted"
taConfig["allocation_strategy"] = "consistent-hashing"
taConfig["prometheus_cr"] = map[string]string{
"scrape_interval": "30s",
}
Expand Down
3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18466,9 +18466,10 @@ TargetAllocator indicates a value which determines whether to spawn a target all
<td><b>allocationStrategy</b></td>
<td>enum</td>
<td>
AllocationStrategy determines which strategy the target allocator should use for allocation. The current options are least-weighted and consistent-hashing. The default option is least-weighted<br/>
AllocationStrategy determines which strategy the target allocator should use for allocation. The current options are least-weighted and consistent-hashing. The default option is consistent-hashing<br/>
<br/>
<i>Enum</i>: least-weighted, consistent-hashing<br/>
<i>Default</i>: consistent-hashing<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down
2 changes: 1 addition & 1 deletion internal/manifests/targetallocator/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
if len(params.OtelCol.Spec.TargetAllocator.AllocationStrategy) > 0 {
taConfig["allocation_strategy"] = params.OtelCol.Spec.TargetAllocator.AllocationStrategy
} else {
taConfig["allocation_strategy"] = v1alpha1.OpenTelemetryTargetAllocatorAllocationStrategyLeastWeighted
taConfig["allocation_strategy"] = v1alpha1.OpenTelemetryTargetAllocatorAllocationStrategyConsistentHashing
}

if len(params.OtelCol.Spec.TargetAllocator.FilterStrategy) > 0 {
Expand Down
6 changes: 3 additions & 3 deletions internal/manifests/targetallocator/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestDesiredConfigMap(t *testing.T) {
expectedLables["app.kubernetes.io/name"] = "my-instance-targetallocator"

expectedData := map[string]string{
"targetallocator.yaml": `allocation_strategy: least-weighted
"targetallocator.yaml": `allocation_strategy: consistent-hashing
collector_selector:
matchlabels:
app.kubernetes.io/component: opentelemetry-collector
Expand Down Expand Up @@ -81,7 +81,7 @@ label_selector:
expectedLables["app.kubernetes.io/name"] = "my-instance-targetallocator"

expectedData := map[string]string{
"targetallocator.yaml": `allocation_strategy: least-weighted
"targetallocator.yaml": `allocation_strategy: consistent-hashing
collector_selector:
matchlabels:
app.kubernetes.io/component: opentelemetry-collector
Expand Down Expand Up @@ -133,7 +133,7 @@ service_monitor_selector:
expectedLables["app.kubernetes.io/name"] = "my-instance-targetallocator"

expectedData := map[string]string{
"targetallocator.yaml": `allocation_strategy: least-weighted
"targetallocator.yaml": `allocation_strategy: consistent-hashing
collector_selector:
matchlabels:
app.kubernetes.io/component: opentelemetry-collector
Expand Down

0 comments on commit d7a0840

Please sign in to comment.