Skip to content

feat(ecs): awslogs -> CloudWatch Logs + EventBridge task state change#727

Merged
vieiralucas merged 1 commit intomainfrom
worktree-ecr-ecs-tighten-batch2
Apr 24, 2026
Merged

feat(ecs): awslogs -> CloudWatch Logs + EventBridge task state change#727
vieiralucas merged 1 commit intomainfrom
worktree-ecr-ecs-tighten-batch2

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 24, 2026

Summary

Batch 2 of the ECR+ECS tightening pass. Closes the two deferred ECS observability integrations from last week.

  • awslogs -> CloudWatch Logs — container definitions that declare logDriver=awslogs stream captured stdout/stderr into fakecloud-logs via a new fakecloud_logs::ingest::append_events same-process helper (no HTTP round-trip).
  • EventBridge task state change — task transitions fire source: aws.ecs / ECS Task State Change events on the default bus, with AWS-shaped detail (taskArn, clusterArn, lastStatus, stopCode, per-container exitCode, ...). Reuses the existing EventBridgeDelivery trait / DeliveryBus pattern (same as S3 notifications).
  • Builder methods on EcsRuntime: with_delivery_bus + with_logs. Unwired runtime behaves exactly as before — keeps unit tests simple.
  • E2E coverage: new ecs_observability test file. One test runs a task with awslogs config and asserts GetLogEvents returns the container stdout. Another puts an EventBridge rule -> SQS target and asserts the STOPPED event arrives for the right task ARN.
  • Docs: website/content/docs/services/ecs.md documents both integrations and the expected logConfiguration shape.

Test plan

  • cargo test -p fakecloud-logs --lib ingest — ingest helper unit tests pass
  • cargo test -p fakecloud-e2e --test ecs_observability — both E2E tests pass on local docker
  • cargo test -p fakecloud-e2e --test ecs --test lambda --test ecr_cross_service — no regressions
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • CI + Cubic

Summary by cubic

Adds CloudWatch Logs integration for ECS awslogs and emits EventBridge task state change events. Tasks now stream container stdout/stderr to Logs, and lifecycle events can trigger EventBridge targets.

  • New Features
    • Forward awslogs output to CloudWatch Logs via same-process fakecloud-logs::ingest::append_events (auto-creates group/stream; visible via DescribeLogStreams/GetLogEvents).
    • Emit aws.ecs / "ECS Task State Change" events on the default EventBridge bus with AWS-shaped detail (task/container fields). Uses the existing DeliveryBus pattern; routes to SQS and other targets.
    • EcsRuntime adds with_delivery_bus and with_logs. When unwired, behavior is unchanged.
    • E2E tests cover both flows; docs updated with the expected logConfiguration shape.

Written for commit 9228bd6. Summary will update on new commits.

Batch 2 of the ECR+ECS tightening pass. Closes the two deferred ECS
observability integrations from last week so tasks are actually
debuggable without `docker logs` and so downstream rules can react to
task lifecycle events end-to-end.

- New `fakecloud_logs::ingest` helper appends events directly into
  `SharedLogsState`, creating the group + stream on demand. Same-process
  call path — no `AwsRequest`/HTTP round-trip — so ECS can forward
  synchronously after a task exits.

- `EcsRuntime` gains two optional builder methods: `with_delivery_bus`
  and `with_logs`. Left unwired a runtime behaves exactly as before
  (test-friendly) — with them wired, every state transition emits
  `aws.ecs` / `ECS Task State Change` on the default bus and every
  task whose container definition declares `logDriver=awslogs` has
  its captured stdout/stderr streamed into the corresponding log group.

- The EventBridge detail payload matches AWS's task-state-change shape:
  `taskArn`, `clusterArn`, `launchType`, `group`, `taskDefinitionArn`,
  `lastStatus`, `desiredStatus`, `stopCode`, `stoppedReason`, and a
  `containers` array with `exitCode` / `reason`. Rules matching
  `source: aws.ecs` get the same fan-out treatment as S3 / SES events
  via the existing `EventBridgeDelivery` trait.

- Server rewires `EcsRuntime` construction to happen after the delivery
  bus setup so it can inject both the EventBridge delivery and the
  shared logs state.

- Two new E2E tests cover the loop end-to-end: `awslogs_forwards_to_cloudwatch`
  (runs a task, asserts captured stdout appears via `GetLogEvents`)
  and `state_change_emits_eventbridge` (puts a rule -> SQS target,
  runs a task, asserts an SQS message with `lastStatus=STOPPED` for
  the right task ARN).

- Docs updated to call out both integrations and the expected
  `logConfiguration` shape.
@vieiralucas vieiralucas merged commit 0204572 into main Apr 24, 2026
19 checks passed
@vieiralucas vieiralucas deleted the worktree-ecr-ecs-tighten-batch2 branch April 24, 2026 11:17
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 42.79835% with 139 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/fakecloud-ecs/src/runtime.rs 0.00% 124 Missing ⚠️
crates/fakecloud-server/src/main.rs 0.00% 15 Missing ⚠️

📢 Thoughts on this report? Let us know!

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