-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsamplingcache_test.go
More file actions
55 lines (43 loc) · 1.46 KB
/
samplingcache_test.go
File metadata and controls
55 lines (43 loc) · 1.46 KB
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
46
47
48
49
50
51
52
53
54
55
package promsketch
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/zzylol/prometheus-sketches/model/labels"
)
func TestSamplingCache(t *testing.T) {
sc := NewSamplingCache()
time_window_size := int64(100000)
scrape_interval := int64(100)
item_window_size := int(time_window_size / scrape_interval)
sampling_rate := 0.1
lset := labels.FromStrings("fake_metric", "machine0")
FuncName := "count_over_time"
var mint, maxt int64
mint = 900000
maxt = 1000000
lookup := sc.LookUp(FuncName, lset, mint, maxt)
t.Log("lookup=", lookup)
if lookup == false {
err := sc.NewSamplingCacheEntry(lset, sampling_rate, time_window_size, item_window_size) // Then the max_size of sampling cache is 0.1 * 1000 = 100 items
require.NoError(t, err)
}
lookup = sc.LookUp(FuncName, lset, mint, maxt)
t.Log("lookup=", lookup)
outVec, _ := sc.Eval(FuncName, lset, sampling_rate, mint, maxt)
fmt.Println("outVec=", outVec)
for i := 0; i < 10000; i++ {
err := sc.Insert(lset, int64(i*int(scrape_interval)), 0.1*float64(i))
// s := sc.series.getByHash(lset.Hash(), lset)
// fmt.Println(len(s.us.Arr), s.us.Cur_time, s.us.Time_window_size)
require.NoError(t, err)
}
floats, err := sc.Select(lset, 0, 5)
fmt.Println(floats, err)
floats, err = sc.Select(lset, 2, 11)
fmt.Println(floats, err)
floats, err = sc.Select(lset, mint, maxt)
fmt.Println(floats, err)
outVec, _ = sc.Eval(FuncName, lset, sampling_rate, mint, maxt)
fmt.Println(outVec)
}