Skip to content

Conversation

@Vad1mo
Copy link
Member

@Vad1mo Vad1mo commented Jan 13, 2026

The Prometheus exporter's harbor_system_info metric was not exporting
the Harbor version because the /api/v2.0/systeminfo endpoint now
requires authentication to return version information.

This change bakes the version into the exporter binary at build time
using ldflags, similar to how harbor-core handles versioning.

Changes:

  • Pass RELEASEVERSION and GITCOMMIT from root Makefile to photon Makefile
  • Add harbor_version and git_commit build args to exporter Docker build
  • Update exporter Dockerfile to use ldflags in go build command
  • Update system_collector.go to use version package directly instead
    of API response for version info

The exporter still calls the API for auth_mode and self_registration
(dynamic config), but now gets the version from the build-time
embedded values.

Please indicate you've done the following:

  • Well Written Title and Summary of the PR
  • Label the PR as needed. "release-note/ignore-for-release, release-note/new-feature, release-note/update, release-note/enhancement, release-note/community, release-note/breaking-change, release-note/docs, release-note/infra, release-note/deprecation"
  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Made sure tests are passing and test coverage is added if needed.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed in website repository.

Copilot AI review requested due to automatic review settings January 13, 2026 12:36
@Vad1mo Vad1mo requested a review from a team as a code owner January 13, 2026 12:36
@Vad1mo Vad1mo added the release-note/update Update or Fix label Jan 13, 2026
@Vad1mo Vad1mo enabled auto-merge (squash) January 13, 2026 12:37
@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.86%. Comparing base (c8c11b4) to head (f52ccba).
⚠️ Report is 615 commits behind head on main.

Files with missing lines Patch % Lines
src/pkg/exporter/system_collector.go 0.00% 8 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main   #22733       +/-   ##
===========================================
+ Coverage   45.36%   65.86%   +20.49%     
===========================================
  Files         244     1073      +829     
  Lines       13333   116280   +102947     
  Branches     2719     2931      +212     
===========================================
+ Hits         6049    76585    +70536     
- Misses       6983    35447    +28464     
- Partials      301     4248     +3947     
Flag Coverage Δ
unittests 65.86% <0.00%> (+20.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/pkg/exporter/system_collector.go 35.55% <0.00%> (ø)

... and 987 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the Harbor version reporting in the Prometheus exporter's harbor_system_info metric by baking the version into the binary at build time using ldflags, rather than relying on the authenticated /api/v2.0/systeminfo endpoint which now requires authentication to return version information.

Changes:

  • Modified build process to pass RELEASEVERSION and GITCOMMIT as Docker build arguments through the Makefile chain
  • Updated exporter Dockerfile to use ldflags during compilation to embed version information
  • Modified system_collector.go to retrieve version from the version package (set at build time) instead of from the API response

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
Makefile Added RELEASEVERSION and GITCOMMIT environment variables to be passed to photon Makefile
make/photon/Makefile Added harbor_version and git_commit build arguments to exporter Docker build command
make/photon/exporter/Dockerfile Added ARG declarations and ldflags to go build command to embed version at compile time
src/pkg/exporter/system_collector.go Updated to get version from version package instead of API response; API still called for dynamic config (auth_mode, self_registration)

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

Comment on lines +82 to 90
// Get version directly from package (set at build time via ldflags)
harborVersion := version.ReleaseVersion
if version.GitCommit != "" {
harborVersion = fmt.Sprintf("%s-%s", version.ReleaseVersion, version.GitCommit)
}

// Still call API for auth_mode and self_registration (dynamic config)
res, err := hbrCli.Get(sysInfoURL)
if err != nil {
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The version formatting logic differs from how core handles it. In src/controller/systeminfo/controller.go line 131, the version is always formatted as fmt.Sprintf("%s-%s", version.ReleaseVersion, version.GitCommit) without checking if GitCommit is empty. Here, the code only appends GitCommit if it's not empty. However, the Dockerfile default for git_commit is "unknown" (not empty), which means the condition will always be true, resulting in versions like "v2.0.0-unknown" when GITCOMMIT is not provided. For consistency with core's behavior, either: (1) remove the conditional check and always append GitCommit like core does, or (2) change the Dockerfile default to an empty string to make the check meaningful.

Suggested change
// Get version directly from package (set at build time via ldflags)
harborVersion := version.ReleaseVersion
if version.GitCommit != "" {
harborVersion = fmt.Sprintf("%s-%s", version.ReleaseVersion, version.GitCommit)
}
// Still call API for auth_mode and self_registration (dynamic config)
res, err := hbrCli.Get(sysInfoURL)
if err != nil {
// Get version directly from package (set at build time via ldflags),
// format it consistently with core as "<release>-<git_commit>".
harborVersion := fmt.Sprintf("%s-%s", version.ReleaseVersion, version.GitCommit)
// Still call API for auth_mode and self_registration (dynamic config)
res, err := hbrCli.Get(sysInfoURL)
if err != nil {
res, err := hbrCli.Get(sysInfoURL)
if err != nil {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/update Update or Fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants