@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"io"
23
23
"log"
24
+ "math"
24
25
"net/http"
25
26
"net/url"
26
27
"os"
@@ -78,7 +79,8 @@ func main() {
78
79
if * avalancheFlagsForTotal > 0 {
79
80
fmt .Fprintln (os .Stdout )
80
81
fmt .Fprintln (os .Stdout , "Avalanche flags for the similar distribution to get to the adjusted series goal of:" , * avalancheFlagsForTotal )
81
- flags , adjustedSum := computeAvalancheFlags (* avalancheFlagsForTotal , total , statistics )
82
+ seriesCount := 10
83
+ flags , adjustedSum := computeAvalancheFlags (* avalancheFlagsForTotal , seriesCount , total , statistics )
82
84
for _ , f := range flags {
83
85
fmt .Fprintln (os .Stdout , f )
84
86
}
@@ -96,10 +98,10 @@ func computeTotal(statistics map[dto.MetricType]stats) stats {
96
98
return total
97
99
}
98
100
99
- func computeAvalancheFlags (avalancheFlagsForTotal int , total stats , statistics map [dto.MetricType ]stats ) ([]string , int ) {
101
+ func computeAvalancheFlags (avalancheFlagsForTotal , seriesCount int , total stats , statistics map [dto.MetricType ]stats ) ([]string , int ) {
100
102
// adjustedGoal is tracking the # of adjusted series we want to generate with avalanche.
101
103
adjustedGoal := float64 (avalancheFlagsForTotal )
102
- adjustedGoal /= 10.0 // Assuming --series-count=10
104
+ adjustedGoal /= float64 ( seriesCount )
103
105
// adjustedSum is tracking the total sum of series so far (at the end hopefully adjustedSum ~= adjustedGoal)
104
106
adjustedSum := 0
105
107
// Accumulate flags
@@ -113,7 +115,10 @@ func computeAvalancheFlags(avalancheFlagsForTotal int, total stats, statistics m
113
115
114
116
// adjustedSeriesForType is tracking (per metric type), how many unique series of that
115
117
// metric type avalanche needs to create according to the ratio we got from our input.
116
- adjustedSeriesForType := int (adjustedGoal * adjustedSeriesRatio )
118
+ var adjustedSeriesForType int
119
+ if ! math .IsNaN (adjustedSeriesRatio ) {
120
+ adjustedSeriesForType = int (adjustedGoal * adjustedSeriesRatio )
121
+ }
117
122
118
123
switch mtype {
119
124
case dto .MetricType_GAUGE :
@@ -123,27 +128,37 @@ func computeAvalancheFlags(avalancheFlagsForTotal int, total stats, statistics m
123
128
flags = append (flags , fmt .Sprintf ("--counter-metric-count=%v" , adjustedSeriesForType ))
124
129
adjustedSum += adjustedSeriesForType
125
130
case dto .MetricType_HISTOGRAM :
126
- avgBkts := s .buckets / s .series
127
- adjustedSeriesForType /= 2 + avgBkts
131
+ var avgBkts int
132
+ if s .series > 0 {
133
+ avgBkts = s .buckets / s .series
134
+ adjustedSeriesForType /= 2 + avgBkts
135
+ }
128
136
flags = append (flags , fmt .Sprintf ("--histogram-metric-count=%v" , adjustedSeriesForType ))
129
- flags = append (flags , fmt .Sprintf ("--histogram-metric-bucket-count=%v" , avgBkts - 1 )) // -1 is due to caveat of additional +Inf not added by avalanche.
137
+ if s .series > 0 {
138
+ flags = append (flags , fmt .Sprintf ("--histogram-metric-bucket-count=%v" , avgBkts - 1 )) // -1 is due to caveat of additional +Inf not added by avalanche.
139
+ }
130
140
adjustedSum += adjustedSeriesForType * (2 + avgBkts )
131
141
case metricType_NATIVE_HISTOGRAM :
132
142
flags = append (flags , fmt .Sprintf ("--native-histogram-metric-count=%v" , adjustedSeriesForType ))
133
143
adjustedSum += adjustedSeriesForType
134
144
case dto .MetricType_SUMMARY :
135
- avgObjs := s .objectives / s .series
136
- adjustedSeriesForType /= 2 + avgObjs
145
+ var avgObjs int
146
+ if s .series > 0 {
147
+ avgObjs = s .objectives / s .series
148
+ adjustedSeriesForType /= 2 + avgObjs
149
+ }
137
150
flags = append (flags , fmt .Sprintf ("--summary-metric-count=%v" , adjustedSeriesForType ))
138
- flags = append (flags , fmt .Sprintf ("--summary-metric-objective-count=%v" , avgObjs ))
151
+ if s .series > 0 {
152
+ flags = append (flags , fmt .Sprintf ("--summary-metric-objective-count=%v" , avgObjs ))
153
+ }
139
154
adjustedSum += adjustedSeriesForType * (2 + avgObjs )
140
155
default :
141
156
if s .series > 0 {
142
157
log .Fatalf ("not supported %v metric in avalanche" , mtype )
143
158
}
144
159
}
145
160
}
146
- flags = append (flags , fmt .Sprintf ("--series-count=10" ))
161
+ flags = append (flags , fmt .Sprintf ("--series-count=%v" , seriesCount ))
147
162
// Changes values every 5m.
148
163
flags = append (flags , "--value-interval=300" )
149
164
// 1h series churn.
0 commit comments