Skip to content

feat(go-lib/version): add Handler and HandlerFor http.Handler#270

Open
priyaselvaganesan wants to merge 2 commits into
mainfrom
feat/version-handler-go-lib
Open

feat(go-lib/version): add Handler and HandlerFor http.Handler#270
priyaselvaganesan wants to merge 2 commits into
mainfrom
feat/version-handler-go-lib

Conversation

@priyaselvaganesan

@priyaselvaganesan priyaselvaganesan commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

TL;DR

Adds Handler() and HandlerFor() to go-lib/pkg/version — a shared HTTP handler that serves build metadata as JSON at GET /info. Each service registers one line to expose the endpoint; service name, version, and commit are injected via Bazel x_defs at build time.

Additional Details

Handler() reads the Service, Version, and GitHash package vars injected at link time via x_defs (set to a hardcoded service name, {STABLE_VERSION}, and {STABLE_GIT_COMMIT} from tools/workspace_status.sh when 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, so go build locally returns a real commit SHA. Empty service or version fall back to "unknown".

Response schema: {"service":"nvcf-my-service","version":"v1.2.3","commit":"abc1234"}

This is a prerequisite for the follow-on PR that wires nvcfversion.Handler() into each Go control plane service.

For the Reviewer

  • handler.go and handler_test.go are new files; BUILD.bazel adds them to the existing go_library and go_test targets.
  • version.go is updated to add a Service package var alongside the existing Version, GitHash, and Dirty vars.

For QA

go test ./pkg/version/... passes. No service changes in this PR.

Issues

Relates to #315

Checklist

  • I am familiar with the Contributing Guidelines.
  • I have signed off my commits for Developer Certificate of Origin (DCO) compliance.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

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
@priyaselvaganesan
priyaselvaganesan requested a review from a team as a code owner July 20, 2026 18:56
@github-actions

Copy link
Copy Markdown

🛡️ CodeQL Analysis

🚨 Found 2 issue(s)

Severity Breakdown:

  • 🔴 Errors: 0
  • 🟡 Warnings: 0
  • 🔵 Notes: 0
📋 Top Issues

🔗 View full details in Security tab

🕐 Last updated: 2026-07-20 19:00:38 UTC | Commit: f779787

@priyaselvaganesan priyaselvaganesan self-assigned this Jul 20, 2026

@kristinapathak kristinapathak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please provide a github issue rather than an internal JIRA issue.

@priyaselvaganesan

Copy link
Copy Markdown
Contributor Author

Please provide a github issue rather than an internal JIRA issue.

Done — created issue #315 and updated the Issues section here.

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
priyaselvaganesan added a commit that referenced this pull request Jul 21, 2026
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
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.

3 participants