mirror of https://github.com/hashicorp/boundary
feat(metrics): add build info metric on server start (#1984)
Adds a Prometheus gauge metric set to the value of 1, with labels for go version, git revision, and Boundary version. Assigns the Prometheus DefaultRegisterer to the Server struct as a parameter to NewServer(), to avoid "duplicate metrics collector registration" panics from test cases.pull/2009/head
parent
8d80d10ff7
commit
e3f72bd0a4
@ -0,0 +1,50 @@
|
||||
// Package metric provides functions to initialize a prometheus metric
|
||||
// detailing build info
|
||||
package metric
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/version"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const (
|
||||
labelGoVersion = "goversion"
|
||||
labelGitRevision = "revision"
|
||||
labelBoundaryVersion = "version"
|
||||
)
|
||||
|
||||
// buildInfoVec is a gauge metric whose value is always equal to 1 and whose
|
||||
// labels contain the current go version, git revision, and boundary version.
|
||||
var buildInfoVec = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Namespace: globals.MetricNamespace,
|
||||
Name: "build_info",
|
||||
Help: "Gauge with labels describing go version, git revision hash, and Boundary release version.",
|
||||
},
|
||||
[]string{labelGoVersion, labelGitRevision, labelBoundaryVersion},
|
||||
)
|
||||
|
||||
func retrieveBuildInfoLabels() map[string]string {
|
||||
verInfo := version.Get()
|
||||
|
||||
return map[string]string{
|
||||
labelGoVersion: runtime.Version(),
|
||||
labelGitRevision: verInfo.Revision,
|
||||
labelBoundaryVersion: verInfo.Version,
|
||||
}
|
||||
}
|
||||
|
||||
// InitializeBuildInfo registers the boundary_build_info metric with its
|
||||
// correct labels and sets its value to 1.
|
||||
func InitializeBuildInfo(r prometheus.Registerer) {
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
r.MustRegister(buildInfoVec)
|
||||
l := prometheus.Labels(retrieveBuildInfoLabels())
|
||||
buildInfoVec.With(l).Set(float64(1))
|
||||
}
|
||||
Loading…
Reference in new issue