Skip to content

Commit

Permalink
Merge pull request #952 from tydra-wang/fix-kubelet-metrics-1.26
Browse files Browse the repository at this point in the history
Cherry pick #949 fix kubelet stats summary collector panic
  • Loading branch information
k8s-ci-robot authored Jan 15, 2024
2 parents 51f49b7 + 33afa88 commit 303a494
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions pkg/metric/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metric

import (
"errors"
"runtime/debug"
"sync"
"time"

Expand Down Expand Up @@ -98,6 +99,11 @@ func (csi CSICollector) Collect(ch chan<- prometheus.Metric) {
}

func execute(name string, c Collector, ch chan<- prometheus.Metric) {
defer func() {
if err := recover(); err != nil {
logrus.Errorf("Collecotor panic occurred: %v. stacktrace: %s", err, string(debug.Stack()))
}
}()
begin := time.Now()
err := c.Update(ch)
duration := time.Since(begin)
Expand Down
20 changes: 12 additions & 8 deletions pkg/metric/kubelet_stats_summary_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,22 @@ func (c *kubeletStatsSummaryCollector) Update(ch chan<- prometheus.Metric) error
return err
}
for _, pod := range summary.Pods {
for _, m := range ephemeralStorageMetrics {
metric := m.Metric(pod.EphemeralStorage, pod.PodRef.Namespace, pod.PodRef.Name, pod.PodRef.UID)
if metric != nil {
ch <- metric
if pod.EphemeralStorage != nil {
for _, m := range ephemeralStorageMetrics {
metric := m.Metric(pod.EphemeralStorage, pod.PodRef.Namespace, pod.PodRef.Name, pod.PodRef.UID)
if metric != nil {
ch <- metric
}
}
}

for _, container := range pod.Containers {
for _, m := range rootfsMetrics {
metric := m.Metric(container.Rootfs, pod.PodRef.Namespace, pod.PodRef.Name, pod.PodRef.UID, container.Name)
if metric != nil {
ch <- metric
if container.Rootfs != nil {
for _, m := range rootfsMetrics {
metric := m.Metric(container.Rootfs, pod.PodRef.Namespace, pod.PodRef.Name, pod.PodRef.UID, container.Name)
if metric != nil {
ch <- metric
}
}
}
}
Expand Down

0 comments on commit 303a494

Please sign in to comment.