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