Skip to content

Commit 4aa6e83

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

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

pkg/storage/bloom/v1/bloom_tokenizer.go

+16-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,25 @@ 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))
161173
ch <- &BloomCreation{
162174
Bloom: bloom,
163175
SourceBytesAdded: bytesAdded,
164176
}
165-
close(ch)
166177
}
167178

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

pkg/storage/bloom/v1/metrics.go

-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
type Metrics struct {
1111
// writes
1212
bloomsTotal *prometheus.CounterVec // number of blooms created
13-
sbfCreationTime *prometheus.CounterVec // time spent creating sbfs
1413
bloomSize prometheus.Histogram // size of the bloom filter in bytes
1514
hammingWeightRatio prometheus.Histogram // ratio of the hamming weight of the bloom filter to the number of bits in the bloom filter
1615
estimatedCount prometheus.Histogram // estimated number of elements in the bloom filter
@@ -68,11 +67,6 @@ func NewMetrics(r prometheus.Registerer) *Metrics {
6867
Name: "blooms_created_total",
6968
Help: "Number of blooms created",
7069
}, []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"}),
7670
bloomSize: promauto.With(r).NewHistogram(prometheus.HistogramOpts{
7771
Namespace: constants.Loki,
7872
Name: "bloom_size",

0 commit comments

Comments
 (0)