Skip to content

Commit 5c6d4ae

Browse files
committed
metric integration
Signed-off-by: Owen Diehl <[email protected]>
1 parent c2a1ae8 commit 5c6d4ae

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

pkg/storage/bloom/v1/bloom_tokenizer.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,7 @@ func (bt *BloomTokenizer) Populate(
137137
// If a bloom is full, the chunk wasn't completely added
138138
// so we'll submit this bloom, start a new one, and continue indexing
139139
if full {
140-
ch <- &BloomCreation{
141-
Bloom: bloom,
142-
SourceBytesAdded: bytesAdded,
143-
}
140+
bt.sendBloom(ch, bloom, bytesAdded)
144141

145142
// start a new bloom + reset bytesAdded counter
146143
bytesAdded = 0
@@ -158,11 +155,26 @@ func (bt *BloomTokenizer) Populate(
158155
}
159156

160157
// Send the last bloom
158+
bt.sendBloom(ch, bloom, bytesAdded)
159+
close(ch)
160+
}
161+
162+
func (bt *BloomTokenizer) sendBloom(
163+
ch chan<- *BloomCreation,
164+
bloom *Bloom,
165+
bytesAdded int,
166+
) {
167+
fillRatio := bloom.ScalableBloomFilter.FillRatio()
168+
bt.metrics.hammingWeightRatio.Observe(fillRatio)
169+
bt.metrics.estimatedCount.Observe(
170+
float64(estimatedCount(bloom.ScalableBloomFilter.Capacity(), fillRatio)),
171+
)
172+
bt.metrics.bloomSize.Observe(float64(bloom.ScalableBloomFilter.Capacity() / eightBits))
173+
bt.metrics.bloomsTotal.Inc()
161174
ch <- &BloomCreation{
162175
Bloom: bloom,
163176
SourceBytesAdded: bytesAdded,
164177
}
165-
close(ch)
166178
}
167179

168180
// addChunkToBloom adds the tokens from the given chunk to the given bloom.

pkg/storage/bloom/v1/metrics.go

+6-15
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import (
99

1010
type Metrics struct {
1111
// writes
12-
bloomsTotal *prometheus.CounterVec // number of blooms created
13-
sbfCreationTime *prometheus.CounterVec // time spent creating sbfs
14-
bloomSize prometheus.Histogram // size of the bloom filter in bytes
15-
hammingWeightRatio prometheus.Histogram // ratio of the hamming weight of the bloom filter to the number of bits in the bloom filter
16-
estimatedCount prometheus.Histogram // estimated number of elements in the bloom filter
12+
bloomsTotal prometheus.Counter // number of blooms created
13+
bloomSize prometheus.Histogram // size of the bloom filter in bytes
14+
hammingWeightRatio prometheus.Histogram // ratio of the hamming weight of the bloom filter to the number of bits in the bloom filter
15+
estimatedCount prometheus.Histogram // estimated number of elements in the bloom filter
1716
chunksIndexed *prometheus.CounterVec
1817
chunksPerSeries prometheus.Histogram
1918
blockSeriesIterated prometheus.Counter
@@ -51,9 +50,6 @@ const (
5150
skipReasonErr = "err"
5251
skipReasonOOB = "out_of_bounds"
5352

54-
bloomCreationTypeIndexed = "indexed"
55-
bloomCreationTypeSkipped = "skipped"
56-
5753
recorderRequested = "requested"
5854
recorderFound = "found"
5955
recorderSkipped = "skipped"
@@ -63,16 +59,11 @@ const (
6359

6460
func NewMetrics(r prometheus.Registerer) *Metrics {
6561
return &Metrics{
66-
bloomsTotal: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
62+
bloomsTotal: promauto.With(r).NewCounter(prometheus.CounterOpts{
6763
Namespace: constants.Loki,
6864
Name: "blooms_created_total",
6965
Help: "Number of blooms created",
70-
}, []string{"type"}),
71-
sbfCreationTime: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
72-
Namespace: constants.Loki,
73-
Name: "bloom_creation_time_total",
74-
Help: "Time spent creating scalable bloom filters",
75-
}, []string{"type"}),
66+
}),
7667
bloomSize: promauto.With(r).NewHistogram(prometheus.HistogramOpts{
7768
Namespace: constants.Loki,
7869
Name: "bloom_size",

0 commit comments

Comments
 (0)