@@ -5,7 +5,6 @@ package metrics
5
5
6
6
import (
7
7
"context"
8
- rand "math/rand/v2"
9
8
"sync"
10
9
"sync/atomic"
11
10
"time"
@@ -31,6 +30,53 @@ type worker struct {
31
30
index int // worker index
32
31
}
33
32
33
+ var histogramBucketSamples = []struct {
34
+ bucketCounts []uint64
35
+ sum int64
36
+ }{
37
+ {
38
+ []uint64 {0 , 0 , 0 , 0 , 0 },
39
+ 0 ,
40
+ },
41
+
42
+ {
43
+ []uint64 {0 , 1 , 0 , 0 , 0 },
44
+ 1 ,
45
+ },
46
+ {
47
+ []uint64 {0 , 1 , 0 , 1 , 0 },
48
+ 4 ,
49
+ },
50
+ {
51
+ []uint64 {1 , 1 , 1 , 0 , 0 },
52
+ 3 ,
53
+ },
54
+ {
55
+ []uint64 {0 , 0 , 1 , 2 , 1 },
56
+ 12 ,
57
+ },
58
+ {
59
+ []uint64 {0 , 0 , 0 , 0 , 0 },
60
+ 0 ,
61
+ },
62
+ {
63
+ []uint64 {0 , 1 , 0 , 0 , 0 },
64
+ 1 ,
65
+ },
66
+ {
67
+ []uint64 {0 , 2 , 0 , 0 , 0 },
68
+ 2 ,
69
+ },
70
+ {
71
+ []uint64 {1 , 0 , 1 , 1 , 0 },
72
+ 5 ,
73
+ },
74
+ {
75
+ []uint64 {2 , 0 , 1 , 0 , 1 },
76
+ 6 ,
77
+ },
78
+ }
79
+
34
80
func (w worker ) simulateMetrics (res * resource.Resource , exporterFunc func () (sdkmetric.Exporter , error ), signalAttrs []attribute.KeyValue ) {
35
81
limiter := rate .NewLimiter (w .limitPerSecond , 1 )
36
82
@@ -39,8 +85,6 @@ func (w worker) simulateMetrics(res *resource.Resource, exporterFunc func() (sdk
39
85
w .logger .Error ("failed to create the exporter" , zap .Error (err ))
40
86
return
41
87
}
42
- randomPCG := rand .NewPCG (0 , 0 )
43
- randomgenerator := rand .New (randomPCG )
44
88
45
89
defer func () {
46
90
w .logger .Info ("stopping the exporter" )
@@ -86,8 +130,9 @@ func (w worker) simulateMetrics(res *resource.Resource, exporterFunc func() (sdk
86
130
},
87
131
})
88
132
case metricTypeHistogram :
89
- iteration := uint64 (i ) % 5
90
- sum , bucketCounts := generateHistogramBuckets [int64 ](iteration , randomgenerator )
133
+ iteration := uint64 (i ) % 10
134
+ sum := histogramBucketSamples [iteration ].sum
135
+ bucketCounts := histogramBucketSamples [iteration ].bucketCounts
91
136
metrics = append (metrics , metricdata.Metrics {
92
137
Name : w .metricName ,
93
138
Data : metricdata.Histogram [int64 ]{
@@ -133,16 +178,3 @@ func (w worker) simulateMetrics(res *resource.Resource, exporterFunc func() (sdk
133
178
w .logger .Info ("metrics generated" , zap .Int64 ("metrics" , i ))
134
179
w .wg .Done ()
135
180
}
136
-
137
- func generateHistogramBuckets [T int64 | float64 ](count uint64 , randomgenerator * rand.Rand ) (sum T , bucketCounts []uint64 ) {
138
- sum = 0
139
- bucketCounts = make ([]uint64 , 5 )
140
- var i uint64
141
- for i = 0 ; i < count ; i ++ {
142
- sample := randomgenerator .IntN (5 )
143
- // See bounds above
144
- sum += T (sample )
145
- bucketCounts [sample ]++
146
- }
147
- return
148
- }
0 commit comments