Skip to content

Commit 4c7b32a

Browse files
committed
Add default Prometheus EMF metric_declaration when target allocator is enabled
1 parent f6a3940 commit 4c7b32a

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ Logic:
8989
{{- $needsLogs = true -}}
9090
{{- $_ := set $metricsCollected "kubernetes" (dict "enhanced_container_insights" true) -}}
9191
{{- end -}}
92+
{{/* Prometheus EMF: when the Target Allocator is enabled, wire the awsemf path for the
93+
Prometheus pipeline by adding logs.metrics_collected.prometheus.emf_processor with
94+
metric_declarations. Without this, scraped Prometheus values reach CloudWatch Logs
95+
but produce no CloudWatch metrics (Phase-3 findings F1/F5). */}}
96+
{{- if $ctx.Values.agent.prometheus.targetAllocator.enabled -}}
97+
{{- $emf := $ctx.Values.agent.prometheus.emfProcessor -}}
98+
{{- if and $emf $emf.metricDeclarations -}}
99+
{{- $needsLogs = true -}}
100+
{{/* CloudWatch Agent input schema key is "metric_declaration" (singular array);
101+
emitting "metric_declarations" (plural) fails config-translator validation
102+
("Additional property metric_declarations is not allowed"). */}}
103+
{{- $emfProcessor := dict "metric_declaration" $emf.metricDeclarations -}}
104+
{{- if $emf.metricNamespace -}}
105+
{{- $_ := set $emfProcessor "metric_namespace" $emf.metricNamespace -}}
106+
{{- end -}}
107+
{{- $_ := set $metricsCollected "prometheus" (dict "emf_processor" $emfProcessor) -}}
108+
{{- end -}}
109+
{{- end -}}
92110
{{- if $needsLogs -}}
93111
{{- $_ := set $config "logs" (dict "metrics_collected" $metricsCollected) -}}
94112
{{- end -}}

charts/amazon-cloudwatch-observability/values.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,41 @@ agent:
763763
otelConfig: # optional YAML config that can be provided to combine with the build-default-otel-config output
764764
prometheus:
765765
config:
766+
## EMF (Embedded Metric Format) processor for the Prometheus pipeline.
767+
## When the Target Allocator is enabled (agent.prometheus.targetAllocator.enabled=true),
768+
## the CloudWatch Agent converts scraped Prometheus metrics into CloudWatch metrics via
769+
## EMF using these metric_declarations. WITHOUT metric_declarations the scraped values
770+
## are written to CloudWatch Logs but carry no `_aws.CloudWatchMetrics` block, so NO
771+
## CloudWatch metrics are produced. These declarations wire the awsemf path for the
772+
## Prometheus pipeline. This block is only rendered into the agent config when the Target
773+
## Allocator is enabled, so default behavior for non-Prometheus users is unchanged.
774+
## Override `emfProcessor.metricDeclarations` to scrape additional jobs/metrics, and
775+
## `emfProcessor.metricNamespace` to change the destination CloudWatch namespace.
776+
emfProcessor:
777+
metricNamespace: ContainerInsights/Prometheus
778+
metricDeclarations:
779+
# node-exporter (PodMonitor "node-exporter") — host CPU/memory/disk/network
780+
- source_labels: ["job"]
781+
label_matcher: ".*node-exporter.*"
782+
dimensions:
783+
- ["ClusterName"]
784+
- ["ClusterName", "Namespace"]
785+
metric_selectors:
786+
- "^node_cpu_seconds_total$"
787+
- "^node_memory_MemAvailable_bytes$"
788+
- "^node_memory_MemTotal_bytes$"
789+
- "^node_filesystem_avail_bytes$"
790+
- "^node_filesystem_size_bytes$"
791+
- "^node_network_receive_bytes_total$"
792+
- "^node_network_transmit_bytes_total$"
793+
# nginx (ServiceMonitor "nginx") — application request/connection metrics
794+
- source_labels: ["job"]
795+
label_matcher: ".*nginx.*"
796+
dimensions:
797+
- ["ClusterName"]
798+
- ["ClusterName", "Namespace"]
799+
metric_selectors:
800+
- "^nginx_.*$"
766801
targetAllocator:
767802
enabled: false
768803
image:

0 commit comments

Comments
 (0)