-
Notifications
You must be signed in to change notification settings - Fork 28
Target allocator #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Target allocator #261
Changes from 19 commits
59fb829
bea6ed2
0dce7f2
b3cf3cf
2dc2f2b
bfb6b3a
b74b110
313843f
95f77b0
a877192
64e55f3
31db083
7ae202e
f82db5a
310ba61
b683196
b5428a3
b551012
50e29f0
57c0f4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package v1alpha1 | ||
|
||
type ( | ||
// AmazonCloudWatchAgentTargetAllocatorAllocationStrategy represent which strategy to distribute target to each collector | ||
// +kubebuilder:validation:Enum=consistent-hashing | ||
AmazonCloudWatchAgentTargetAllocatorAllocationStrategy string | ||
) | ||
|
||
const ( | ||
// AmazonCloudWatchAgentTargetAllocatorAllocationStrategyConsistentHashing targets will be consistently added to collectors, which allows a high-availability setup. | ||
AmazonCloudWatchAgentTargetAllocatorAllocationStrategyConsistentHashing AmazonCloudWatchAgentTargetAllocatorAllocationStrategy = "consistent-hashing" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ import ( | |
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
|
||
"github.com/aws/amazon-cloudwatch-agent-operator/internal/config" | ||
"github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/collector/adapters" | ||
ta "github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/targetallocator/adapters" | ||
"github.com/aws/amazon-cloudwatch-agent-operator/pkg/featuregate" | ||
) | ||
|
||
var ( | ||
|
@@ -87,6 +90,9 @@ func (c CollectorWebhook) defaulter(r *AmazonCloudWatchAgent) error { | |
if r.Spec.Replicas == nil { | ||
r.Spec.Replicas = &one | ||
} | ||
if r.Spec.TargetAllocator.Enabled && r.Spec.TargetAllocator.Replicas == nil { | ||
r.Spec.TargetAllocator.Replicas = &one | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if this needs to be documented or made configurable later ? This means TA is not scalable at the moment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think this can be an enhancement. |
||
} | ||
|
||
if r.Spec.MaxReplicas != nil || (r.Spec.Autoscaler != nil && r.Spec.Autoscaler.MaxReplicas != nil) { | ||
if r.Spec.Autoscaler == nil { | ||
|
@@ -163,6 +169,32 @@ func (c CollectorWebhook) validate(r *AmazonCloudWatchAgent) (admission.Warnings | |
return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'AdditionalContainers'", r.Spec.Mode) | ||
} | ||
|
||
// validate target allocation | ||
if r.Spec.TargetAllocator.Enabled && r.Spec.Mode != ModeStatefulSet { | ||
warnings = append(warnings, fmt.Sprintf("The Amazon CloudWatch Agent mode is set to %s, we do not recommend enabling Target Allocator when not running as a StatefulSet", r.Spec.Mode)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could be updated with The mode could be Deployment and the error message would say StatefulSet which can be confusing |
||
} | ||
|
||
// validate Prometheus config for target allocation | ||
if r.Spec.TargetAllocator.Enabled { | ||
promConfigYaml, err := r.Spec.Prometheus.Yaml() | ||
if err != nil { | ||
return warnings, fmt.Errorf("%s could not convert json to yaml", err) | ||
} | ||
|
||
promCfg, err := adapters.ConfigFromString(promConfigYaml) | ||
if err != nil { | ||
return warnings, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err) | ||
} | ||
err = ta.ValidatePromConfig(promCfg, r.Spec.TargetAllocator.Enabled, featuregate.EnableTargetAllocatorRewrite.IsEnabled()) | ||
okankoAMZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return warnings, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err) | ||
} | ||
err = ta.ValidateTargetAllocatorConfig(r.Spec.TargetAllocator.PrometheusCR.Enabled, promCfg) | ||
if err != nil { | ||
return warnings, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err) | ||
} | ||
} | ||
|
||
// validator port config | ||
for _, p := range r.Spec.Ports { | ||
nameErrs := validation.IsValidPortName(p.Name) | ||
|
Uh oh!
There was an error while loading. Please reload this page.