Skip to content

Commit

Permalink
feat: improve Owned Streams feature observability (#13232)
Browse files Browse the repository at this point in the history
Signed-off-by: Vladyslav Diachenko <vlad.diachenko@grafana.com>
  • Loading branch information
vlad-diachenko authored Jun 18, 2024
1 parent b7fcf2b commit ce86459
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/ingester/owned_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,13 +60,15 @@ func (s *ownedStreamService) incOwnedStreamCount() {
func (s *ownedStreamService) incNotOwnedStreamCount() {
s.lock.Lock()
defer s.lock.Unlock()
notOwnedStreamsMetric.WithLabelValues(s.tenantID).Inc()
s.notOwnedStreamCount++
}

func (s *ownedStreamService) decOwnedStreamCount() {
s.lock.Lock()
defer s.lock.Unlock()
if s.notOwnedStreamCount > 0 {
notOwnedStreamsMetric.WithLabelValues(s.tenantID).Dec()
s.notOwnedStreamCount--
return
}
Expand All @@ -71,4 +80,5 @@ func (s *ownedStreamService) resetStreamCounts() {
defer s.lock.Unlock()
s.ownedStreamCount = 0
s.notOwnedStreamCount = 0
notOwnedStreamsMetric.WithLabelValues(s.tenantID).Set(0)
}

0 comments on commit ce86459

Please sign in to comment.