Skip to content

Commit ce86459

Browse files
feat: improve Owned Streams feature observability (#13232)
Signed-off-by: Vladyslav Diachenko <[email protected]>
1 parent b7fcf2b commit ce86459

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pkg/ingester/owned_streams.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ package ingester
33
import (
44
"sync"
55

6-
"github.com/grafana/dskit/services"
6+
"github.com/prometheus/client_golang/prometheus"
7+
"github.com/prometheus/client_golang/prometheus/promauto"
78
"go.uber.org/atomic"
9+
10+
"github.com/grafana/loki/v3/pkg/util/constants"
811
)
912

10-
type ownedStreamService struct {
11-
services.Service
13+
var notOwnedStreamsMetric = promauto.NewGaugeVec(prometheus.GaugeOpts{
14+
Namespace: constants.Loki,
15+
Name: "ingester_not_owned_streams",
16+
Help: "The total number of not owned streams in memory per tenant.",
17+
}, []string{"tenant"})
1218

19+
type ownedStreamService struct {
1320
tenantID string
1421
limiter *Limiter
1522
fixedLimit *atomic.Int32
@@ -53,13 +60,15 @@ func (s *ownedStreamService) incOwnedStreamCount() {
5360
func (s *ownedStreamService) incNotOwnedStreamCount() {
5461
s.lock.Lock()
5562
defer s.lock.Unlock()
63+
notOwnedStreamsMetric.WithLabelValues(s.tenantID).Inc()
5664
s.notOwnedStreamCount++
5765
}
5866

5967
func (s *ownedStreamService) decOwnedStreamCount() {
6068
s.lock.Lock()
6169
defer s.lock.Unlock()
6270
if s.notOwnedStreamCount > 0 {
71+
notOwnedStreamsMetric.WithLabelValues(s.tenantID).Dec()
6372
s.notOwnedStreamCount--
6473
return
6574
}
@@ -71,4 +80,5 @@ func (s *ownedStreamService) resetStreamCounts() {
7180
defer s.lock.Unlock()
7281
s.ownedStreamCount = 0
7382
s.notOwnedStreamCount = 0
83+
notOwnedStreamsMetric.WithLabelValues(s.tenantID).Set(0)
7484
}

0 commit comments

Comments
 (0)