v1.1.3: surface daemon version + commit on maglev_info

Extend the existing maglev_info gauge with two more labels:
- version (build version, from -ldflags)
- commit (git short hash)

Mirrors nginx_ipng_stats-plugin's nginx_ipng_info pattern: a
label-only gauge value=1 carrying build metadata for Prometheus
to query and Grafana dashboards to render. Useful for spotting
version drift across the fleet with a single query, and for
populating the "Version" column of the Maglev Nodes table on
the global overview.

Existing label source_tag is preserved.

Plumbing: NewCollector / Register signatures gain version and
commit string parameters; main.go reads them from cmd.Version()
and cmd.Commit() (already imported as 'buildinfo').
This commit is contained in:
2026-05-01 23:20:03 +02:00
parent dc7599f3ee
commit d2ee6d009e
3 changed files with 15 additions and 9 deletions
+1 -1
View File
@@ -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)' \
+1 -1
View File
@@ -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()
+13 -7
View File
@@ -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)