Skip to content

[amazon-cloudwatch-observability] refactor: single-switch SM/PM scraping under otelContainerInsights.prometheusScrape - #332

Open
wenegiemepraise wants to merge 1 commit into
aws-observability:mainfrom
wenegiemepraise:helm-flag-restructure
Open

wenegiemepraise wants to merge 1 commit into
aws-observability:mainfrom
wenegiemepraise:helm-flag-restructure

Conversation

@wenegiemepraise

Copy link
Copy Markdown

Summary

Collapse the SM/PM scraping enablement into a single switch. Previously, turning on the
feature spanned several interacting flags (prometheusCRDs.install,
otelContainerInsights.serviceMonitor/podMonitor.enabled, deep
agent.prometheus.targetAllocator.*). This consolidates them under one nested bundle:

otelContainerInsights:
  enabled: true                 # the one switch: CRDs + Target Allocator + prometheusCR + RBAC
  prometheusScrape:
    enabled: true               # single opt-out: false => OTEL CI without SM/PM scraping
    allocationStrategy: per-node
    crds:
      install: auto             # auto|always|never
    serviceMonitor: { enabled: true }
    podMonitor:     { enabled: true }

otelContainerInsights.enabled: true now makes SM/PM scraping work end to end; a single
prometheusScrape.enabled: false opts out while keeping the rest of OTEL Container Insights.

Notes for reviewers

  • API/UX change. These keys never shipped in a released chart version, so there's no
    external contract to preserve — the old prometheusCRDs / otelContainerInsights. serviceMonitor|podMonitor top-level keys are moved, not aliased.
  • Gating helpers in _helpers.tpl (otelCIScrapeEnabled, prometheusCRDsEnabled) now read
    from the prometheusScrape bundle.

Dependencies

Top of the helm stack — refactors keys introduced by #329 (v2 OTLP path), #330
(per-node) and #331 (CRD bundling). Merge those first; this PR's diff includes them until
they land.

Testing

helm template:

  • otelContainerInsights.enabled=true → CRDs render (2), prometheuscr path renders,
    allocationStrategy: "per-node".
  • + prometheusScrape.enabled=false → prometheuscr and bundled CRDs both drop to 0
    (scraping off, rest of CI intact).

helm lint clean (pre-existing fluent-bit-windows region warning is unrelated).

- "--auto-instrumentation-nodejs-image={{ template "auto-instrumentation-nodejs.image" . }}"
- "--target-allocator-image={{ template "target-allocator.image" (merge .Values.agent.prometheus.targetAllocator.image (dict "region" $.Values.region)) }}"
- "--feature-gates=operator.autoinstrumentation.multiinstrumentation,operator.autoinstrumentation.multiinstrumentation.skipcontainervalidation"
- "--feature-gates=operator.autoinstrumentation.multi-instrumentation,operator.autoinstrumentation.multi-instrumentation.skip-container-validation"

@musa-asad musa-asad Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same --feature-gates issue as #329: hyphenated multi-instrumentation IDs the pinned operator doesn't register, so it CrashLoopBackOffs. Could we fix it in #329 and rebase?

## Allocator's prometheusCR discovery. When otelContainerInsights.enabled is true,
## enabling this gives SM/PM scraping end-to-end (CRDs + Target Allocator +
## prometheusCR + RBAC). Only takes effect when otelContainerInsights.enabled is true.
prometheusScrape:

@musa-asad musa-asad Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prometheusScrape bundle moves prometheusCRDs.install and the monitor flags to new prometheusScrape.* keys with no alias, so an existing --set prometheusCRDs.install=never is silently ignored. If we can't guarantee merge order, could we add aliases or a deprecation path?

- nonResourceURLs: ["/metrics"]
verbs: ["get"]
{{- if and (hasKey ($customAgent.prometheus.targetAllocator) "prometheusCR") $customAgent.prometheus.targetAllocator.prometheusCR.enabled }}
{{- if or (and (hasKey ($customAgent.prometheus) "targetAllocator") (hasKey ($customAgent.prometheus.targetAllocator) "prometheusCR") $customAgent.prometheus.targetAllocator.prometheusCR.enabled) $otelCIScrape }}

@musa-asad musa-asad Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: the SM/PM rule is present but the customresourcedefinitions rule (in #327) isn't, so this branch needs #327 to land alongside for the target-allocator to list CRDs. Could we make sure they merge together under the same gate?

@@ -0,0 +1,1429 @@
{{- /*
PodMonitor CRD (monitoring.coreos.com/v1), pinned to prometheus-operator v0.91.0 to

@musa-asad musa-asad Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header pins these CRDs to prometheus operator v0.91.0 but go.mod is on v0.92.0, so the API server prunes any field added between the two from a user's monitor. Could we refetch both from v0.92.0 (or fix the header)? Same in servicemonitor-crd.yaml.

@@ -6405,9 +6405,10 @@ spec:
allocationStrategy:

@musa-asad musa-asad Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allocationStrategy gains per-node only in the crds/ copy, which Helm doesn't touch on upgrade, so upgrading a release whose CRD predates the enum makes the API server reject the rendered per-node. Could we move this CRD into templates/ and gate it like the bundled monitor CRDs?


printf "\n${Y}== Target Allocator CRD RBAC ==${N}\n"
# The TA needs customresourcedefinitions get;list;watch on the prometheus-CR path.
expect_count "CRD RBAC present when otelCI on" "$CRD_RBAC" 1 --set otelContainerInsights.enabled=true

@musa-asad musa-asad Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CRD_RBAC assertions on lines 76 to 78 expect customresourcedefinitions RBAC that lands in a separate branch, so this branch renders zero and set -euo pipefail fails the whole suite. Could we move them into that branch or guard them until the rule exists?

otelContainerInsights.prometheusScrape.enabled are both true.
Returns the string "true" when CRDs should be rendered, empty otherwise.
*/}}
{{- define "amazon-cloudwatch-observability.prometheusCRDsEnabled" -}}

@musa-asad musa-asad Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prometheusCRDsEnabled only matches always/never exactly, so a typo like nevr falls through and silently bundles the CRDs when otelCI is on. Could we add a fail branch for anything that isn't auto, always, or never?

the configured targetAgent, and at least one of serviceMonitor/podMonitor is enabled.
Accepts a dict with "agentName" (string) and "context" (root context $).
*/}}
{{- define "cloudwatch-agent.otelCIScrapeEnabled" -}}

@musa-asad musa-asad Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otelCIScrapeEnabled no longer short circuits when both serviceMonitor.enabled and podMonitor.enabled are false, so prometheusScrape.enabled=true renders an idle target-allocator that bundles CRDs but discovers nothing. Could we reject that both false case and add a matrix assertion?

wenegiemepraise added a commit to wenegiemepraise/helm-charts that referenced this pull request Jul 23, 2026
…cture

Re-sync aws-observability#332 onto the updated stack (aws-observability#329->aws-observability#330->aws-observability#331). Resolutions favor the
settled older-PR fixes applied onto aws-observability#332's prometheusScrape.* restructure:
- prometheusCRDsEnabled: keep aws-observability#331's explicit auto branch + invalid-value fail,
  gated on aws-observability#332's otelContainerInsights.enabled && prometheusScrape.enabled.
- allocationStrategy: use aws-observability#332's precomputed $allocationStrategy (per-node on the
  otelCI path via prometheusScrape.allocationStrategy, consistent-hashing for
  direct-TA) -- supersedes aws-observability#330's ternary while preserving its intent.
- Fix a stale old-key guard (otelContainerInsights.serviceMonitor.enabled) left by
  auto-merge in the prometheuscr scope-processor to prometheusScrape.enabled.
- Keep aws-observability#330's SM/PM node-stamping removal; port aws-observability#331's GitOps opt-out caveat into
  the new prometheusScrape.crds doc.
Verified: lint clean, CRD matrix 21/0, flag matrix 8/8.
wenegiemepraise added a commit to wenegiemepraise/helm-charts that referenced this pull request Jul 23, 2026
…ion-scraper-routing

