add warning log if volume calculation took too long than 1 second

This commit is contained in:
Paco Xu
2021-12-23 16:18:32 +08:00
committed by -e
parent a6299aa2ab
commit e3745a10aa

View File

@@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
utiltrace "k8s.io/utils/trace"
)
// volumeStatCalculator calculates volume metrics for a given pod periodically in the background and caches the result
@@ -133,7 +134,11 @@ func (s *volumeStatCalculator) calcAndStoreStats() {
var ephemeralStats []stats.VolumeStats
var persistentStats []stats.VolumeStats
for name, v := range metricVolumes {
metric, err := v.GetMetrics()
metric, err := func() (*volume.Metrics, error) {
trace := utiltrace.New(fmt.Sprintf("Calculate volume metrics of %v for pod %v/%v", name, s.pod.Namespace, s.pod.Name))
defer trace.LogIfLong(1 * time.Second)
return v.GetMetrics()
}()
if err != nil {
// Expected for Volumes that don't support Metrics
if !volume.IsNotSupported(err) {