Skip to content

feat(analytics): write game outcomes to S3 (TWG-8) - #31

Merged
mcteamster merged 4 commits into
mainfrom
feat/twg-8-s3-game-analytics
Oct 4, 2026
Merged

mcteamster merged 4 commits into
mainfrom
feat/twg-8-s3-game-analytics

Conversation

@mcteamster

Copy link
Copy Markdown
Owner

Summary

Captures every explicitly-terminated Twinge game as a JSON record in S3 for ad-hoc analysis with Athena.

Four outcome values:

  • won — deck exhausted (nextRound)
  • lost — lives hit 0 (twinge)
  • abandoned — last player left voluntarily (leaveGame)
  • ended — host explicitly terminated (endGame)

Infrastructure:

  • New TwingeAnalyticsStack — single S3 bucket (twinge-analytics-prod) in eu-central-1, 365-day lifecycle
  • All 10 regional play Lambdas write cross-region; fire-and-forget, S3 failures swallowed
  • Hive-partitioned keys (games/year=YYYY/month=MM/day=DD/<gameId>-<ts>.json) for Athena compatibility

Known gap: Games that expire via DynamoDB TTL (all players disconnect without action) are not captured — accepted, would require DynamoDB Streams + 10 regional stream processors.

What was tested

  • 211/211 unit tests pass
  • 0 lint errors
  • New tests cover all four write sites, explicit outcome param, no-op guard, S3 error swallowing

Deployment order

  1. Deploy TwingeAnalyticsStack to eu-central-1 first (creates bucket)
  2. Deploy all regional TwingeServiceStack updates

Closes TWG-8

Spectre and others added 4 commits October 4, 2026 19:47
Implements OpenSpec change twg-8-s3-game-analytics.

- add @aws-sdk/client-s3 runtime dependency
- new analytics helper (writeAnalytics): builds the outcome record,
  derives the YYYY/MM/DD/<gameId>.json key, guards on ANALYTICS_BUCKET,
  and swallows S3 errors so the player path is never affected
- play handler emits analytics on won/lost transitions in the twinge
  and next-round paths via an isTerminalPhase guard
- CDK: per-region twinge-analytics-<stage> bucket with BLOCK_ALL public
  access, SSE-S3, 365-day expiry lifecycle, ANALYTICS_BUCKET env var, and
  least-privilege grantPut(playHandler)
- unit tests for the helper (key format, schema, error swallow, env guard)
  and both handler paths (emit on won/lost, skip on playing)

Tasks 1.1-6.1 complete; 6.2 deferred (needs live AWS deploy).
@mcteamster
mcteamster merged commit b04817e into main Oct 4, 2026
1 check passed
@mcteamster
mcteamster deleted the feat/twg-8-s3-game-analytics branch October 4, 2026 11:38
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