-
Notifications
You must be signed in to change notification settings - Fork 5.1k
fix(exporter): bake Harbor version into exporter binary at build time #22733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(exporter): bake Harbor version into exporter binary at build time #22733
Conversation
Signed-off-by: Vadim Bauer <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this 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.
| // 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 { |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
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.
| // 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 { |
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:
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: