From ce8645900e76db962af36794c70d1e3662009ded Mon Sep 17 00:00:00 2001 From: Vladyslav Diachenko <82767850+vlad-diachenko@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:58:33 +0300 Subject: [PATCH] feat: improve Owned Streams feature observability (#13232) Signed-off-by: Vladyslav Diachenko --- pkg/ingester/owned_streams.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/ingester/owned_streams.go b/pkg/ingester/owned_streams.go index 7a405d684dc5..db9d0e94715f 100644 --- a/pkg/ingester/owned_streams.go +++ b/pkg/ingester/owned_streams.go @@ -3,13 +3,20 @@ package ingester import ( "sync" - "github.com/grafana/dskit/services" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "go.uber.org/atomic" + + "github.com/grafana/loki/v3/pkg/util/constants" ) -type ownedStreamService struct { - services.Service +var notOwnedStreamsMetric = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: constants.Loki, + Name: "ingester_not_owned_streams", + Help: "The total number of not owned streams in memory per tenant.", +}, []string{"tenant"}) +type ownedStreamService struct { tenantID string limiter *Limiter fixedLimit *atomic.Int32 @@ -53,6 +60,7 @@ func (s *ownedStreamService) incOwnedStreamCount() { func (s *ownedStreamService) incNotOwnedStreamCount() { s.lock.Lock() defer s.lock.Unlock() + notOwnedStreamsMetric.WithLabelValues(s.tenantID).Inc() s.notOwnedStreamCount++ } @@ -60,6 +68,7 @@ func (s *ownedStreamService) decOwnedStreamCount() { s.lock.Lock() defer s.lock.Unlock() if s.notOwnedStreamCount > 0 { + notOwnedStreamsMetric.WithLabelValues(s.tenantID).Dec() s.notOwnedStreamCount-- return } @@ -71,4 +80,5 @@ func (s *ownedStreamService) resetStreamCounts() { defer s.lock.Unlock() s.ownedStreamCount = 0 s.notOwnedStreamCount = 0 + notOwnedStreamsMetric.WithLabelValues(s.tenantID).Set(0) }