feat: skip log collector on hot path when admin API is disabled#118
Merged
Conversation
Build the admin.LogCollector only when admin is enabled and pass nil to gateway.New otherwise. The logging middleware is now installed only when a collector exists, so a disabled admin API no longer pays a per-request mutex lock + ring-buffer write that no consumer could read. Fixes #112
Contributor
Reviewer's GuideThis PR makes the gateway tolerant of a nil admin log collector and wires devcloud so that the log collector (and associated logging middleware) is only created and installed when the admin API is enabled, keeping logging-related mutex and ring-buffer operations off the AWS request hot path while adding a regression test and changelog entry. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Skip per-request log collection when the admin API is disabled (the default), removing needless bookkeeping from the AWS request hot path.
Related Issue
Fixes #112
Changes
cmd/devcloud/main.go: build theadmin.LogCollectoronly inside theif cfg.Admin.Enabledblock; passniltogateway.Newwhen admin is off.internal/gateway/gateway.go: install the logging middleware only whenlogCollector != nil. With a nil collector the service router is used directly, so the mutex lock + ring-buffer write,newStatusRecorder,time.Now, anddetectServiceall drop off the hot path.Newsignature is unchanged (now nil-tolerant).internal/gateway/gateway_test.go: addTestGateway_NilLogCollectorcovering the disabled/nil path (request succeeds, no panic, noAdd).Test Plan
go build ./...go test ./internal/gateway/ ./internal/admin/ ./cmd/...— all pass. Admin-enabled behavior (recent-logs endpoint) stays covered byinternal/admin/api_test.go; collector semantics bylogger_test.go.golangci-lint run ./internal/gateway/... ./cmd/...— 0 issues.Checklist
golangci-lint run)