2 Commits

Author SHA1 Message Date
Pim van Pelt f16cf7cb14 Tag v1.1.1 with source_tag attribution in Prometheus 2026-05-01 15:22:37 +02:00
Pim van Pelt 86b265c2a9 Add maglev_backend_info variable that correlates backend/address/healthcheck/source_tag 2026-05-01 15:19:19 +02:00
4 changed files with 29 additions and 8 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 FRONTEND_WEB_DIST := cmd/frontend/web/dist/index.html
NATIVE_ARCH := $(shell go env GOARCH) NATIVE_ARCH := $(shell go env GOARCH)
VERSION := 1.1.0 VERSION := 1.1.1
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
View File
@@ -381,6 +381,7 @@ func (c *Checker) GetBackendInfo(name string) (metrics.BackendInfo, bool) {
Health: w.backend, Health: w.backend,
Enabled: w.entry.Enabled, Enabled: w.entry.Enabled,
HCName: w.entry.HealthCheck, HCName: w.entry.HealthCheck,
SourceTag: w.entry.SourceTag,
}, true }, true
} }
+7
View File
@@ -123,6 +123,7 @@ type TCPParams struct {
type Backend struct { type Backend struct {
Address net.IP Address net.IP
HealthCheck string // name reference into Config.HealthChecks; "" = no probing, assume healthy HealthCheck string // name reference into Config.HealthChecks; "" = no probing, assume healthy
SourceTag string // nginx source tag; defaults to the backend name if omitted from config
Enabled bool // default true; false = exclude from serving entirely Enabled bool // default true; false = exclude from serving entirely
} }
@@ -218,6 +219,7 @@ type rawParams struct {
type rawBackend struct { type rawBackend struct {
Address string `yaml:"address"` Address string `yaml:"address"`
HealthCheck string `yaml:"healthcheck"` HealthCheck string `yaml:"healthcheck"`
SourceTag string `yaml:"source-tag"` // defaults to backend name if omitted
Enabled *bool `yaml:"enabled"` // nil → default true Enabled *bool `yaml:"enabled"` // nil → default true
} }
@@ -588,9 +590,14 @@ func convertBackend(name string, r *rawBackend, hcs map[string]HealthCheck) (Bac
return Backend{}, fmt.Errorf("invalid address %q", r.Address) return Backend{}, fmt.Errorf("invalid address %q", r.Address)
} }
sourceTag := r.SourceTag
if sourceTag == "" {
sourceTag = name
}
b := Backend{ b := Backend{
Address: ip, Address: ip,
HealthCheck: r.HealthCheck, HealthCheck: r.HealthCheck,
SourceTag: sourceTag,
Enabled: boolDefault(r.Enabled, true), Enabled: boolDefault(r.Enabled, true),
} }
+13
View File
@@ -24,6 +24,7 @@ type BackendInfo struct {
Health *health.Backend Health *health.Backend
Enabled bool Enabled bool
HCName string // healthcheck name from config HCName string // healthcheck name from config
SourceTag string // nginx source tag; equals backend name when unset in config
} }
// StateSource provides read-only access to the running checker state. // StateSource provides read-only access to the running checker state.
@@ -134,6 +135,7 @@ 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
backendInfo *prometheus.Desc
backendState *prometheus.Desc backendState *prometheus.Desc
backendHealth *prometheus.Desc backendHealth *prometheus.Desc
backendEnabled *prometheus.Desc backendEnabled *prometheus.Desc
@@ -156,6 +158,11 @@ func NewCollector(src StateSource, vpp VPPSource) *Collector {
return &Collector{ return &Collector{
src: src, src: src,
vpp: vpp, vpp: vpp,
backendInfo: prometheus.NewDesc(
"maglev_backend_info",
"Static backend metadata. Always 1; metadata is conveyed via labels.",
[]string{"backend", "address", "healthcheck", "source_tag"}, nil,
),
backendState: prometheus.NewDesc( backendState: prometheus.NewDesc(
"maglev_backend_state", "maglev_backend_state",
"Current backend state (1 = active for the given state label).", "Current backend state (1 = active for the given state label).",
@@ -216,6 +223,7 @@ func NewCollector(src StateSource, vpp VPPSource) *Collector {
// Describe implements prometheus.Collector. // Describe implements prometheus.Collector.
func (c *Collector) Describe(ch chan<- *prometheus.Desc) { func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.backendInfo
ch <- c.backendState ch <- c.backendState
ch <- c.backendHealth ch <- c.backendHealth
ch <- c.backendEnabled ch <- c.backendEnabled
@@ -247,6 +255,11 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
} }
addr := info.Health.Address.String() addr := info.Health.Address.String()
ch <- prometheus.MustNewConstMetric(
c.backendInfo, prometheus.GaugeValue, 1.0,
name, addr, info.HCName, info.SourceTag,
)
// One time-series per possible state; the current state is 1, rest 0. // One time-series per possible state; the current state is 1, rest 0.
for _, s := range states { for _, s := range states {
val := 0.0 val := 0.0