Re-sync aws-observability#339 (scraper routing) onto the full updated stack. Preserve aws-observability#339's
annotation-routing feature (scraperRole: cluster-scraper) while adopting the
older/settled fixes: the prometheusScrape restructure, legacy-key aliases +
deprecation notice, the serviceMonitorEnabled/podMonitorEnabled helpers for the
SM/PM selector guards, the feature-gate/CRD-RBAC/render-once/v0.92.0-CRD fixes,
and per-node scoping. Verified: lint clean, CRD matrix 24/0, flag matrix 8/8,
scraperRole renders, legacy prometheusCRDs.install alias honored.
wenegiemepraise added a commit to wenegiemepraise/helm-charts that referenced this pull request Jul 24, 2026
…ion-scraper-routing

Propagates the both-false prometheusScrape validation (reject scrape.enabled
with no monitors).

# Conflicts:
#	charts/amazon-cloudwatch-observability/tests/prometheus_crds_matrix.sh
wenegiemepraise added a commit to wenegiemepraise/helm-charts that referenced this pull request Jul 24, 2026
…ion-scraper-routing

Propagates the needsCR least-privilege fix (require targetAllocator.enabled).
musa-asad
musa-asad previously approved these changes Jul 24, 2026
Aakash-Dantre pushed a commit to wenegiemepraise/helm-charts that referenced this pull request Sep 23, 2026
…ion-scraper-routing

Brings in aws-observability#332 plus origin/main (including the resolved
cloudwatch-agent-custom-resource.yaml conflict). The only conflict here
was the otelCIScrapeEnabled doc comment; the merged text keeps this
branch's two-agent description (targetAgent or clusterScraperAgent) and
aws-observability#332's note that individual monitor types are not checked by this helper.
Aakash-Dantre pushed a commit to wenegiemepraise/helm-charts that referenced this pull request Sep 23, 2026
…ion-scraper-routing

Brings in the full chain (aws-observability#332, aws-observability#331, aws-observability#330, aws-observability#329) and origin/main.

The cluster-scraper OTEL config conflicted structurally: main added the
Karpenter/KEDA solution pipelines (aws-observability#325, aws-observability#345) in the same receivers /
processors / pipelines sections where this branch adds its prometheuscr
blocks, and git interleaved the {{- if }}/{{- end }} boundaries. Rather
than untangle the markers, the file was reconstructed from main's version
with this branch's three self-contained, individually-gated prometheuscr
blocks re-inserted at their anchors (after each kubeStateMetrics block).

Verified: all five cluster-scraper pipelines render (prometheuscr,
karpenter, keda, apiserver, kube_state_metrics), scraperRole is still set
only on the cluster-scraper, and the TA ClusterRole/Binding still render
exactly once.
@Aakash-Dantre

Aakash-Dantre commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Checklist posted for the PR author to move into the PR description under a ## PR Checklist heading.

PR Checklist

  • Commits are squashed into a logical, reviewable set — single commit, authored by the PR author
  • Commits and PR description comply with Amazon internal guidelines
  • make passes locally — helm lint clean, helm template renders, tests/prometheus_crds_matrix.sh 30 passed / 0 failed
  • All GitHub Actions checks on the PR are passing
  • Integration test evidence: link to a passing run, or state N/A with the reason
  • New or updated integration test coverage: [test/otel/pernode] Add per-node + zero-step CRD E2E suite and EKS harness aws/amazon-cloudwatch-agent-test#720 (per_node_test.go, crd_bundling_test.go)
  • New functionality has unit tests; bug fixes have a reproducing test — chart render tests under tests/
  • Config translation changes include updated golden files — N/A, chart-only change
  • Breaking or customer-visible changes are called out in the PR description

Note for the description: this is a values-key restructure. The former top-level prometheusCRDs
key and otelContainerInsights.serviceMonitor / .podMonitor keys are moved, not aliased, to
otelContainerInsights.prometheusScrape.*. Any values file setting the old paths needs updating.

…ights.prometheusScrape

Collapses SM/PM scraping enablement into a single switch.
otelContainerInsights.enabled: true now makes SM/PM scraping work end to end;
prometheusScrape.enabled: false opts out while keeping the rest of OTEL
Container Insights.

BREAKING (unreleased keys): the former top-level prometheusCRDs key and
otelContainerInsights.serviceMonitor / .podMonitor keys are MOVED, not
aliased, to otelContainerInsights.prometheusScrape.*. Any values file setting
the old paths needs updating. These keys have not shipped in a released chart
version, so there is no external contract to preserve.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants