3 Commits

4 changed files with 34 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.0
VERSION := 1.1.2
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)
metrics.Register(reg, chkr, vppSrc, cfg.SourceTag)
reg.MustRegister(grpcMetrics)
mux := http.NewServeMux()
+14
View File
@@ -17,6 +17,7 @@ import (
// Config is the top-level parsed and validated configuration.
type Config struct {
SourceTag string // this node's nginx source tag; defaults to the short hostname
HealthChecker HealthCheckerConfig
VPP VPPConfig
HealthChecks map[string]HealthCheck
@@ -163,6 +164,7 @@ type rawConfig struct {
}
type rawMaglev struct {
SourceTag string `yaml:"source-tag"`
HealthChecker rawHealthCheckerCfg `yaml:"healthchecker"`
VPP rawVPPCfg `yaml:"vpp"`
HealthChecks map[string]rawHealthCheck `yaml:"healthchecks"`
@@ -299,6 +301,18 @@ func parse(data []byte) (*Config, error) {
func convert(r *rawMaglev) (*Config, error) {
cfg := &Config{}
// ---- source-tag -----------------------------------------------------------
cfg.SourceTag = r.SourceTag
if cfg.SourceTag == "" {
if h, err := os.Hostname(); err == nil {
if dot := strings.IndexByte(h, '.'); dot > 0 {
cfg.SourceTag = h[:dot]
} else {
cfg.SourceTag = h
}
}
}
// ---- healthchecker --------------------------------------------------------
cfg.HealthChecker.Netns = r.HealthChecker.Netns
cfg.HealthChecker.TransitionHistory = r.HealthChecker.TransitionHistory
+18 -7
View File
@@ -131,9 +131,11 @@ var (
// on each scrape. This avoids stale label sets when backends are added or
// removed by a config reload.
type Collector struct {
src StateSource
vpp VPPSource // optional; nil when VPP integration is disabled
src StateSource
vpp VPPSource // optional; nil when VPP integration is disabled
sourceTag string
maglevInfo *prometheus.Desc
backendState *prometheus.Desc
backendHealth *prometheus.Desc
backendEnabled *prometheus.Desc
@@ -152,10 +154,16 @@ 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) *Collector {
func NewCollector(src StateSource, vpp VPPSource, sourceTag string) *Collector {
return &Collector{
src: src,
vpp: vpp,
src: src,
vpp: vpp,
sourceTag: sourceTag,
maglevInfo: prometheus.NewDesc(
"maglev_info",
"Static maglevd instance metadata. Always 1; metadata is conveyed via labels.",
[]string{"source_tag"}, nil,
),
backendState: prometheus.NewDesc(
"maglev_backend_state",
"Current backend state (1 = active for the given state label).",
@@ -216,6 +224,7 @@ func NewCollector(src StateSource, vpp VPPSource) *Collector {
// Describe implements prometheus.Collector.
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.maglevInfo
ch <- c.backendState
ch <- c.backendHealth
ch <- c.backendEnabled
@@ -231,6 +240,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)
states := []health.State{
health.StateUnknown,
health.StateUp,
@@ -343,8 +354,8 @@ 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) *Collector {
coll := NewCollector(src, vpp)
func Register(reg prometheus.Registerer, src StateSource, vpp VPPSource, sourceTag string) *Collector {
coll := NewCollector(src, vpp, sourceTag)
reg.MustRegister(coll)
reg.MustRegister(ProbeTotal)
reg.MustRegister(ProbeDuration)