Skip to content

Commit

Permalink
Add platform info to labels
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Comellini <[email protected]>
  • Loading branch information
lucacome committed Nov 11, 2022
1 parent 8c9cb3f commit d4d71e3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions version/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var (
BuildUser string
BuildDate string
GoVersion = runtime.Version()
GoOS = runtime.GOOS
GoArch = runtime.GOARCH
)

// NewCollector returns a collector that exports metrics about current version
Expand All @@ -41,14 +43,16 @@ func NewCollector(program string) prometheus.Collector {
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.",
"A metric with a constant '1' value labeled by version, revision, branch, goversion from which %s was built, and the goos and goarch for the build.",
program,
),
ConstLabels: prometheus.Labels{
"version": Version,
"revision": Revision,
"branch": Branch,
"goversion": GoVersion,
"os": GoOS,
"arch": GoArch,
},
},
func() float64 { return 1 },
Expand All @@ -74,7 +78,7 @@ func Print(program string) string {
"buildUser": BuildUser,
"buildDate": BuildDate,
"goVersion": GoVersion,
"platform": runtime.GOOS + "/" + runtime.GOARCH,
"platform": GoOS + "/" + GoArch,
}
t := template.Must(template.New("version").Parse(versionInfoTmpl))

Expand All @@ -90,7 +94,7 @@ func Info() string {
return fmt.Sprintf("(version=%s, branch=%s, revision=%s)", Version, Branch, Revision)
}

// BuildContext returns goVersion, buildUser and buildDate information.
// BuildContext returns goVersion, platform, buildUser and buildDate information.
func BuildContext() string {
return fmt.Sprintf("(go=%s, user=%s, date=%s)", GoVersion, BuildUser, BuildDate)
return fmt.Sprintf("(go=%s, platform=%s, user=%s, date=%s)", GoVersion, GoOS+"/"+GoArch, BuildUser, BuildDate)
}

0 comments on commit d4d71e3

Please sign in to comment.