feat(observability): add structured logging and metrics #516
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/thwap-pagesd!516
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/observability"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Add application observability:
httpapi.Deps.metrics.RegistryservesGET /metricswith:thwap_pagesd_sites_totalandthwap_pagesd_deployments_totalcomputed on scrape from the backing repositoriesthwap_pagesd_errors_total— a running counter incremented on server-side failures in the site and webhook handlersWhy
Phase 7 task #100 — completes the Rollback and Operational Features phase; operators can observe request traffic, site/deployment counts, and errors.
Testing
go build ./...go vet ./...go test -race ./...— metrics registry (counts + error counter + handler),/metricsendpoint, registration-error increments the counter; full suite passesgofmt -l ./cmd ./internal ./pkgcleangolangci-lint run— 0 issuesBreaking Changes
None.
Notes
Closes #97
Closes #98
Closes #100
Review Summary
Verified locally on the PR head (
e9a276b):go build,go vet,gofmt,golangci-lint runall clean; all metrics + httpapi tests pass with-race. Smoke-tested the running daemon (fake Forgejo + kubeconfig):/metricsserves correct Prometheus text (sites_total/deployments_total/errors_total),/healthz//readyzreturn 200, request logging flows through zap ("http request","method":"GET","path":"/metrics","status":200,"client":...), and graceful shutdown works.The
requestLoggermiddleware replaces gin's stdoutLogger()with zap structured logs — closing the recurring mixed-logging note from earlier reviews. The metrics registry is clean and thread-safe (atomic.Uint64for errors, on-scrape computation from the repositories), and only server-side failures (500s / webhook 401s/400s) increment the error counter — client 4xx on the API correctly don't.No blocking issues.
Non-blocking observations:
forgejo.NewClientperforms an eager/api/v1/versioncheck — plus a kubeconfig./healthz//metricscan't run without full cluster+Forgejo config; worth documenting startup requirements.gin.Recovery()still writes panic stacks to stdout rather than zap — minor.# HELP/# TYPEdeclarations; Prometheus treats them as untyped counters, which works but is slightly non-idiomatic.Registry.Handlercapturescontext.Background()at router-build time rather than the request context — fine for a scrape endpoint.Approving.