-
Notifications
You must be signed in to change notification settings - Fork 535
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
Fill in version information #962
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e69383a
Fill in version information
andyasp ccf450a
Format makefiles
andyasp 5ed74fd
Add defaults and base date off commit
andyasp 6da4b47
Transition to using internal version
andyasp b769814
Default to unknown directly
andyasp 1cd3b37
Merge branch 'main' into aasp/version-information
pstibrany File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Provenance-includes-location: https://github.com/prometheus/common/blob/main/version/info.go | ||
// Provenance-includes-license: Apache-2.0 | ||
// Provenance-includes-copyright: The Prometheus Authors. | ||
|
||
package version | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
"text/template" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// Build information. Populated at build-time. | ||
// Note: Removed BuildUser and BuildDate for reproducible builds | ||
var ( | ||
Version string = "unknown" | ||
Revision string = "unknown" | ||
Branch string = "unknown" | ||
GoVersion = runtime.Version() | ||
) | ||
|
||
// NewCollector returns a collector that exports metrics about current version | ||
// information. | ||
func NewCollector(program string) prometheus.Collector { | ||
return prometheus.NewGaugeFunc( | ||
prometheus.GaugeOpts{ | ||
Namespace: program, | ||
Name: "build_info", | ||
Help: fmt.Sprintf( | ||
"A metric with a constant '1' value labeled by version, revision, branch, and goversion from which %s was built.", | ||
program, | ||
), | ||
ConstLabels: prometheus.Labels{ | ||
"version": Version, | ||
"revision": Revision, | ||
"branch": Branch, | ||
"goversion": GoVersion, | ||
}, | ||
}, | ||
func() float64 { return 1 }, | ||
) | ||
} | ||
|
||
// versionInfoTmpl contains the template used by Info. | ||
var versionInfoTmpl = ` | ||
{{.program}}, version {{.version}} (branch: {{.branch}}, revision: {{.revision}}) | ||
go version: {{.goVersion}} | ||
platform: {{.platform}} | ||
` | ||
|
||
// Print returns version information. | ||
func Print(program string) string { | ||
m := map[string]string{ | ||
"program": program, | ||
"version": Version, | ||
"revision": Revision, | ||
"branch": Branch, | ||
"goVersion": GoVersion, | ||
"platform": runtime.GOOS + "/" + runtime.GOARCH, | ||
} | ||
t := template.Must(template.New("version").Parse(versionInfoTmpl)) | ||
|
||
var buf bytes.Buffer | ||
if err := t.ExecuteTemplate(&buf, "version", m); err != nil { | ||
panic(err) | ||
} | ||
return strings.TrimSpace(buf.String()) | ||
} | ||
|
||
// Info returns version, branch and revision information. | ||
func Info() string { | ||
return fmt.Sprintf("(version=%s, branch=%s, revision=%s)", Version, Branch, Revision) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shall we change
cortex
tomimir
here? It would changecortex_build_info
tomimir_build_info
, and this needs to be documented in CHANGELOG. I don't see this metric used anywhere in our jsonnet or internal tooling. (Can be separate PR too)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.
I think that makes a lot of sense given that this is no longer cortex build information. Probably best to do it in another PR though since I'm unaware of what the plans are for metric renaming.
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.
In general we plan to keep metrics as-is. However in this specific case, I think it makes sense to rename. But we can discuss that separately.
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.
Opened #1022