-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbloom_filter_helpers.go
45 lines (37 loc) · 1006 Bytes
/
bloom_filter_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package multi_tier_caching
import (
"math"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
)
// Helper function to get counter value
func getCounterValue(c prometheus.Counter) float64 {
var metric dto.Metric
if err := c.Write(&metric); err != nil {
return 0
}
return metric.Counter.GetValue()
}
// Helper function to get sum of counter vector values
func getCounterValueVec(vec *prometheus.CounterVec) float64 {
total := 0.0
// Collect all metrics from the counter vector
ch := make(chan prometheus.Metric, 10) // Buffered channel to prevent blocking
go func() {
vec.Collect(ch)
close(ch)
}()
for metric := range ch {
dtoMetric := &dto.Metric{}
if err := metric.Write(dtoMetric); err == nil {
total += dtoMetric.Counter.GetValue()
}
}
return total
}
func estimateFalsePositiveRate(k uint, m uint, n uint) float64 {
if m == 0 || n == 0 {
return 0.0
}
return math.Pow(1-math.Exp(-float64(k*n)/float64(m)), float64(k))
}