Skip to content

feat: add expvar debug endpoint and build version injection - #33

Merged
emsearcy merged 5 commits into
mainfrom
arch-350-debug-endpoint
Mar 20, 2026
Merged

feat: add expvar debug endpoint and build version injection#33
emsearcy merged 5 commits into
mainfrom
arch-350-debug-endpoint

Conversation

@emsearcy

@emsearcy emsearcy commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements ARCH-350.

Changes

  • /debug/vars expvar endpoint: Registers the Go standard library expvar handler on the HTTP mux at /debug/vars (internal-only; not exposed via ingress HTTPRoute). The blank import of expvar registers its handler on http.DefaultServeMux, which is then mounted at that path.

  • Build version injection: Adds a Version package-level var as an ldflags injection target. Used as the MCP server implementation version string (visible in MCP Inspector) and in --help output.

  • Makefile: Derives version from git describe --tags --dirty --always, giving:

    • v0.4.1 on a tagged commit
    • v0.4.1-3-gabcdef0 between tags
    • v0.4.1-dirty / v0.4.1-3-gabcdef0-dirty with uncommitted changes
  • .ko.yaml: Declares the -X main.Version ldflag using {{.Env.VERSION}} templating, following the same pattern as lfx-v2-member-service.

  • CI workflows: Sets VERSION env var in both ko build steps:

    • Tagged release: VERSION=github.ref_name (e.g. v0.4.1)
    • Main branch: `VERSION=development-

Register the expvar debug endpoint on the HTTP mux at /debug/vars
(internal-only; not exposed via ingress HTTPRoute). The blank import of
expvar registers its handler on http.DefaultServeMux, which is then
mounted at that path.

Add a Version package-level var as an ldflags injection target, and use
it as the MCP server implementation version string instead of a
hardcoded literal. The Makefile derives the version from
'git describe --tags --dirty --always', which produces a clean tag on
tagged commits, a tag+offset+hash string between tags, and appends
-dirty when there are uncommitted changes.

🤖 Generated with [GitHub Copilot](https://github.com/features/copilot) (via Zed)

Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Override the FlagSet Usage func to print the version string before the
flag defaults, so 'lfx-mcp-server --help' shows the running version.

🤖 Generated with [GitHub Copilot](https://github.com/features/copilot) (via Zed)

Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Add .ko.yaml declaring the -X main.Version ldflag using the VERSION
environment variable, following the same pattern as lfx-v2-member-service.

Set VERSION in both ko workflow steps:
- Tagged release: VERSION=github.ref_name (e.g. v0.4.1)
- Main branch: VERSION=development-<sha>

Also name the previously anonymous main-branch build step for clarity.

🤖 Generated with [GitHub Copilot](https://github.com/features/copilot) (via Zed)

Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
@emsearcy
emsearcy requested review from Copilot and jordane and removed request for Copilot March 20, 2026 19:34
Add a VERSION build arg to the Dockerfile (defaulting to 'dev') and pass
it to the -X main.Version ldflag in the go build command. Update the
docker-build Makefile target to forward VERSION=$(VERSION) so local
Docker builds get the same git-describe version string as make build.
Also change the default DOCKER_TAG from 'latest' to 'local' to avoid
accidentally tagging local builds as latest.

🤖 Generated with [GitHub Copilot](https://github.com/features/copilot) (via Zed)

Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Copilot AI review requested due to automatic review settings March 20, 2026 19:42

Copilot AI 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.

Pull request overview

Adds internal observability and build metadata to the lfx-mcp-server binary by exposing a Go expvar endpoint and injecting a build-time version string used in the MCP implementation metadata and CLI help output.

Changes:

  • Registers /debug/vars (expvar) on the HTTP server mux.
  • Introduces a build-injected main.Version variable and uses it in MCP implementation metadata and --help output.
  • Updates local build (Makefile/Dockerfile) and CI/ko configuration to pass version via ldflags.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Makefile Derives a git-based VERSION, injects it via ldflags, and passes it to Docker builds.
Dockerfile Accepts a VERSION build-arg and injects it via ldflags for local Docker builds.
cmd/lfx-mcp-server/main.go Adds build-time Version, prints it in CLI usage, uses it in MCP implementation metadata, and mounts /debug/vars.
.ko.yaml Configures ko to inject main.Version from VERSION env var at build time.
.github/workflows/ko-build-tag.yaml Sets VERSION from the tag name for tagged ko builds.
.github/workflows/ko-build-main.yaml Sets VERSION to a development SHA-based value for main-branch ko builds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/lfx-mcp-server/main.go Outdated
Comment thread cmd/lfx-mcp-server/main.go
Comment thread .ko.yaml
- bump github.com/modelcontextprotocol/go-sdk v1.4.0 -> v1.4.1 to
  resolve GHSA-89xv-2j6f-qhc8 and GHSA-q382-vc8q-7jhj
- add missing package comment to internal/tools/member_write.go
- replace blank expvar import with named import; register
  /debug/vars via expvar.Handler() directly on the local mux instead
  of mounting http.DefaultServeMux
- wrap /debug/vars in localhostOnly middleware so it is reachable via
  kubectl port-forward but blocked from ingress traffic
- add ko-build Makefile target that loads a local image as
  linuxfoundation/lfx-mcp/lfx-mcp-server:local, matching docker-build;
  VERSION is forwarded so the .ko.yaml template resolves correctly

🤖 Generated with [GitHub Copilot](https://github.com/features/copilot) (via Zed)

Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
@emsearcy
emsearcy merged commit 1d601d4 into main Mar 20, 2026
3 checks passed
@emsearcy
emsearcy deleted the arch-350-debug-endpoint branch March 20, 2026 20:25
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