@@ -18,7 +18,6 @@ limitations under the License.
1818package updater
1919
2020import (
21- "math"
2221 "strconv"
2322
2423 "github.com/prometheus/client_golang/prometheus"
@@ -27,15 +26,11 @@ import (
2726
2827const (
2928 metricsNamespace = metrics .TopMetricsNamespace + "updater"
30-
31- // The metrics will distinguish VPA sizes up to 2^maxVpaSizeLog (~1M)
32- // Anything above that size will be reported in the top bucket.
33- maxVpaSizeLog = 20
3429)
3530
3631// SizeBasedGauge is a wrapper for incrementally recording values indexed by log2(VPA size)
3732type SizeBasedGauge struct {
38- values [maxVpaSizeLog ]int
33+ values [metrics . MaxVpaSizeLog ]int
3934 gauge * prometheus.GaugeVec
4035}
4136
@@ -97,7 +92,7 @@ func NewExecutionTimer() *metrics.ExecutionTimer {
9792// newSizeBasedGauge provides a wrapper for counting items in a loop
9893func newSizeBasedGauge (gauge * prometheus.GaugeVec ) * SizeBasedGauge {
9994 return & SizeBasedGauge {
100- values : [maxVpaSizeLog ]int {},
95+ values : [metrics . MaxVpaSizeLog ]int {},
10196 gauge : gauge ,
10297 }
10398}
@@ -122,27 +117,15 @@ func NewVpasWithEvictedPodsCounter() *SizeBasedGauge {
122117 return newSizeBasedGauge (vpasWithEvictedPodsCount )
123118}
124119
125- func getVpaSizeLog2 (vpaSize int ) int {
126- if vpaSize == 0 {
127- return 0
128- }
129-
130- ret := int (math .Log2 (float64 (vpaSize )))
131- if ret > maxVpaSizeLog {
132- return maxVpaSizeLog
133- }
134- return ret
135- }
136-
137120// AddEvictedPod increases the counter of pods evicted by Updater, by given VPA size
138121func AddEvictedPod (vpaSize int ) {
139- log2 := getVpaSizeLog2 (vpaSize )
122+ log2 := metrics . GetVpaSizeLog2 (vpaSize )
140123 evictedCount .WithLabelValues (strconv .Itoa (log2 )).Inc ()
141124}
142125
143126// Add increases the counter for the given VPA size
144127func (g * SizeBasedGauge ) Add (vpaSize int , value int ) {
145- log2 := getVpaSizeLog2 (vpaSize )
128+ log2 := metrics . GetVpaSizeLog2 (vpaSize )
146129 g .values [log2 ] += value
147130}
148131
0 commit comments