From 54dc5efc77ef20abed5164d33c4136fdbb050ef3 Mon Sep 17 00:00:00 2001 From: Rory Z <16801068+Rory-Z@users.noreply.github.com> Date: Wed, 8 Nov 2023 10:39:50 +0800 Subject: [PATCH] feat(probe): add target labels Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com> --- main_test.go | 11 ++++++++--- prober/handler.go | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/main_test.go b/main_test.go index a0cb51b..2c0d98e 100644 --- a/main_test.go +++ b/main_test.go @@ -361,9 +361,14 @@ var _ = Describe("Check EMQX Exporter Probe", Label("probes"), func() { WithTransform(func(m *dto.MetricFamily) dto.MetricType { return m.GetType() }, Equal(dto.MetricType_GAUGE)), - WithTransform(func(m *dto.MetricFamily) int { - return int(*m.Metric[0].Gauge.Value) - }, Equal(1)), + WithTransform(func(m *dto.MetricFamily) float64 { + return *m.GetMetric()[0].Gauge.Value + }, BeNumerically("==", 1)), + WithTransform(func(m *dto.MetricFamily) map[string]string { + return map[string]string{ + m.GetMetric()[0].Label[0].GetName(): m.GetMetric()[0].Label[0].GetValue(), + } + }, HaveKeyWithValue("target", target)), )), )) diff --git a/prober/handler.go b/prober/handler.go index 0560589..d2be2d1 100644 --- a/prober/handler.go +++ b/prober/handler.go @@ -38,12 +38,18 @@ func Handler(w http.ResponseWriter, r *http.Request, probes []config.Probe, logg Subsystem: "mqtt", Name: "probe_success", Help: "Displays whether or not the probe was a success", + ConstLabels: prometheus.Labels{ + "target": probe.Target, + }, }) probeDurationGauge := prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: "emqx", Subsystem: "mqtt", Name: "probe_duration_seconds", Help: "Returns how long the probe took to complete in seconds", + ConstLabels: prometheus.Labels{ + "target": probe.Target, + }, }) registry := prometheus.NewRegistry()