Skip to content

Commit

Permalink
change convertValueToFloat64 function name
Browse files Browse the repository at this point in the history
  • Loading branch information
leiwingqueen committed Nov 2, 2024
1 parent 31f7931 commit 2c34676
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions internal/store/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package store
import (
"context"
"k8s.io/apimachinery/pkg/api/resource"
"math"
"strings"

basemetrics "k8s.io/component-base/metrics"
Expand Down Expand Up @@ -355,7 +354,7 @@ func createNodeStatusAllocatableFamilyGenerator() generator.FamilyGenerator {
SanitizeLabelName(string(resourceName)),
string(constant.UnitByte),
},
Value: convertFloat64(&val),
Value: convertValueToFloat64(&val),
})
}
if isAttachableVolumeResourceName(resourceName) {
Expand All @@ -364,7 +363,7 @@ func createNodeStatusAllocatableFamilyGenerator() generator.FamilyGenerator {
SanitizeLabelName(string(resourceName)),
string(constant.UnitByte),
},
Value: convertFloat64(&val),
Value: convertValueToFloat64(&val),
})
}
if isExtendedResourceName(resourceName) {
Expand All @@ -373,7 +372,7 @@ func createNodeStatusAllocatableFamilyGenerator() generator.FamilyGenerator {
SanitizeLabelName(string(resourceName)),
string(constant.UnitInteger),
},
Value: convertFloat64(&val),
Value: convertValueToFloat64(&val),
})
}
}
Expand Down Expand Up @@ -409,7 +408,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
SanitizeLabelName(string(resourceName)),
string(constant.UnitCore),
},
Value: convertFloat64(&val),
Value: convertValueToFloat64(&val),
})
case v1.ResourceStorage:
fallthrough
Expand All @@ -421,15 +420,15 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
SanitizeLabelName(string(resourceName)),
string(constant.UnitByte),
},
Value: convertFloat64(&val),
Value: convertValueToFloat64(&val),
})
case v1.ResourcePods:
ms = append(ms, &metric.Metric{
LabelValues: []string{
SanitizeLabelName(string(resourceName)),
string(constant.UnitInteger),
},
Value: convertFloat64(&val),
Value: convertValueToFloat64(&val),
})
default:
if isHugePageResourceName(resourceName) {
Expand All @@ -438,7 +437,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
SanitizeLabelName(string(resourceName)),
string(constant.UnitByte),
},
Value: convertFloat64(&val),
Value: convertValueToFloat64(&val),
})
}
if isAttachableVolumeResourceName(resourceName) {
Expand All @@ -447,7 +446,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
SanitizeLabelName(string(resourceName)),
string(constant.UnitByte),
},
Value: convertFloat64(&val),
Value: convertValueToFloat64(&val),
})
}
if isExtendedResourceName(resourceName) {
Expand All @@ -456,7 +455,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
SanitizeLabelName(string(resourceName)),
string(constant.UnitInteger),
},
Value: convertFloat64(&val),
Value: convertValueToFloat64(&val),
})
}
}
Expand Down Expand Up @@ -533,10 +532,8 @@ func createNodeListWatch(kubeClient clientset.Interface, _ string, _ string) cac
}
}

const maxValue = math.MaxInt64 / 1000

func convertFloat64(q *resource.Quantity) float64 {
if q.Value() > maxValue {
func convertValueToFloat64(q *resource.Quantity) float64 {
if q.Value() > resource.MaxMilliValue {
return float64(q.Value())
}
return float64(q.MilliValue()) / 1000
Expand Down

0 comments on commit 2c34676

Please sign in to comment.