Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/kubelet/cm/container_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
if err != nil {
return nil, err
}
metrics.Register(cm.draManager.NewMetricsCollector())
metrics.RegisterCollectors(cm.draManager.NewMetricsCollector())
}
cm.kubeClient = kubeClient

Expand Down
3 changes: 2 additions & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,8 @@ func (kl *Kubelet) StartGarbageCollection() {
// Note that the modules here must not depend on modules that are not initialized here.
func (kl *Kubelet) initializeModules(ctx context.Context) error {
// Prometheus metrics.
metrics.Register(
metrics.Register()
metrics.RegisterCollectors(
collectors.NewVolumeStatsCollector(kl),
collectors.NewLogMetricsCollector(kl.StatsProvider.ListPodStats),
)
Expand Down
7 changes: 3 additions & 4 deletions pkg/kubelet/metrics/collectors/volume_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/kubelet/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ var (
var registerMetrics sync.Once

// Register registers all metrics.
func Register(collectors ...metrics.StableCollector) {
func Register() {
// Register the metrics.
registerMetrics.Do(func() {
legacyregistry.MustRegister(FirstNetworkPodStartSLIDuration)
Expand Down Expand Up @@ -1274,10 +1274,6 @@ func Register(collectors ...metrics.StableCollector) {
legacyregistry.MustRegister(OrphanPodCleanedVolumes)
legacyregistry.MustRegister(OrphanPodCleanedVolumesErrors)

for _, collector := range collectors {
legacyregistry.CustomMustRegister(collector)
}

if utilfeature.DefaultFeatureGate.Enabled(features.GracefulNodeShutdown) &&
utilfeature.DefaultFeatureGate.Enabled(features.GracefulNodeShutdownBasedOnPodPriority) {
legacyregistry.MustRegister(GracefulShutdownStartTime)
Expand Down Expand Up @@ -1314,6 +1310,10 @@ func Register(collectors ...metrics.StableCollector) {
})
}

func RegisterCollectors(collectors ...metrics.StableCollector) {
legacyregistry.CustomMustRegister(collectors...)
}

// GetGather returns the gatherer. It used by test case outside current package.
func GetGather() metrics.Gatherer {
return legacyregistry.DefaultGatherer
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/server/stats/volume_stat_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down