Skip to content

feat(MonitoringAspect): add Fargate service support#734

Open
costmatt-amzn wants to merge 1 commit intocdklabs:mainfrom
costmatt-amzn:feat/fargate-aspect
Open

feat(MonitoringAspect): add Fargate service support#734
costmatt-amzn wants to merge 1 commit intocdklabs:mainfrom
costmatt-amzn:feat/fargate-aspect

Conversation

@costmatt-amzn
Copy link
Copy Markdown
Contributor

@costmatt-amzn costmatt-amzn commented Apr 17, 2026

What

Wires Fargate services into the auto-applied MonitoringAspect so that teams relying on the aspect for fleet-wide auto-monitoring get Fargate coverage without manual opt-in.

Covers three cases:

Matched construct Facade method Metrics covered
ecs.FargateService (bare) monitorSimpleFargateService Service: CPU, memory, running/desired tasks
ApplicationLoadBalancedFargateService / NetworkLoadBalancedFargateService monitorFargateService Service + ALB/NLB + target group
QueueProcessingFargateService monitorQueueProcessingFargateService Service + SQS queue + DLQ

To prevent double-monitoring, the bare FargateService visitor skips services whose ancestor chain contains one of the L3 pattern constructs — those are already covered by the dedicated visitors.

Why

MonitoringFacade already exposes all of the Fargate monitoring methods, but none of them were reachable through MonitoringAspect. Teams that use the aspect for fleet-wide auto-monitoring had to opt Fargate services in manually. This change closes that gap and mirrors the wiring pattern already used for Lambda, API Gateway, DynamoDB, etc.

Changes

  • lib/facade/IMonitoringAspect.ts
    • Add FargateServiceAspectType, LoadBalancedFargateServiceAspectType, QueueProcessingFargateServiceAspectType.
    • Add fargateService, fargateLoadBalancedService, queueProcessingFargateService to MonitoringAspectProps.
  • lib/facade/MonitoringAspect.ts
    • Add monitorFargateService, monitorFargateLoadBalancedService, monitorQueueProcessingFargateService visitors.
    • Add isInsideFargatePattern helper to de-duplicate the bare-service match inside L3 patterns.
  • lib/monitoring/aws-ecs-patterns/FargateServiceMonitoring.ts
    • Export BaseFargateServiceMonitoringProps and BaseLoadBalancedFargateServiceMonitoringProps so they can be used as aspect-option types (jsii requires named interfaces; Omit<> transforms aren't accepted).
  • lib/monitoring/aws-ecs-patterns/misc.ts
    • Add BaseQueueProcessingFargateServiceMonitoringOptions as a public alias over the package-private BaseQueueProcessingServiceMonitoringProps, for the same reason.
  • API.md — regenerated by projen.

Usage

new MonitoringAspect(facade, {
  fargateService: {
    props: {
      addCpuUsageAlarm: { Warning: { maxUsagePercent: 80 } },
    },
  },
  fargateLoadBalancedService: {
    props: {
      addHealthyTaskCountAlarm: { Critical: { minHealthyTasks: 1 } },
    },
  },
  queueProcessingFargateService: {
    props: {
      addQueueAlarms: { addApproximateNumberOfMessagesVisibleAlarm: { Critical: { maxMessageCount: 1000 } } },
    },
  },
});

Testing

  • yarn build passes locally (compile + test + eslint + jsii assembly + pacmak for js/java/python/dotnet/go).
  • New visitors mirror the established pattern in the class; no existing tests were modified.

Out of scope

  • Ec2 service / Ec2-patterns variants — could be added as a follow-up with the same pattern (bare Ec2Service + L3 patterns with ancestor-skip logic).

@cdklabs-automation cdklabs-automation enabled auto-merge (squash) April 17, 2026 19:38
auto-merge was automatically disabled April 17, 2026 19:50

Head branch was pushed to by a user without write access

Wire Fargate services into the auto-applied MonitoringAspect so that
teams relying on the aspect for fleet-wide auto-monitoring get Fargate
coverage without manual opt-in.

Covers three cases:

- Bare ecs.FargateService → monitorSimpleFargateService
  (service-only metrics: CPU, memory, task counts)
- ApplicationLoadBalancedFargateService /
  NetworkLoadBalancedFargateService → monitorFargateService
  (service + ALB/NLB + target group metrics)
- QueueProcessingFargateService →
  monitorQueueProcessingFargateService
  (service + SQS queue + DLQ metrics)

To prevent double-monitoring, the bare FargateService visitor skips
services whose ancestor chain contains one of the L3 pattern
constructs — those are already covered by the dedicated visitors.

Changes:
- IMonitoringAspect: add FargateServiceAspectType,
  LoadBalancedFargateServiceAspectType,
  QueueProcessingFargateServiceAspectType and the three corresponding
  props (fargateService, fargateLoadBalancedService,
  queueProcessingFargateService) on MonitoringAspectProps.
- MonitoringAspect: add monitorFargateService,
  monitorFargateLoadBalancedService,
  monitorQueueProcessingFargateService visitors and an
  isInsideFargatePattern helper.
- FargateServiceMonitoring: export
  BaseFargateServiceMonitoringProps and
  BaseLoadBalancedFargateServiceMonitoringProps so they can be
  referenced as aspect-option types (jsii requires named interfaces).
- misc: add BaseQueueProcessingFargateServiceMonitoringOptions
  (thin alias over the package-private
  BaseQueueProcessingServiceMonitoringProps) for the same reason.
- API.md: regenerated by projen.
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.

1 participant