feat: add taxonomy lifecycle observability - #119
Conversation
WalkthroughThe change adds configurable text or JSON logging for API and worker processes. It introduces taxonomy lifecycle metrics with bounded attributes. Taxonomy failure requests can include diagnostics that are serialized and persisted. Repository reaping returns run metadata instead of a count. The API passes taxonomy metrics to the service and reaper, which log reaped runs and record outcome and duration metrics. Tests cover logging, metric attributes, diagnostic persistence, and updated persistence contracts. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/taxonomy_persistence_test.go (1)
105-120: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winExercise the new
metricsJSONB contract.Lines 105-120 only call
MarkRunFailedwithnil, and the service test uses a mock repository. Add an integration case with known JSON. Assert the default{}and the non-empty value afterMarkRunFailedand afterGetRunForInternalService. This covers the new$4binding and JSONB round trip.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/taxonomy_persistence_test.go` around lines 105 - 120, Extend the integration coverage around MarkRunFailed to pass known metrics JSON instead of only nil, then assert the persisted default {} for nil metrics and the exact non-empty JSON for supplied metrics. Also call GetRunForInternalService and verify the metrics value round-trips correctly, covering both MarkRunFailed’s $4 binding and JSONB persistence.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/api/app.go`:
- Around line 953-977: Update FailStuckRuns and its reaped-run result to return
a per-run finished_at timestamp when each stale run is successfully
transitioned. In the reaper metrics loop around RecordRunDuration, calculate
duration from StartedAt or CreatedAt to that run’s finished_at, and clamp
negative durations to zero instead of using time.Now/time.Since after the batch
completes.
In `@internal/models/taxonomy.go`:
- Around line 259-273: Add validation for
TaxonomyRunFailureDiagnostics.PhaseDurations before the FailRun payload is
persisted to taxonomy_runs.metrics: permit only the approved taxonomy phase
keys, enforce a maximum number of entries, and reject negative duration values.
Reuse the repository’s validator configuration and add handler tests covering
valid keys, disallowed keys, excessive entries, and negative durations.
In `@tests/taxonomy_persistence_test.go`:
- Around line 168-170: Extend the assertions after repo.FailStuckRuns in the
taxonomy persistence test to locate the returned ReapedTaxonomyRun entries for
stuck.ID and pending.ID, then verify each entry’s tenant, scope, source, field,
StartedAt, and CreatedAt values against the corresponding fixtures. Keep the
existing length and error assertions.
---
Outside diff comments:
In `@tests/taxonomy_persistence_test.go`:
- Around line 105-120: Extend the integration coverage around MarkRunFailed to
pass known metrics JSON instead of only nil, then assert the persisted default
{} for nil metrics and the exact non-empty JSON for supplied metrics. Also call
GetRunForInternalService and verify the metrics value round-trips correctly,
covering both MarkRunFailed’s $4 binding and JSONB persistence.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: be9354a5-e8e6-47dd-86d4-915ae3118db3
📒 Files selected for processing (17)
.env.examplecmd/api/app.gocmd/api/main.gocmd/worker/main.gointernal/api/handlers/taxonomy_internal_handler.gointernal/config/config.gointernal/models/taxonomy.gointernal/observability/aggregate.gointernal/observability/logging.gointernal/observability/logging_test.gointernal/observability/names.gointernal/observability/taxonomy.gointernal/observability/taxonomy_test.gointernal/repository/taxonomy_repository.gointernal/service/taxonomy_service.gointernal/service/taxonomy_service_test.gotests/taxonomy_persistence_test.go
|
Addressed the outside-diff CodeRabbit request in 15f43df: the Postgres integration suite now verifies that nil failure metrics persist and round-trip as |
xernobyl
left a comment
There was a problem hiding this comment.
All three points are addressed, and the fixes look right to me:
- the second
TraceContextHandlerwrap is gone fromNewApp, soSetupLoggingis the single wrap point for both binaries now — and the count assertion added tologging_test.gokeeps it from creeping back phaseandphase_durations_secondsshare one vocabularyhub_taxonomy_outcomes_totallines up with the other_outcomes_totalcounters
Checked locally at affdd30: build, vet and go test ./internal/... all green, and request_id now appears exactly once in the JSON output. The per-run finished_at for the reaper duration is a nicer fix than what I'd have suggested.
Approving 👍
Summary
Verification
golangci-lint rungo test ./internal/observability ./internal/service ./internal/api/handlers ./internal/repository -count=1Rollout
This is PR 1 of 5 for ENG-1200. Merge and deploy this compatibility contract before the Taxonomy and GitOps changes.