Skip to content

Commit

Permalink
Fix: telemetry region label (#638)
Browse files Browse the repository at this point in the history
Telemetry metrics should reference the check region, therefore use the
region ID extracted from the global check ID.
  • Loading branch information
ka3de authored Feb 29, 2024
1 parent f6fb2cc commit e06edba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
1 change: 0 additions & 1 deletion internal/scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ func (s *Scraper) Run(ctx context.Context) {
s.telemeter.AddExecution(telemetry.Execution{
LocalTenantID: s.check.TenantId,
RegionID: int32(s.check.RegionId),
Region: s.probe.Region,
CheckClass: s.check.Class(),
Duration: end.Sub(start),
})
Expand Down
18 changes: 9 additions & 9 deletions internal/telemetry/telemeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package telemetry

import (
"context"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -40,7 +41,6 @@ type metrics struct {
type Execution struct {
LocalTenantID int64
RegionID int32
Region string
CheckClass sm.CheckClass
Duration time.Duration
}
Expand Down Expand Up @@ -89,11 +89,11 @@ func (t *Telemeter) AddExecution(e Execution) {
// If we do not have a pusher for this region, create it
l := t.logger.With().
Str("component", "region-pusher").
Str("agent_instance", t.instance).
Str("region", e.Region).
Str("agentInstance", t.instance).
Int32("regionId", e.RegionID).
Logger()
labels := prom.Labels{
"region": e.Region,
"region_id": strconv.FormatInt(int64(e.RegionID), 10),
}
m := RegionMetrics{
t.metrics.pushRequestsActive.With(labels),
Expand All @@ -118,29 +118,29 @@ func (t *Telemeter) registerMetrics(registerer prom.Registerer) {
Name: "push_requests_active",
Help: "Active push telemetry requests",
ConstLabels: prom.Labels{"agent_instance": t.instance},
}, []string{"region"})
}, []string{"region_id"})
t.metrics.pushRequestsDuration = prom.NewHistogramVec(prom.HistogramOpts{
Namespace: "sm_agent",
Subsystem: "telemetry",
Name: "push_requests_duration_seconds",
Help: "Duration of push telemetry requests",
Buckets: prom.ExponentialBucketsRange(0.01, 2.0, 10),
ConstLabels: prom.Labels{"agent_instance": t.instance},
}, []string{"region"})
}, []string{"region_id"})
t.metrics.pushRequestsTotal = prom.NewCounterVec(prom.CounterOpts{
Namespace: "sm_agent",
Subsystem: "telemetry",
Name: "push_requests_total",
Help: "Total count of push telemetry requests",
ConstLabels: prom.Labels{"agent_instance": t.instance},
}, []string{"region"})
}, []string{"region_id"})
t.metrics.pushRequestsError = prom.NewCounterVec(prom.CounterOpts{
Namespace: "sm_agent",
Subsystem: "telemetry",
Name: "push_requests_errors_total",
Help: "Total count of errored push telemetry requests",
ConstLabels: prom.Labels{"agent_instance": t.instance},
}, []string{"region"})
}, []string{"region_id"})

t.metrics.addExecutionDuration = prom.NewHistogramVec(prom.HistogramOpts{
Namespace: "sm_agent",
Expand All @@ -152,7 +152,7 @@ func (t *Telemeter) registerMetrics(registerer prom.Registerer) {
NativeHistogramMaxBucketNumber: 100,
NativeHistogramMinResetDuration: time.Hour,
ConstLabels: prom.Labels{"agent_instance": t.instance},
}, []string{"region"})
}, []string{"region_id"})

registerer.MustRegister(t.metrics.pushRequestsActive)
registerer.MustRegister(t.metrics.pushRequestsDuration)
Expand Down

0 comments on commit e06edba

Please sign in to comment.