Merge pull request #107490 from pacoxu/add-volume-stats-slow-log

add warning log if volume calculation took too long than 1 second
This commit is contained in:
Kubernetes Prow Robot 2022-07-28 17:55:10 -07:00 committed by GitHub
commit cc69f8f65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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) {