Skip to content

Commit 653945a

Browse files
committed
add env var and reuse processors
1 parent c93f677 commit 653945a

6 files changed

Lines changed: 23 additions & 79 deletions

File tree

charts/amazon-cloudwatch-observability/templates/linux/_otel-container-insights-logs-config.tpl

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ OTEL Container Insights LOGS-only otelConfig (hybrid model).
99
Metrics are generated by the agent from spec.config (JSON); this template supplies
1010
ONLY the CI log pipelines via spec.otelConfig. The agent merges the two at startup.
1111
12-
The shared enrichment processors `resourcedetection/opentelemetry`, `k8sattributes/opentelemetry`,
13-
and `transform/identity` are referenced here. The agent's metrics config
14-
(spec.config) supplies them at merge, giving multi-cloud detection + service/identity enrichment.
15-
The CI-specific `k8sattributes/cw_k8s_ci_v0_logs_{node,pod}` are "_logs"-suffixed so they don't
16-
collide with the agent's metrics-side copies during the merge.
12+
The enrichment processors are referenced here but NOT redefined. The agent's metrics
13+
config (spec.config) supplies them at merge. Only the logs-specific processors
14+
(scope, cluster/node, filelog, exporter/auth/batch) are defined.
1715
*/}}
1816
{{- define "otel-container-insights-logs.config" -}}
1917
extensions:
@@ -66,68 +64,6 @@ receivers:
6664
max_concurrent_files: 100
6765
6866
processors:
69-
k8sattributes/cw_k8s_ci_v0_logs_node:
70-
auth_type: serviceAccount
71-
passthrough: false
72-
exclude:
73-
pods: []
74-
filter:
75-
node_from_env_var: K8S_NODE_NAME
76-
extract:
77-
metadata:
78-
- k8s.node.name
79-
labels:
80-
- tag_name: "k8s.node.label.$$$1"
81-
key_regex: "(.*)"
82-
from: node
83-
pod_association:
84-
- sources:
85-
- from: resource_attribute
86-
name: k8s.node.name
87-
88-
k8sattributes/cw_k8s_ci_v0_logs_pod:
89-
auth_type: serviceAccount
90-
passthrough: false
91-
exclude:
92-
pods: []
93-
filter:
94-
node_from_env_var: K8S_NODE_NAME
95-
extract:
96-
annotations:
97-
- from: pod
98-
key: resource.opentelemetry.io/service.name
99-
tag_name: resource.opentelemetry.io/service.name
100-
- from: pod
101-
key: resource.opentelemetry.io/service.namespace
102-
tag_name: resource.opentelemetry.io/service.namespace
103-
- from: pod
104-
key: resource.opentelemetry.io/service.instance.id
105-
tag_name: resource.opentelemetry.io/service.instance.id
106-
- from: pod
107-
key: resource.opentelemetry.io/service.version
108-
tag_name: resource.opentelemetry.io/service.version
109-
metadata:
110-
- k8s.pod.uid
111-
- k8s.node.name
112-
- k8s.deployment.name
113-
- k8s.statefulset.name
114-
- k8s.daemonset.name
115-
- k8s.replicaset.name
116-
- k8s.job.name
117-
- k8s.cronjob.name
118-
- k8s.pod.start_time
119-
- k8s.container.name
120-
labels:
121-
- tag_name: "k8s.pod.label.$$$1"
122-
key_regex: "(.*)"
123-
from: pod
124-
pod_association:
125-
- sources:
126-
- from: resource_attribute
127-
name: k8s.pod.name
128-
- from: resource_attribute
129-
name: k8s.namespace.name
130-
13167
transform/cw_k8s_ci_v0_logs_set_cluster_and_node:
13268
error_mode: ignore
13369
log_statements:
@@ -207,8 +143,8 @@ service:
207143
processors:
208144
- transform/cw_k8s_ci_v0_logs_set_cluster_and_node
209145
- resourcedetection/opentelemetry
210-
- k8sattributes/cw_k8s_ci_v0_logs_node
211-
- k8sattributes/cw_k8s_ci_v0_logs_pod
146+
- k8sattributes/cw_k8s_ci_v0_node
147+
- k8sattributes/cw_k8s_ci_v0_pod
212148
- k8sattributes/opentelemetry
213149
- transform/identity
214150
- transform/cw_k8s_ci_v0_logs_set_scope_app
@@ -222,7 +158,7 @@ service:
222158
processors:
223159
- transform/cw_k8s_ci_v0_logs_set_cluster_and_node
224160
- resourcedetection/opentelemetry
225-
- k8sattributes/cw_k8s_ci_v0_logs_node
161+
- k8sattributes/cw_k8s_ci_v0_node
226162
- k8sattributes/opentelemetry
227163
- transform/identity
228164
- transform/cw_k8s_ci_v0_logs_set_scope_host

charts/amazon-cloudwatch-observability/tests/flag_matrix.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ OTEL_CI_CLUSTER='\"role\":\"cluster\"'
120120
# otelConfig (spec.otelConfig). The node JSON always sets logs.enabled:false; the
121121
# presence of CI logs is asserted via the logs exporter in the rendered otelConfig.
122122
OTEL_CI_LOGS_YAML_ON='cw_k8s_ci_v0_app_logs_dest'
123-
OTEL_CI_JSON_LOGS_OFF='\"logs\":{\"enabled\":false}'
123+
OTEL_CI_LOGS_JSON_OFF='\"logs\":{\"enabled\":false}'
124124
# aws-for-fluent-bit is the container image string — unique to the FluentBit
125125
# DaemonSet. Using this instead of bare "fluent-bit" avoids false matches in
126126
# OTEL config paths like /var/log/containers/fluent-bit* (which exist in the
@@ -160,12 +160,12 @@ run_case 4 false true true "ok" \
160160
# State #5: OTEL metrics only (logs disabled).
161161
run_case 5 true false false "ok" \
162162
"OTEL metrics only, no logs" \
163-
"$OTEL_CI_BOTH_ROLES,$OTEL_CI_JSON_LOGS_OFF" "$OTEL_CI_LOGS_YAML_ON,$FLUENT_BIT_IMAGE"
163+
"$OTEL_CI_BOTH_ROLES,$OTEL_CI_LOGS_JSON_OFF" "$OTEL_CI_LOGS_YAML_ON,$FLUENT_BIT_IMAGE"
164164

165165
# State #6: hybrid — OTEL metrics + FluentBit logs.
166166
run_case 6 true false true "ok" \
167167
"Hybrid — OTEL metrics + FluentBit logs" \
168-
"$OTEL_CI_BOTH_ROLES,$OTEL_CI_JSON_LOGS_OFF,$FLUENT_BIT_IMAGE" "$OTEL_CI_LOGS_YAML_ON"
168+
"$OTEL_CI_BOTH_ROLES,$OTEL_CI_LOGS_JSON_OFF,$FLUENT_BIT_IMAGE" "$OTEL_CI_LOGS_YAML_ON"
169169

170170
# State #7: full OTEL (metrics + logs, no FluentBit).
171171
run_case 7 true true false "ok" \

charts/amazon-cloudwatch-observability/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,10 @@ agents:
720720
- name: cloudwatch-agent-cluster-scraper
721721
mode: deployment
722722
config: "default" # the reserved string "default" indicates building the default config dynamically
723+
# if a customer json config role is empty, CWAGENT_ROLE=LEADER keeps this agent resolving to the "cluster" role.
724+
env:
725+
- name: CWAGENT_ROLE
726+
value: LEADER
723727
agent:
724728
name:
725729
mode: daemonset # Represents the mode the AmazonCloudWatchAgent workload will run in (deployment, daemonset or statefulset)

integration-tests/amazon-cloudwatch-observability/validations/minikube/scenarios/agent_config_merge_isolation_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ func TestAgentConfigMergeIsolation(t *testing.T) {
110110

111111
mode, _ := spec["mode"].(string)
112112
assert.Equal(t, "deployment", mode, "cluster-scraper should be in deployment mode")
113+
114+
// Fallback env: guarantees the scraper resolves to the cluster role even if a
115+
// custom config omits role (JSON role: cluster wins by default; env is the safety net).
116+
assertEnvValue(t, spec, "CWAGENT_ROLE", "LEADER")
113117
})
114118

115119
t.Log("Agent config merge isolation validation passed")

integration-tests/amazon-cloudwatch-observability/validations/minikube/scenarios/otlp_hybrid_metrics_fluentbit_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func TestOTLPHybridMetricsFluentBit(t *testing.T) {
7878

7979
// OTEL CI enabled (node role), logs off (FluentBit handles logs).
8080
minikube.AssertOtelContainerInsights(t, config, "node")
81-
// Hybrid + logs off: otelConfig is absent, so no CI logs pipeline expected.
82-
otelConfig, _ := spec["otelConfig"].(string)
83-
minikube.AssertOtelCILogs(t, otelConfig, false)
81+
// Hybrid + logs off: no CI logs otelConfig should be emitted.
82+
_, hasOtelConfig := spec["otelConfig"].(string)
83+
assert.False(t, hasOtelConfig, "otelConfig should be absent when CI logs are disabled")
8484

8585
// CWA DaemonSet must not have log-related host mounts.
8686
assertNoLogMounts(t, k8sClient, "cloudwatch-agent")

integration-tests/amazon-cloudwatch-observability/validations/minikube/scenarios/otlp_logs_disabled_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ func TestOTLPLogsDisabled(t *testing.T) {
8383

8484
// Metrics pipeline present (node role); logs disabled.
8585
minikube.AssertOtelContainerInsights(t, config, "node")
86-
// Hybrid + logs off: otelConfig is absent, so no CI logs pipeline expected.
87-
otelConfig, _ := spec["otelConfig"].(string)
88-
minikube.AssertOtelCILogs(t, otelConfig, false)
86+
// Hybrid + logs off: no CI logs otelConfig should be emitted.
87+
_, hasOtelConfig := spec["otelConfig"].(string)
88+
assert.False(t, hasOtelConfig, "otelConfig should be absent when CI logs are disabled")
8989

9090
// CWA DaemonSet must not have log-related host mounts.
9191
assertNoLogMounts(t, k8sClient, "cloudwatch-agent")

0 commit comments

Comments
 (0)