diff --git a/Makefile b/Makefile index 3904394..2e4de75 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ FRONTEND_WEB_SRC := $(shell find cmd/frontend/web/src -type f 2>/dev/null) \ FRONTEND_WEB_DIST := cmd/frontend/web/dist/index.html NATIVE_ARCH := $(shell go env GOARCH) -VERSION := 1.1.2 +VERSION := 1.1.3 COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ) LDFLAGS := -X '$(MODULE)/cmd.version=$(VERSION)' \ diff --git a/cmd/server/main.go b/cmd/server/main.go index 5487efc..6e555b1 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -150,7 +150,7 @@ func run() error { if vppClient != nil { vppSrc = vppClient } - metrics.Register(reg, chkr, vppSrc, cfg.SourceTag) + metrics.Register(reg, chkr, vppSrc, cfg.SourceTag, buildinfo.Version(), buildinfo.Commit()) reg.MustRegister(grpcMetrics) mux := http.NewServeMux() diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index df4bd5b..83ee5a8 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -134,6 +134,8 @@ type Collector struct { src StateSource vpp VPPSource // optional; nil when VPP integration is disabled sourceTag string + version string + commit string maglevInfo *prometheus.Desc backendState *prometheus.Desc @@ -153,16 +155,18 @@ type Collector struct { // NewCollector creates a Collector backed by the given StateSource. vpp may // be nil when VPP integration is disabled; in that case vpp_* metrics are -// simply not emitted. -func NewCollector(src StateSource, vpp VPPSource, sourceTag string) *Collector { +// simply not emitted. version and commit are surfaced via maglev_info labels. +func NewCollector(src StateSource, vpp VPPSource, sourceTag, version, commit string) *Collector { return &Collector{ src: src, vpp: vpp, sourceTag: sourceTag, + version: version, + commit: commit, maglevInfo: prometheus.NewDesc( "maglev_info", "Static maglevd instance metadata. Always 1; metadata is conveyed via labels.", - []string{"source_tag"}, nil, + []string{"source_tag", "version", "commit"}, nil, ), backendState: prometheus.NewDesc( "maglev_backend_state", @@ -240,7 +244,8 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) { // Collect implements prometheus.Collector. func (c *Collector) Collect(ch chan<- prometheus.Metric) { - ch <- prometheus.MustNewConstMetric(c.maglevInfo, prometheus.GaugeValue, 1.0, c.sourceTag) + ch <- prometheus.MustNewConstMetric(c.maglevInfo, prometheus.GaugeValue, 1.0, + c.sourceTag, c.version, c.commit) states := []health.State{ health.StateUnknown, @@ -353,9 +358,10 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { } // Register registers all metrics with the given registry. vpp may be nil -// to disable VPP-related metrics. -func Register(reg prometheus.Registerer, src StateSource, vpp VPPSource, sourceTag string) *Collector { - coll := NewCollector(src, vpp, sourceTag) +// to disable VPP-related metrics. version / commit are surfaced via +// maglev_info labels. +func Register(reg prometheus.Registerer, src StateSource, vpp VPPSource, sourceTag, version, commit string) *Collector { + coll := NewCollector(src, vpp, sourceTag, version, commit) reg.MustRegister(coll) reg.MustRegister(ProbeTotal) reg.MustRegister(ProbeDuration)