Skip to content

Commit

Permalink
feat: fix dangaling metrics regading status code (#146)
Browse files Browse the repository at this point in the history
* feat: fix dangaling metrics regading status code; add 2 additional metrics

* docs: update readme

* chore: rm new counter again

* docs: fix readme for metrics

* chore: added deprecation hint

Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>

---------

Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Co-authored-by: Bruno Bressi <bruno.bressi@telekom.de>
  • Loading branch information
y-eight and puffitos authored Jun 6, 2024
1 parent c19585a commit d55eefc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,14 @@ latency:

- `sparrow_latency_duration_seconds`
- Type: Gauge
- Description: Latency with status information of targets
- Description: Latency with status information of targets. This metric is DEPRECATED. Use `sparrow_latency_seconds`.
- Labelled with `target` and `status`

- `sparrow_latency_seconds`
- Type: Gauge
- Description: Latency information of targets
- Labelled with `target`

- `sparrow_latency_count`
- Type: Counter
- Description: Count of latency checks done
Expand Down
23 changes: 19 additions & 4 deletions pkg/checks/latency/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ type result struct {

// metrics defines the metric collectors of the latency check
type metrics struct {
duration *prometheus.GaugeVec
count *prometheus.CounterVec
histogram *prometheus.HistogramVec
duration *prometheus.GaugeVec
totalDuration *prometheus.GaugeVec
count *prometheus.CounterVec
histogram *prometheus.HistogramVec
}

// Run starts the latency check
Expand Down Expand Up @@ -149,13 +150,22 @@ func newMetrics() metrics {
duration: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "sparrow_latency_duration_seconds",
Help: "Latency with status information of targets",
Help: "DEPRECATED Latency with status information of targets. Use sparrow_latency_seconds.",
},
[]string{
"target",
"status",
},
),
totalDuration: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "sparrow_latency_seconds",
Help: "Latency for each target",
},
[]string{
"target",
},
),
count: prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "sparrow_latency_count",
Expand All @@ -181,6 +191,7 @@ func newMetrics() metrics {
func (l *Latency) GetMetricCollectors() []prometheus.Collector {
return []prometheus.Collector{
l.metrics.duration,
l.metrics.totalDuration,
l.metrics.count,
l.metrics.histogram,
}
Expand Down Expand Up @@ -231,7 +242,11 @@ func (l *Latency) check(ctx context.Context) map[string]result {
lo.Debug("Successfully got latency status of target")
mu.Lock()
defer mu.Unlock()

l.metrics.duration.DeletePartialMatch(prometheus.Labels{"target": target})
l.metrics.duration.WithLabelValues(target, strconv.Itoa(results[target].Code)).Set(results[target].Total)
l.metrics.totalDuration.WithLabelValues(target).Set(results[target].Total)
l.metrics.count.WithLabelValues(target).Inc()
l.metrics.histogram.WithLabelValues(target).Observe(results[target].Total)
l.metrics.count.WithLabelValues(target).Inc()
}()
Expand Down

0 comments on commit d55eefc

Please sign in to comment.