Skip to content

refactor: split internal/lambda into handler sub-packages#71

Merged
dwsmith1983 merged 9 commits intomainfrom
refactor/lambda-subpackages
Mar 29, 2026
Merged

refactor: split internal/lambda into handler sub-packages#71
dwsmith1983 merged 9 commits intomainfrom
refactor/lambda-subpackages

Conversation

@dwsmith1983
Copy link
Copy Markdown
Owner

Summary

  • Split the monolithic internal/lambda/ package (46 files) into 6 handler-aligned sub-packages: orchestrator/, stream/, watchdog/, sla/, alert/, sink/
  • Extract shared utilities into focused root files (publish, date, exclusion, sensor, schedule, config, terminal)
  • Add pkg/sla/ with pure SLA deadline calculation functions
  • Add PipelineConfig.DeepCopy() for safe config cache isolation
  • Fix HandleWatchdog to return aggregate errors and publish WATCHDOG_DEGRADED event
  • Replace buildTriggerConfig switch with generic registry map
  • Add smoke tests for all 6 cmd/lambda/ packages

Motivation

The internal/lambda/ package grew to 46 files handling orchestration, stream routing, watchdog detection, SLA monitoring, alerting, reruns, drift detection, and dry-run evaluation — all in a single namespace with no interface boundaries. This restructure adds package-level encapsulation while preserving all existing behavior.

What changed

Area Before After
Lambda handler code 46 files in flat internal/lambda/ 6 sub-packages + shared root
Watchdog errors Silently returned nil Returns errors.Join, publishes WATCHDOG_DEGRADED
Trigger config builder 70-line switch statement Generic registry map
SLA time calculations Inline in Lambda handler Pure functions in pkg/sla/
Config cache deep copy JSON marshal/unmarshal roundtrip Typed DeepCopy() method
cmd/lambda/ test coverage 0% (no test files) Smoke tests for all 6 packages

Migration note

Root-level handler files (orchestrator.go, stream_router.go, etc.) are retained as deprecated stubs for backward compatibility with existing tests. A follow-up will migrate tests to sub-packages and remove these stubs.

…ule access

Relocates the validation package so that external modules (e.g. chaos-data)
can import it. Updates all 6 internal importers to the new path.
Create orchestrator, stream, watchdog, sla, alert, sink sub-packages.
Root retains shared types, interfaces, and utilities.
Sub-packages import root; root never imports sub-packages.
…legation

- Replace buildTriggerConfig switch with generic registry map
- HandleWatchdog returns errors.Join, publishes degraded event
- SLA calculate delegates to pkg/sla pure functions
- Move CapturePostRunBaseline to root, add deprecation comments
- ValidateEnv smoke tests for all 6 Lambda handlers
- Centralize triggerUnmarshalers in trigger_registry.go
- Log PublishEvent errors in watchdog instead of discarding
- README: project structure reflects new sub-packages and pkg/sla
- CHANGELOG: v0.9.4 entry with refactored, added, and fixed sections
- aws.md: watchdog section updated to 8 checks + degraded event
- watchdog.md: full check list, error handling, and WATCHDOG_DEGRADED event
@github-actions github-actions bot added tests Test changes lambda Lambda handlers docs Documentation types Public types (pkg/types) labels Mar 29, 2026
@dwsmith1983 dwsmith1983 changed the title Split internal/lambda into handler sub-packages (v0.9.4) refactor: split internal/lambda into handler sub-packages Mar 29, 2026
@dwsmith1983 dwsmith1983 self-assigned this Mar 29, 2026
@dwsmith1983 dwsmith1983 merged commit ead5e6e into main Mar 29, 2026
6 checks passed
@dwsmith1983 dwsmith1983 deleted the refactor/lambda-subpackages branch March 29, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation lambda Lambda handlers tests Test changes types Public types (pkg/types)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant