Skip to content

Commit cf01423

Browse files
okankoAMZmusa-asadmitali-salviItielOlenicksky333999
authored
Target allocator (#261)
* Implemented Target Allocator Container (#214) * Merge `main` into `target-allocator` (#232) NodeJS merging-in from main * Supporting K8s 1.31 (#222) (#236) Co-authored-by: Mitali Salvi <[email protected]> * Implemented TargetAllocator resource deployments. (#208) * Adding target-allocator label to service selectors (#242) * Target allocator TLS Implementation (#239) * Ta https server (#2921) * Added https server, tests, secret marshalling --------- Co-authored-by: ItielOlenick <[email protected]> * [Target Allocator] Enable Deployment and Daemonset modes for Agent (#253) * Changes error to warning * [CI/CD] Add Target Allocator(TA) Build to Build and Upload Workflow (#247) * edited workflow * Clean up managed resources when disabled (#255) * Reconciler now removes un-used managed resources for CWA collector * remove pprof endpoint (#260) * [TA] One service per Target Allocator (#259) * added one-service per TA * Setup cert-watcher for TA server cert (#264) * [TA] Target Allocator TLS Unit-tests (#265) * TLS tests * Injecting Prometheus path if not specified in agent config (#258) * Injecting Prom path if it doesn't exist * Rebasing Target Allocator Branch to Main (#266) * Adding support for NodeJS auto instrumentation and integ tests (#220) * Support configurable resources for NodeJS. (#225) * Supporting JMX annotations (#240) * Add support for a supplemental YAML configuration for the CloudWatchAgent (#241) * Changed naming for OTLP container ports from agent JSON (#252) * Updated Release Notes for 1.8.0 (#251) * Adjust EKS add-on integration test service count expectations (#256) * Add integration tests for JMX. (#250) * Implemented Target Allocator Container (#214) * Implemented TargetAllocator resource deployments. (#208) * Update cmd/amazon-cloudwatch-agent-target-allocator/config/config.go Co-authored-by: Musa <[email protected]> * Update internal/config/main.go Co-authored-by: Musa <[email protected]> --------- Co-authored-by: Parampreet Singh <[email protected]> Co-authored-by: Musa <[email protected]> Co-authored-by: Mitali Salvi <[email protected]> Co-authored-by: Jeffrey Chien <[email protected]> --------- Co-authored-by: Musa <[email protected]> Co-authored-by: Mitali Salvi <[email protected]> Co-authored-by: ItielOlenick <[email protected]> Co-authored-by: Kaushik Surya <[email protected]> Co-authored-by: Parampreet Singh <[email protected]> Co-authored-by: Jeffrey Chien <[email protected]>
1 parent 8e78c01 commit cf01423

File tree

111 files changed

+12117
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+12117
-164
lines changed

.github/workflows/build-and-upload-release.yml

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ env:
66
# Use terraform assume role for uploading to ecr
77
AWS_ASSUME_ROLE: ${{ secrets.TERRAFORM_AWS_ASSUME_ROLE }}
88
ECR_OPERATOR_STAGING_REPO: ${{ vars.ECR_OPERATOR_STAGING_REPO }}
9-
ECR_OPERATOR_RELEASE_IMAGE: ${{ secrets.ECR_OPERATOR_RELEASE_IMAGE }}
9+
ECR_TARGET_ALLOCATOR_STAGING_REPO: ${{ vars.ECR_TARGET_ALLOCATOR_STAGING_REPO}}
10+
ECR_OPERATOR_RELEASE_IMAGE: ${{ vars.ECR_TARGET_ALLOCATOR_TEST_OPERATOR_REPO}}
11+
ECR_TARGET_ALLOCATOR_RELEASE_REPO: ${{ vars.ECR_TARGET_ALLOCATOR_RELEASE_REPO}}
1012

1113
on:
1214
workflow_dispatch:
@@ -81,9 +83,60 @@ jobs:
8183
tags: ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}
8284
platforms: linux/amd64, linux/arm64
8385

86+
MakeTABinary:
87+
name: 'MakeTargetAllocatorImage'
88+
runs-on: ubuntu-latest
89+
permissions:
90+
id-token: write
91+
contents: read
92+
steps:
93+
- uses: actions/checkout@v3
94+
with:
95+
fetch-depth: 0
96+
97+
- name: Set up Go 1.x
98+
uses: actions/setup-go@v4
99+
with:
100+
go-version: '>1.22'
101+
cache: true
102+
103+
- name: Configure AWS Credentials
104+
uses: aws-actions/configure-aws-credentials@v2
105+
with:
106+
role-to-assume: ${{ env.AWS_ASSUME_ROLE }}
107+
aws-region: us-west-2
108+
109+
- name: Login to ECR
110+
if: steps.cached_binaries.outputs.cache-hit == false
111+
id: login-ecr
112+
uses: aws-actions/amazon-ecr-login@v1
113+
114+
- name: Set up Docker Buildx
115+
if: steps.cached_binaries.outputs.cache-hit == false
116+
uses: docker/setup-buildx-action@v1
117+
118+
- name: Set up QEMU
119+
if: steps.cached_binaries.outputs.cache-hit == false
120+
uses: docker/setup-qemu-action@v1
121+
122+
- name: Build Binaries
123+
run: |
124+
go mod download
125+
export GOARCH=arm64 && make targetallocator
126+
export GOARCH=amd64 && make targetallocator
127+
- name: Build Cloudwatch Agent Target Allocator Image and push to ECR
128+
uses: docker/build-push-action@v4
129+
if: steps.cached_binaries.outputs.cache-hit == false
130+
with:
131+
file: ./cmd/amazon-cloudwatch-agent-target-allocator/Dockerfile
132+
context: ./cmd/amazon-cloudwatch-agent-target-allocator
133+
push: true
134+
tags: ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}
135+
platforms: linux/amd64, linux/arm64
136+
84137
e2e-test:
85138
name: "Application Signals E2E Test"
86-
needs: MakeBinary
139+
needs: [MakeBinary]
87140
uses: ./.github/workflows/application-signals-e2e-test.yml
88141
secrets: inherit
89142
permissions:
@@ -119,4 +172,10 @@ jobs:
119172
run: |
120173
docker buildx imagetools create \
121174
-t ${{ env.ECR_OPERATOR_RELEASE_IMAGE }} \
122-
${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}
175+
${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}
176+
177+
- name: Push image to TA release ECR
178+
run: |
179+
docker buildx imagetools create \
180+
-t ${{ env.ECR_TARGET_ALLOCATOR_RELEASE_REPO}} \
181+
${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.20 as builder
2+
FROM golang:1.21 as builder
33

44
# set goproxy=direct
55
ENV GOPROXY direct
@@ -30,9 +30,10 @@ ARG AUTO_INSTRUMENTATION_DOTNET_VERSION
3030
ARG AUTO_INSTRUMENTATION_NODEJS_VERSION
3131
ARG DCMG_EXPORTER_VERSION
3232
ARG NEURON_MONITOR_VERSION
33+
ARG TARGET_ALLOCATOR_VERSION
3334

3435
# Build
35-
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.agent=${AGENT_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.dcgmExporter=${DCMG_EXPORTER_VERSION} -X ${VERSION_PKG}.neuronMonitor=${NEURON_MONITOR_VERSION}" -a -o manager main.go
36+
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.agent=${AGENT_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.dcgmExporter=${DCMG_EXPORTER_VERSION} -X ${VERSION_PKG}.neuronMonitor=${NEURON_MONITOR_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGET_ALLOCATOR_VERSION}" -a -o manager main.go
3637

3738
# Use distroless as minimal base image to package the manager binary
3839
# Refer to https://github.com/GoogleContainerTools/distroless for more details
@@ -41,4 +42,4 @@ WORKDIR /
4142
COPY --from=builder /workspace/manager .
4243
USER 65532:65532
4344

44-
ENTRYPOINT ["/manager"]
45+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ AUTO_INSTRUMENTATION_DOTNET_VERSION ?= "$(shell grep -v '\#' versions.txt | grep
99
AUTO_INSTRUMENTATION_NODEJS_VERSION ?= "$(shell grep -v '\#' versions.txt | grep aws-otel-nodejs-instrumentation | awk -F= '{print $$2}')"
1010
DCGM_EXPORTER_VERSION ?= "$(shell grep -v '\#' versions.txt | grep dcgm-exporter | awk -F= '{print $$2}')"
1111
NEURON_MONITOR_VERSION ?= "$(shell grep -v '\#' versions.txt | grep neuron-monitor | awk -F= '{print $$2}')"
12+
TARGET_ALLOCATOR_VERSION ?= "$(shell grep -v '\#' versions.txt | grep target-allocator | awk -F= '{print $$2}')"
1213

1314
# Image URL to use all building/pushing image targets
1415
IMG_PREFIX ?= aws
1516
IMG_REPO ?= cloudwatch-agent-operator
1617
IMG ?= ${IMG_PREFIX}/${IMG_REPO}:${VERSION}
1718
ARCH ?= $(shell go env GOARCH)
1819

20+
TARGET_ALLOCATOR_IMG_REPO ?= target-allocator
21+
TARGET_ALLOCATOR_IMG ?= ${IMG_PREFIX}/${TARGET_ALLOCATOR_IMG_REPO}:${TARGET_ALLOCATOR_VERSION}
22+
1923
# Options for 'bundle-build'
2024
ifneq ($(origin CHANNELS), undefined)
2125
BUNDLE_CHANNELS := --channels=$(CHANNELS)
@@ -96,6 +100,10 @@ test: generate fmt vet envtest
96100
.PHONY: manager
97101
manager: generate fmt vet
98102
go build -o bin/manager main.go
103+
# Build target allocator binary
104+
.PHONY: targetallocator
105+
targetallocator:
106+
cd cmd/amazon-cloudwatch-agent-target-allocator && CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -installsuffix cgo -o bin/targetallocator_${ARCH} -ldflags "${LDFLAGS}" .
99107

100108
# Run against the configured Kubernetes cluster in ~/.kube/config
101109
.PHONY: run
@@ -155,13 +163,26 @@ generate: controller-gen api-docs
155163
# buildx is used to ensure same results for arm based systems (m1/2 chips)
156164
.PHONY: container
157165
container:
158-
docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg AGENT_VERSION=${AGENT_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg DCGM_EXPORTER_VERSION=${DCGM_EXPORTER_VERSION} --build-arg NEURON_MONITOR_VERSION=${NEURON_MONITOR_VERSION} .
166+
docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg AGENT_VERSION=${AGENT_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg DCGM_EXPORTER_VERSION=${DCGM_EXPORTER_VERSION} --build-arg NEURON_MONITOR_VERSION=${NEURON_MONITOR_VERSION} --build-arg TARGET_ALLOCATOR_VERSION=${TARGET_ALLOCATOR_VERSION} .
159167

160168
# Push the container image, used only for local dev purposes
161169
.PHONY: container-push
162170
container-push:
163171
docker push ${IMG}
164172

173+
.PHONY: container-target-allocator-push
174+
container-target-allocator-push:
175+
docker push ${TARGET_ALLOCATOR_IMG}
176+
177+
.PHONY: container-target-allocator
178+
container-target-allocator: GOOS = linux
179+
container-target-allocator: targetallocator
180+
docker buildx build --load --platform linux/${ARCH} -t ${TARGET_ALLOCATOR_IMG} cmd/amazon-cloudwatch-agent-target-allocator
181+
182+
.PHONY: ta-build-and-push
183+
ta-build-and-push: container-target-allocator
184+
ta-build-and-push: container-target-allocator-push
185+
165186
.PHONY: kustomize
166187
kustomize: ## Download kustomize locally if necessary.
167188
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
type (
7+
// AmazonCloudWatchAgentTargetAllocatorAllocationStrategy represent which strategy to distribute target to each collector
8+
// +kubebuilder:validation:Enum=consistent-hashing
9+
AmazonCloudWatchAgentTargetAllocatorAllocationStrategy string
10+
)
11+
12+
const (
13+
// AmazonCloudWatchAgentTargetAllocatorAllocationStrategyConsistentHashing targets will be consistently added to collectors, which allows a high-availability setup.
14+
AmazonCloudWatchAgentTargetAllocatorAllocationStrategyConsistentHashing AmazonCloudWatchAgentTargetAllocatorAllocationStrategy = "consistent-hashing"
15+
)

apis/v1alpha1/amazoncloudwatchagent_types.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ type AmazonCloudWatchAgentSpec struct {
143143
// Collector and Target Allocator pods.
144144
// +optional
145145
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
146+
// TargetAllocator indicates a value which determines whether to spawn a target allocation resource or not.
147+
// +optional
148+
TargetAllocator AmazonCloudWatchAgentTargetAllocator `json:"targetAllocator,omitempty"`
146149
// Mode represents how the collector should be deployed (deployment, daemonset, statefulset or sidecar)
147150
// +optional
148151
Mode Mode `json:"mode,omitempty"`
@@ -164,6 +167,9 @@ type AmazonCloudWatchAgentSpec struct {
164167
// ImagePullPolicy indicates the pull policy to be used for retrieving the container image (Always, Never, IfNotPresent)
165168
// +optional
166169
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
170+
// Prometheus is the raw YAML to be used as the collector's prometheus configuration.
171+
// +optional
172+
Prometheus PrometheusConfig `json:"prometheus,omitempty"`
167173
// Config is the raw JSON to be used as the collector's configuration. Refer to the OpenTelemetry Collector documentation for details.
168174
// +required
169175
Config string `json:"config,omitempty"`
@@ -276,6 +282,87 @@ type AmazonCloudWatchAgentSpec struct {
276282
UpdateStrategy appsv1.DaemonSetUpdateStrategy `json:"updateStrategy,omitempty"`
277283
}
278284

285+
// AmazonCloudWatchAgentTargetAllocator defines the configurations for the Prometheus target allocator.
286+
type AmazonCloudWatchAgentTargetAllocator struct {
287+
// Replicas is the number of pod instances for the underlying TargetAllocator. This should only be set to a value
288+
// other than 1 if a strategy that allows for high availability is chosen. Currently, the only allocation strategy
289+
// that can be run in a high availability mode is consistent-hashing.
290+
// +optional
291+
Replicas *int32 `json:"replicas,omitempty"`
292+
// NodeSelector to schedule OpenTelemetry TargetAllocator pods.
293+
// +optional
294+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
295+
// Resources to set on the OpenTelemetryTargetAllocator containers.
296+
// +optional
297+
Resources v1.ResourceRequirements `json:"resources,omitempty"`
298+
// AllocationStrategy determines which strategy the target allocator should use for allocation.
299+
// The current option is consistent-hashing.
300+
// +optional
301+
AllocationStrategy AmazonCloudWatchAgentTargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"`
302+
// FilterStrategy determines how to filter targets before allocating them among the collectors.
303+
// The only current option is relabel-config (drops targets based on prom relabel_config).
304+
// Filtering is disabled by default.
305+
// +optional
306+
FilterStrategy string `json:"filterStrategy,omitempty"`
307+
// ServiceAccount indicates the name of an existing service account to use with this instance. When set,
308+
// the operator will not automatically create a ServiceAccount for the TargetAllocator.
309+
// +optional
310+
ServiceAccount string `json:"serviceAccount,omitempty"`
311+
// Image indicates the container image to use for the OpenTelemetry TargetAllocator.
312+
// +optional
313+
Image string `json:"image,omitempty"`
314+
// Enabled indicates whether to use a target allocation mechanism for Prometheus targets or not.
315+
// +optional
316+
Enabled bool `json:"enabled,omitempty"`
317+
// If specified, indicates the pod's scheduling constraints
318+
// +optional
319+
Affinity *v1.Affinity `json:"affinity,omitempty"`
320+
// PrometheusCR defines the configuration for the retrieval of PrometheusOperator CRDs ( servicemonitor.monitoring.coreos.com/v1 and podmonitor.monitoring.coreos.com/v1 ) retrieval.
321+
// All CR instances which the ServiceAccount has access to will be retrieved. This includes other namespaces.
322+
// +optional
323+
PrometheusCR AmazonCloudWatchAgentTargetAllocatorPrometheusCR `json:"prometheusCR,omitempty"`
324+
// SecurityContext configures the container security context for
325+
// the target-allocator.
326+
// +optional
327+
SecurityContext *v1.PodSecurityContext `json:"securityContext,omitempty"`
328+
// TopologySpreadConstraints embedded kubernetes pod configuration option,
329+
// controls how pods are spread across your cluster among failure-domains
330+
// such as regions, zones, nodes, and other user-defined topology domains
331+
// https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
332+
// +optional
333+
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
334+
// Toleration embedded kubernetes pod configuration option,
335+
// controls how pods can be scheduled with matching taints
336+
// +optional
337+
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
338+
// ENV vars to set on the OpenTelemetry TargetAllocator's Pods. These can then in certain cases be
339+
// consumed in the config file for the TargetAllocator.
340+
// +optional
341+
Env []v1.EnvVar `json:"env,omitempty"`
342+
}
343+
344+
type AmazonCloudWatchAgentTargetAllocatorPrometheusCR struct {
345+
// Enabled indicates whether to use a PrometheusOperator custom resources as targets or not.
346+
// +optional
347+
Enabled bool `json:"enabled,omitempty"`
348+
// Interval between consecutive scrapes. Equivalent to the same setting on the Prometheus CRD.
349+
//
350+
// Default: "30s"
351+
// +kubebuilder:default:="30s"
352+
// +kubebuilder:validation:Format:=duration
353+
ScrapeInterval *metav1.Duration `json:"scrapeInterval,omitempty"`
354+
// PodMonitors to be selected for target discovery.
355+
// This is a map of {key,value} pairs. Each {key,value} in the map is going to exactly match a label in a
356+
// PodMonitor's meta labels. The requirements are ANDed.
357+
// +optional
358+
PodMonitorSelector map[string]string `json:"podMonitorSelector,omitempty"`
359+
// ServiceMonitors to be selected for target discovery.
360+
// This is a map of {key,value} pairs. Each {key,value} in the map is going to exactly match a label in a
361+
// ServiceMonitor's meta labels. The requirements are ANDed.
362+
// +optional
363+
ServiceMonitorSelector map[string]string `json:"serviceMonitorSelector,omitempty"`
364+
}
365+
279366
// ScaleSubresourceStatus defines the observed state of the AmazonCloudWatchAgent's
280367
// scale subresource.
281368
type ScaleSubresourceStatus struct {

apis/v1alpha1/collector_webhook.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1717

1818
"github.com/aws/amazon-cloudwatch-agent-operator/internal/config"
19+
"github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/collector/adapters"
20+
ta "github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/targetallocator/adapters"
21+
"github.com/aws/amazon-cloudwatch-agent-operator/pkg/featuregate"
1922
)
2023

2124
var (
@@ -87,6 +90,9 @@ func (c CollectorWebhook) defaulter(r *AmazonCloudWatchAgent) error {
8790
if r.Spec.Replicas == nil {
8891
r.Spec.Replicas = &one
8992
}
93+
if r.Spec.TargetAllocator.Enabled && r.Spec.TargetAllocator.Replicas == nil {
94+
r.Spec.TargetAllocator.Replicas = &one
95+
}
9096

9197
if r.Spec.MaxReplicas != nil || (r.Spec.Autoscaler != nil && r.Spec.Autoscaler.MaxReplicas != nil) {
9298
if r.Spec.Autoscaler == nil {
@@ -163,6 +169,32 @@ func (c CollectorWebhook) validate(r *AmazonCloudWatchAgent) (admission.Warnings
163169
return warnings, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the attribute 'AdditionalContainers'", r.Spec.Mode)
164170
}
165171

172+
// validate target allocation
173+
if r.Spec.TargetAllocator.Enabled && r.Spec.Mode != ModeStatefulSet {
174+
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))
175+
}
176+
177+
// validate Prometheus config for target allocation
178+
if r.Spec.TargetAllocator.Enabled {
179+
promConfigYaml, err := r.Spec.Prometheus.Yaml()
180+
if err != nil {
181+
return warnings, fmt.Errorf("%s could not convert json to yaml", err)
182+
}
183+
184+
promCfg, err := adapters.ConfigFromString(promConfigYaml)
185+
if err != nil {
186+
return warnings, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err)
187+
}
188+
err = ta.ValidatePromConfig(promCfg, r.Spec.TargetAllocator.Enabled, featuregate.EnableTargetAllocatorRewrite.IsEnabled())
189+
if err != nil {
190+
return warnings, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err)
191+
}
192+
err = ta.ValidateTargetAllocatorConfig(r.Spec.TargetAllocator.PrometheusCR.Enabled, promCfg)
193+
if err != nil {
194+
return warnings, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err)
195+
}
196+
}
197+
166198
// validator port config
167199
for _, p := range r.Spec.Ports {
168200
nameErrs := validation.IsValidPortName(p.Name)

0 commit comments

Comments
 (0)