Move source-tag to toplevel maglev.source-tag config, defaulting to short hostname, v1.1.2
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.1
|
VERSION := 1.1.2
|
||||||
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)
|
metrics.Register(reg, chkr, vppSrc, cfg.SourceTag)
|
||||||
reg.MustRegister(grpcMetrics)
|
reg.MustRegister(grpcMetrics)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|||||||
@@ -381,7 +381,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
// Config is the top-level parsed and validated configuration.
|
// Config is the top-level parsed and validated configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
SourceTag string // this node's nginx source tag; defaults to the short hostname
|
||||||
HealthChecker HealthCheckerConfig
|
HealthChecker HealthCheckerConfig
|
||||||
VPP VPPConfig
|
VPP VPPConfig
|
||||||
HealthChecks map[string]HealthCheck
|
HealthChecks map[string]HealthCheck
|
||||||
@@ -123,7 +124,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,6 +164,7 @@ type rawConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type rawMaglev struct {
|
type rawMaglev struct {
|
||||||
|
SourceTag string `yaml:"source-tag"`
|
||||||
HealthChecker rawHealthCheckerCfg `yaml:"healthchecker"`
|
HealthChecker rawHealthCheckerCfg `yaml:"healthchecker"`
|
||||||
VPP rawVPPCfg `yaml:"vpp"`
|
VPP rawVPPCfg `yaml:"vpp"`
|
||||||
HealthChecks map[string]rawHealthCheck `yaml:"healthchecks"`
|
HealthChecks map[string]rawHealthCheck `yaml:"healthchecks"`
|
||||||
@@ -219,7 +220,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,6 +301,18 @@ func parse(data []byte) (*Config, error) {
|
|||||||
func convert(r *rawMaglev) (*Config, error) {
|
func convert(r *rawMaglev) (*Config, error) {
|
||||||
cfg := &Config{}
|
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 --------------------------------------------------------
|
// ---- healthchecker --------------------------------------------------------
|
||||||
cfg.HealthChecker.Netns = r.HealthChecker.Netns
|
cfg.HealthChecker.Netns = r.HealthChecker.Netns
|
||||||
cfg.HealthChecker.TransitionHistory = r.HealthChecker.TransitionHistory
|
cfg.HealthChecker.TransitionHistory = r.HealthChecker.TransitionHistory
|
||||||
@@ -590,14 +602,9 @@ 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
-15
@@ -24,7 +24,6 @@ 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,8 +133,9 @@ var (
|
|||||||
type Collector struct {
|
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
|
||||||
|
|
||||||
backendInfo *prometheus.Desc
|
maglevInfo *prometheus.Desc
|
||||||
backendState *prometheus.Desc
|
backendState *prometheus.Desc
|
||||||
backendHealth *prometheus.Desc
|
backendHealth *prometheus.Desc
|
||||||
backendEnabled *prometheus.Desc
|
backendEnabled *prometheus.Desc
|
||||||
@@ -154,14 +154,15 @@ 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.
|
||||||
func NewCollector(src StateSource, vpp VPPSource) *Collector {
|
func NewCollector(src StateSource, vpp VPPSource, sourceTag string) *Collector {
|
||||||
return &Collector{
|
return &Collector{
|
||||||
src: src,
|
src: src,
|
||||||
vpp: vpp,
|
vpp: vpp,
|
||||||
backendInfo: prometheus.NewDesc(
|
sourceTag: sourceTag,
|
||||||
"maglev_backend_info",
|
maglevInfo: prometheus.NewDesc(
|
||||||
"Static backend metadata. Always 1; metadata is conveyed via labels.",
|
"maglev_info",
|
||||||
[]string{"backend", "address", "healthcheck", "source_tag"}, nil,
|
"Static maglevd instance metadata. Always 1; metadata is conveyed via labels.",
|
||||||
|
[]string{"source_tag"}, nil,
|
||||||
),
|
),
|
||||||
backendState: prometheus.NewDesc(
|
backendState: prometheus.NewDesc(
|
||||||
"maglev_backend_state",
|
"maglev_backend_state",
|
||||||
@@ -223,7 +224,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.maglevInfo
|
||||||
ch <- c.backendState
|
ch <- c.backendState
|
||||||
ch <- c.backendHealth
|
ch <- c.backendHealth
|
||||||
ch <- c.backendEnabled
|
ch <- c.backendEnabled
|
||||||
@@ -239,6 +240,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)
|
||||||
|
|
||||||
states := []health.State{
|
states := []health.State{
|
||||||
health.StateUnknown,
|
health.StateUnknown,
|
||||||
health.StateUp,
|
health.StateUp,
|
||||||
@@ -255,11 +258,6 @@ 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
|
||||||
@@ -356,8 +354,8 @@ 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.
|
||||||
func Register(reg prometheus.Registerer, src StateSource, vpp VPPSource) *Collector {
|
func Register(reg prometheus.Registerer, src StateSource, vpp VPPSource, sourceTag string) *Collector {
|
||||||
coll := NewCollector(src, vpp)
|
coll := NewCollector(src, vpp, sourceTag)
|
||||||
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