Skip to content

feat(otel): add Karpenter metrics integration test - #715

Open
vaishnavi-30-beep wants to merge 29 commits into
aws:mainfrom
vaishnavi-30-beep:feature/karpenter-integration
Open

feat(otel): add Karpenter metrics integration test#715
vaishnavi-30-beep wants to merge 29 commits into
aws:mainfrom
vaishnavi-30-beep:feature/karpenter-integration

Conversation

@vaishnavi-30-beep

@vaishnavi-30-beep vaishnavi-30-beep commented Jun 26, 2026

Copy link
Copy Markdown

Summary

Add automated integration tests for the Karpenter metrics pipeline. Verifies that all Karpenter metrics are scraped by the CloudWatch Agent and forwarded to CloudWatch with correct instrumentation scope, cluster name, namespace, and expected datapoint labels.

Changes

Test code (test/otel/solutions/karpenter/)

  • setup_test.go — TestMain initialization (region, cluster, SigV4 client, QueryCache)
  • metrics_test.go — 24 Karpenter metric definitions covering pods, nodes, cluster state, nodepools, cloudprovider, disruption, and scaling event metrics
  • karpenter_test.go — test suites:
    • MetricsExist — all metrics are queryable in CloudWatch
    • Instrumentation — scope is github.com/aws/karpenter
    • InstrumentationConsistent — no mixed sources per metric
    • ExpectedLabels — datapoint labels (resource_type, phase, method, reason) present
    • ClusterIdentity, Namespace, DeploymentName, PodName — K8s resource attributes
    • CloudProvider, CloudPlatform, CloudRegion, CloudAccountID, CloudResourceID — cloud resource attributes

Terraform (terraform/eks/daemon/otel/)

  • Installs Karpenter via Helm with IAM role (EC2, IAM instance profile, SSM, Pricing permissions) and Pod Identity
  • Tags subnets/SGs for Karpenter discovery
  • Deploys a NodePool with karpenter-test: NoSchedule taint + EC2NodeClass for metric generation
  • Deploys a karpenter-scale-trigger workload with matching toleration to guarantee Karpenter provisions a node on every run (ensures scaling-event metrics like karpenter_nodeclaims_created_total and karpenter_nodes_created_total are always emitted)
  • Waits for EC2NodeClass readiness and Karpenter controller availability before triggering provisioning
  • Enables otelContainerInsights.solutions.karpenter.enabled=true in the CW Agent helm values
  • Adds Karpenter integration test run to the validator

Shared utility (util/otelmetrics/source_registry.go)

  • Adds SourceKarpenter to the MetricSource enum

Testing

CI integration tests passing for Karpenter under eks_daemon:otel_standard_test: https://github.com/aws/amazon-cloudwatch-agent/actions/runs/30315568293/job/90140403199

Also verified locally against a live EKS cluster (karpenter-test, eu-north-1) — all tests passing.

Screenshot 2026-07-28 at 11 32 39

Related

Comment thread test/otel/integrations/karpenter/karpenter_test.go Outdated
Comment thread terraform/eks/daemon/otel/main.tf Outdated
@vaishnavi-30-beep
vaishnavi-30-beep force-pushed the feature/karpenter-integration branch from 33caed0 to 5f0f260 Compare July 27, 2026 10:41
@petruanica

Copy link
Copy Markdown
Contributor

It seems we are not testing what happens when Karpenter provisions new nodes. Should we validate we can scrape the metrics that are only emitted during scaling operations?

Comment thread test/otel/solutions/karpenter/karpenter_test.go Outdated
Comment thread terraform/eks/daemon/otel/main.tf Outdated
Add karpenter-test taint to NodePool so trigger pod is unschedulable
on managed node group nodes. This guarantees Karpenter must provision
a new node on every run, ensuring provisioning metrics
(karpenter_nodeclaims_created_total, karpenter_nodes_created_total,
karpenter_cloudprovider_duration_seconds, karpenter_pods_bound_duration_seconds)
are always emitted.

Changes:
- Add karpenter-test:NoSchedule taint to NodePool spec
- Replace karpenter.sh/disruption toleration with karpenter-test
  toleration on trigger pod
- Remove || true from kubectl wait so terraform fails loudly if
  Karpenter cannot provision
cloud.account.id is always present on Karpenter metrics. Replace
conditional check with require.True assertion to fail explicitly
if the attribute is ever missing.
- Add karpenter_scale_trigger to validator depends_on so terraform
  waits for Karpenter to actually provision a node before starting
  the metric propagation sleep
- Increase sleep to 4 minutes to give the agent time to scrape
  the provisioning counter metrics after node creation
- Add kubectl wait for karpenter deployment readiness + 10s settle
  before applying NodePool CRDs
- Increase scale-trigger timeout to 600s to allow for slower EC2
  provisioning in CI environments
@vaishnavi-30-beep
vaishnavi-30-beep force-pushed the feature/karpenter-integration branch from db1a0d4 to a3b8d37 Compare July 27, 2026 14:51
Karpenter v1 manages instance profiles directly. Add GetInstanceProfile,
CreateInstanceProfile, AddRoleToInstanceProfile, DeleteInstanceProfile,
RemoveRoleFromInstanceProfile, and TagInstanceProfile to the controller
IAM policy. Without these, EC2NodeClass stays 'not ready' and NodePool
is ignored.
- Expand instance-category to c,m,r,t and sizes to medium,large,xlarge
  t3.medium/large don't have enough allocatable CPU for the trigger pod
- Add ec2:DescribeSpotPriceHistory (Karpenter pricing controller)
- Add iam:ListInstanceProfiles (Karpenter GC controller)
Verify karpenter_nodeclaims_created_total and karpenter_nodes_created_total
have value >= 1, confirming Karpenter actually provisioned a node.
- Revert helm chart clone to aws-observability/helm-charts with
  helm_chart_branch variable
- Remove karpenter_chart_ref variable (testing-only)
- Remove diagnostic log dump from scale-trigger timeout
Comment thread test/otel/solutions/karpenter/karpenter_test.go Outdated
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.

4 participants