Skip to content

Commit 3638862

Browse files
Merge helm-flag-restructure (aws-observability#332) into helm-annotation-scraper-routing
Propagates the both-false prometheusScrape validation (reject scrape.enabled with no monitors). # Conflicts: # charts/amazon-cloudwatch-observability/tests/prometheus_crds_matrix.sh
2 parents fe0bf16 + e032f1a commit 3638862

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

charts/amazon-cloudwatch-observability/templates/_helpers.tpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ otelContainerInsights.serviceMonitor.enabled / .podMonitor.enabled if set
256256
{{- if $v -}}true{{- end -}}
257257
{{- end -}}
258258

259+
{{/*
260+
Reject a contradictory scraping config. prometheusScrape.enabled=true with BOTH
261+
ServiceMonitor and PodMonitor discovery disabled would render an idle Target Allocator
262+
(and bundle CRDs) that discovers nothing. Fail loudly rather than ship a no-op path.
263+
Invoked from an always-rendered template so it runs regardless of which agents render.
264+
*/}}
265+
{{- define "cloudwatch-agent.validatePrometheusScrape" -}}
266+
{{- if and .Values.otelContainerInsights.enabled (dig "prometheusScrape" "enabled" true .Values.otelContainerInsights) -}}
267+
{{- if and (ne (include "cloudwatch-agent.serviceMonitorEnabled" .) "true") (ne (include "cloudwatch-agent.podMonitorEnabled" .) "true") -}}
268+
{{- fail "otelContainerInsights.prometheusScrape.enabled=true requires at least one of prometheusScrape.serviceMonitor.enabled or prometheusScrape.podMonitor.enabled to be true; enable one, or set prometheusScrape.enabled=false" -}}
269+
{{- end -}}
270+
{{- end -}}
271+
{{- end -}}
272+
259273
{{/*
260274
Helper function to modify cloudwatch-agent config
261275
*/}}

charts/amazon-cloudwatch-observability/templates/linux/cloudwatch-agent-custom-resource.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{- if .Values.agent.enabled }}
2+
{{- include "cloudwatch-agent.validatePrometheusScrape" . -}}
23
{{- if and (.Values.agent.autoGenerateCert.enabled) (not .Values.agent.certManager.enabled) -}}
34
{{- $altNames := list ( printf "%s-service" (include "dcgm-exporter.name" .) ) ( printf "%s-service" (include "neuron-monitor.name" .) ) ( printf "%s-service.%s.svc" (include "dcgm-exporter.name" .) .Release.Namespace ) ( printf "%s-service.%s.svc" (include "neuron-monitor.name" .) .Release.Namespace ) ( printf "%s-service" (include "node-exporter.name" .) ) ( printf "%s-service.%s.svc" (include "node-exporter.name" .) .Release.Namespace ) ( include "kube-state-metrics.name" . ) ( printf "%s.%s.svc" (include "kube-state-metrics.name" .) .Release.Namespace ) -}}
45
{{- range $i, $customAgent := .Values.agents }}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ expect_count() {
5353
fi
5454
}
5555

56+
# expect_fail <desc> <pattern> <render-args...> -- expects helm to error with output matching <pattern>
57+
expect_fail() {
58+
local desc="$1" pattern="$2"; shift 2
59+
local out
60+
if out="$(render "$@")"; then
61+
printf "${R}FAIL${N} %s (expected helm error, render succeeded) [%s]\n" "$desc" "$*"
62+
fail_count=$((fail_count+1)); return
63+
fi
64+
if printf '%s\n' "$out" | grep -qE "$pattern"; then
65+
printf "${G}PASS${N} %s (rejected as expected)\n" "$desc"
66+
pass_count=$((pass_count+1))
67+
else
68+
printf "${R}FAIL${N} %s (errored but message missing /%s/) [%s]\n" "$desc" "$pattern" "$*"
69+
fail_count=$((fail_count+1))
70+
fi
71+
}
72+
5673
printf "${Y}== CRD bundling gating ==${N}\n"
5774
# auto (default): bundle only when otelContainerInsights.enabled (and prometheusScrape enabled).
5875
expect_count "auto + otelCI on => ServiceMonitor CRD bundled" "$SM_CRD" 1 --set otelContainerInsights.enabled=true
@@ -85,6 +102,14 @@ expect_count "TA rendered on both agents when otelCI on" 'targetAlloca
85102
expect_count "prometheusCR rendered on both agents when otelCI on" 'prometheusCR:' 2 --set otelContainerInsights.enabled=true
86103
expect_count "TA absent when scrape off" 'targetAllocator:' 0 --set otelContainerInsights.enabled=true --set otelContainerInsights.prometheusScrape.enabled=false
87104

105+
printf "\n${Y}== both monitors disabled => rejected ==${N}\n"
106+
# prometheusScrape.enabled=true with both monitor types off is contradictory (idle TA,
107+
# bundled CRDs, nothing discovered) and must fail rather than render a no-op path.
108+
expect_fail "scrape on + both monitors off => render fails" 'requires at least one of' \
109+
--set otelContainerInsights.enabled=true \
110+
--set otelContainerInsights.prometheusScrape.serviceMonitor.enabled=false \
111+
--set otelContainerInsights.prometheusScrape.podMonitor.enabled=false
112+
88113
printf "\n${Y}== Monitor routing (scraperRole + cloudwatch.aws/scraper annotation) ==${N}\n"
89114
# Routing is annotation-based at runtime; the chart only sets scraperRole on the cluster-scraper CR.
90115
# The per-node agent gets no scraperRole (default role). Runtime annotation filtering is covered by

0 commit comments

Comments
 (0)