logctx: read commit_id from buildinfo.GitSHA (fix env-var divergence)#5
Merged
Merged
Conversation
Today's B1 + B2 dispatches both surfaced that /healthz returned the real commit SHA (via buildinfo.GitSHA from the ldflag-patched Dockerfile) but slog lines showed commit_id=dev because logctx read os.Getenv(COMMIT_ID). The two systems disagreed. The env-var fallback was a decoupling shim from when logctx shipped before buildinfo. Now both live on the same common module; collapse to a direct import.
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
common/logctx/handler.go::commitID()previously reados.Getenv("COMMIT_ID")with a"dev"fallback. This was a decoupling shim from the days whenlogctxshipped beforebuildinfo.instant.dev/commonmodule. Today's B1 + B2 dispatches both surfaced the divergence:/healthzreturned the real ldflag-patchedbuildinfo.GitSHA, but slog log lines emittedcommit_id="dev"becauseCOMMIT_IDenv var is not set in k8s. The two systems disagreed on every running pod.commitID()now returnsbuildinfo.GitSHA. Same"dev"default (the buildinfo sentinel matches), so un-flagged local builds still emitcommit_id="dev". Production binaries (Dockerfile builds with-ldflags -X) now have logs that agree with/healthz.Changes
logctx/handler.go— droposimport, addinstant.dev/common/buildinfoimport,commitID()returnsbuildinfo.GitSHAdirectly. Updated package doc explaining the wiring + historical note about the env-var shim.logctx/handler_test.go— newTestHandler_CommitIDFromBuildinfothat patchesbuildinfo.GitSHA(saved/restored viat.Cleanup), emits a record, and assertscommit_idreflects the patched value. ExistingTestHandler_NoCtxstill asserts default"dev"(sentinel unchanged).No
go.modchange — intra-module import.Test plan
go test ./logctx/... -v— 7/7 pass (6 originals + newTestHandler_CommitIDFromBuildinfo)go test ./...across the entirecommonmodule — buildinfo, crypto, logctx, plans all passapibuilds clean against patched common; router + middleware tests pass (-count=1)workerbuilds cleanprovisionerbuilds cleaninstant-apiDocker image, redeploy, confirm/healthz.commit_idmatches a fresh log line'scommit_idfield on a real pod