mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-20 07:56:02 +00:00
kubelet/metrics: misc optimization
This commit is contained in:
@@ -107,7 +107,7 @@ func (collector *volumeStatsCollector) CollectWithStability(ch chan<- metrics.Me
|
||||
lv = append([]string{pvcRef.Namespace, pvcRef.Name}, lv...)
|
||||
ch <- metrics.NewLazyConstMetric(desc, metrics.GaugeValue, v, lv...)
|
||||
}
|
||||
allPVCs := sets.Set[string]{}
|
||||
allPVCs := sets.Set[stats.PVCReference]{}
|
||||
for _, podStat := range podStats {
|
||||
if podStat.VolumeStats == nil {
|
||||
continue
|
||||
@@ -118,8 +118,7 @@ func (collector *volumeStatsCollector) CollectWithStability(ch chan<- metrics.Me
|
||||
// ignore if no PVC reference
|
||||
continue
|
||||
}
|
||||
pvcUniqStr := pvcRef.Namespace + "/" + pvcRef.Name
|
||||
if allPVCs.Has(pvcUniqStr) {
|
||||
if allPVCs.Has(*pvcRef) {
|
||||
// ignore if already collected
|
||||
continue
|
||||
}
|
||||
@@ -132,7 +131,7 @@ func (collector *volumeStatsCollector) CollectWithStability(ch chan<- metrics.Me
|
||||
if volumeStat.VolumeHealthStats != nil {
|
||||
addGauge(volumeStatsHealthAbnormalDesc, pvcRef, convertBoolToFloat64(volumeStat.VolumeHealthStats.Abnormal))
|
||||
}
|
||||
allPVCs.Insert(pvcUniqStr)
|
||||
allPVCs.Insert(*pvcRef)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1274,9 +1274,7 @@ func Register(collectors ...metrics.StableCollector) {
|
||||
legacyregistry.MustRegister(OrphanPodCleanedVolumes)
|
||||
legacyregistry.MustRegister(OrphanPodCleanedVolumesErrors)
|
||||
|
||||
for _, collector := range collectors {
|
||||
legacyregistry.CustomMustRegister(collector)
|
||||
}
|
||||
legacyregistry.CustomMustRegister(collectors...)
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.GracefulNodeShutdown) &&
|
||||
utilfeature.DefaultFeatureGate.Enabled(features.GracefulNodeShutdownBasedOnPodPriority) {
|
||||
|
||||
@@ -125,7 +125,7 @@ func (s *volumeStatCalculator) calcAndStoreStats() {
|
||||
}
|
||||
|
||||
// Get volume specs for the pod - key'd by volume name
|
||||
volumesSpec := make(map[string]v1.Volume)
|
||||
volumesSpec := make(map[string]v1.Volume, len(s.pod.Spec.Volumes))
|
||||
for _, v := range s.pod.Spec.Volumes {
|
||||
volumesSpec[v.Name] = v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user