feat(go-lib/version): add Handler and HandlerFor http.Handler - #270
feat(go-lib/version): add Handler and HandlerFor http.Handler#270priyaselvaganesan wants to merge 6 commits into
Conversation
🛡️ CodeQL Analysis🚨 Found 2 issue(s) Severity Breakdown:
📋 Top Issues🔗 View full details in Security tab 🕐 Last updated: 2026-07-20 19:00:38 UTC | Commit: f779787 |
kristinapathak
left a comment
There was a problem hiding this comment.
Please provide a github issue rather than an internal JIRA issue.
Done — created issue #315 and updated the Issues section here. |
Registers nvcfversion.Handler() at GET /info on the management server (port 8082). Returns service name, semver, and commit SHA injected at build time via Bazel x_defs. Blocked on go-lib PR #270 merging. Once that lands, go.mod will be updated to the published version that includes Handler(). Refs: NVCF-10975
Adds a shared HTTP handler to go-lib/pkg/version that serves build
metadata as JSON at GET /version. Version and commit are injected at
link time via Bazel x_defs (STABLE_VERSION, STABLE_GIT_COMMIT) when
built with --stamp. Falls back to Go runtime build info for commit
when GitHash is not injected, so local go build still returns a real
commit SHA.
Response schema: {"version": "v1.2.3", "commit": "abc1234"}
Refs: NVCF-10975
Adds Service string var injected via x_defs so each service identifies
itself in the response. Renames from GET /version to GET /info following
reviewer feedback that /info is more extensible for future fields.
Response schema: {"service":"nvcf-my-service","version":"v1.2.3","commit":"abc1234"}
Refs: NVCF-10975
50bc92b to
da89e1d
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an HTTP handler that serves service, version, and commit metadata as JSON, resolves missing values from defaults or Go build information, exposes a CI-populated service variable, and adds Bazel wiring and tests. ChangesVersion metadata HTTP handler
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Client
participant Handler
participant HandlerFor
participant BuildInfo
Client->>Handler: Request metadata
Handler->>HandlerFor: Pass Service, Version, GitHash
HandlerFor->>BuildInfo: Resolve missing commit
BuildInfo-->>HandlerFor: Return vcs.revision or empty
HandlerFor-->>Client: JSON Info response
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@src/libraries/go/lib/pkg/version/handler_test.go`:
- Around line 105-110: Update TestHandler’s cleanup to capture the initial
Service, Version, and GitHash values before the test and restore those captured
values in t.Cleanup instead of assigning empty strings.
In `@src/libraries/go/lib/pkg/version/handler.go`:
- Around line 45-51: Add the established inbound-request observability baseline
inside the handler returned by HandlerFor: emit a structured request log,
create/propagate an OpenTelemetry span, and record RED metrics using bounded
labels derived from the request and service context. Reuse the repository’s
existing observability facilities and conventions, while preserving the current
JSON response behavior.
🪄 Autofix (Beta)
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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 3520689e-8064-454c-b70f-05cf931eac70
📒 Files selected for processing (4)
src/libraries/go/lib/pkg/version/BUILD.bazelsrc/libraries/go/lib/pkg/version/handler.gosrc/libraries/go/lib/pkg/version/handler_test.gosrc/libraries/go/lib/pkg/version/version.go
Signed-off-by: priyaselvaganesan <pselvaganesa@nvidia.com>
Signed-off-by: priyaselvaganesan <pselvaganesa@nvidia.com>
Signed-off-by: priyaselvaganesan <pselvaganesa@nvidia.com>
TL;DR
Adds
Handler()andHandlerFor()togo-lib/pkg/version, a shared HTTP handler that serves build metadata as JSON atGET /info. Each service registers one line to expose the endpoint. Service name, version, and commit are injected via Bazelx_defsat build time.Additional Details
Handler()reads theService,Version, andGitHashpackage vars injected at link time viax_defs(set to a hardcoded service name,{STABLE_VERSION}, and{STABLE_GIT_COMMIT_FULL}fromtools/workspace_status.shwhen building with--stamp).HandlerFor()accepts explicit(service, ver, commit)values and falls back to Go runtime build info for commit when the value is empty, sogo buildlocally returns a real commit SHA. Empty service or version fall back to"unknown". Any non-GET method returns405 Method Not Allowed.Response schema:
{"service":"nvcf-my-service","version":"v1.2.3","commit":"16769d1988ff11c19071966db971de23b173f289"}This is a prerequisite for the follow-on PR that wires
nvcfversion.Handler()into each Go control plane service.For the Reviewer
handler.goandhandler_test.goare new files.BUILD.bazeladds them to the existinggo_libraryandgo_testtargets.version.gois updated to add aServicepackage var alongside the existingVersion,GitHash, andDirtyvars.For QA
go test ./pkg/version/...passes. No service changes in this PR.Issues
Relates to #315
Checklist
Summary by CodeRabbit
New Features
service,version, andcommit."unknown"when inputs are missing.application/jsonfor successful GET requests.405 Method Not Allowed(including anAllow: GETheader).Tests
405 Method Not Allowed.