Skip to content

feat(server): log healthcheck at debug level, add logLevel setting - #606

Merged
fank merged 2 commits into
mainfrom
feat/access-log-level
Nov 14, 2026
Merged

fank merged 2 commits into
mainfrom
feat/access-log-level

Conversation

@smitt14ua

Copy link
Copy Markdown
Contributor

Summary

Docker polls /api/healthcheck every 30s, and each poll was logged at info level as outgoing response, flooding the logs.

  • Replace fuego's built-in request logging with AccessLogMiddleware. It keeps fuego's fields and X-Request-ID handling but logs <prefixURL>/api/healthcheck at debug level. Fuego's logger can't change the level per path.
  • Add logLevel / OCAP_LOGLEVEL (debug, info, warn, error; default info). The slog handler was created without options, so debug records, including fuego's incoming request, were always dropped.
  • The access log now wraps the whole router as a global middleware, so requests that match no route are logged too.

A follow-up PR (stacked on this one) logs the real client IP behind reverse proxies.

Test plan

  • go test ./internal/server ./cmd/...
  • Ran the server locally: healthcheck hidden at info, other requests logged once (no duplicates from fuego)

Replace fuego's request logging with an access log middleware that keeps
its fields and X-Request-ID but logs the healthcheck polled by Docker at
debug level. Add logLevel (OCAP_LOGLEVEL, default info): the slog handler
was created without options, so debug records were always dropped.
@smitt14ua
smitt14ua marked this pull request as ready for review November 13, 2026 23:49
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/web/cmd/ocap-webserver 24.79% (-1.58%) 👎
github.com/OCAP2/web/internal/server 92.26% (-0.10%) 👎
Coverage details

Compared to commit 078e68e (run #43493631896)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/web/cmd/ocap-webserver/main.go 0.00% (ø) 87 (+7) 0 87 (+7)
github.com/OCAP2/web/internal/server/accesslog.go 75.00% (+75.00%) 36 (+36) 27 (+27) 9 (+9) 🌟
github.com/OCAP2/web/internal/server/realip.go 98.18% (+98.18%) 55 (+55) 54 (+54) 1 (+1) 🌟
github.com/OCAP2/web/internal/server/setting.go 92.93% (+0.88%) 99 (+11) 92 (+11) 7 👍

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files:

  • github.com/OCAP2/web/internal/server/accesslog_test.go
  • github.com/OCAP2/web/internal/server/realip_test.go
  • github.com/OCAP2/web/internal/server/setting_test.go

@smitt14ua
smitt14ua requested a review from fank November 13, 2026 23:57
@fank

fank commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Ratatoskr reviewed this pull request.

Approved on 1db4f51e. See the review.

Finished 2026-11-14 00:01 UTC.

@fank fank left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE — 0 blocking findings.

Review details

Reviewed head 1db4f51e48526639c41e373b4c9a5cff6e196370 against the base, including Fuego v0.21.0 middleware registration and existing streaming handlers. No actionable correctness or safety defects found.

Optional test improvement: internal/server/accesslog_test.go:40–46 implements its own 404 handler rather than exercising an unmatched Fuego route. An integration test covering the wiring in cmd/ocap-webserver/main.go:82–83, a non-empty URL prefix, and exactly one outgoing log would pin the global-middleware/no-duplicates behavior; the current unit tests do not protect that wiring.

Verification (Go 1.27.3 from the local module-cache toolchain, added to PATH):

  • go test ./internal/server -run 'TestAccessLog|TestNewSetting_Logging' -count=1 — passed.
  • go test ./internal/server ./cmd/... — command package passed; server suite failed because the local CGO-disabled SQLite driver is a stub.
  • CGO_ENABLED=1 go test ./internal/server ./cmd/... — build unavailable: C compiler gcc is missing. This is an environment limitation, not an identified PR regression.
  • GitHub test and coverage checks passed.

Discussions: GraphQL enumeration returned no review threads (no further pages); none to resolve, leave open, or skip. Checkout remained unchanged. No UI changes requiring visual verification.

* feat(server): log real client IP behind trusted reverse proxies

Add trustedProxies (OCAP_TRUSTEDPROXIES) and remoteIPHeaders
(OCAP_REMOTEIPHEADERS, default X-Forwarded-For, X-Real-IP). When the
direct peer is a trusted proxy, RemoteAddr is replaced with the client
address from the headers, X-Forwarded-For read right to left so entries
the client sent itself are skipped, and the access log adds the proxy as
proxy_addr. No proxy is trusted by default, so headers are ignored.

* docs: explain trusting Cloudflare behind another reverse proxy

* refactor(server): drop proxy_addr from the access log

With a single reverse proxy it is the same address on every line.

* style: gofmt realip_test.go

* fix(server): match IPv4-mapped trusted proxy prefixes

Addresses are unmapped before matching, but a trusted proxy given as an
IPv4-mapped CIDR (::ffff:172.18.0.0/112) stayed an IPv6 prefix and never
matched. Convert it to the equivalent IPv4 prefix; reject mapped
prefixes shorter than /96, which cover more than the mapped range.
@fank
fank merged commit f07f448 into main Nov 14, 2026
2 checks passed
@fank
fank deleted the feat/access-log-level branch November 14, 2026 14:21
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.

2 participants