diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index b2081071f6..5f85684be3 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -639,7 +639,8 @@ func (proxier *Proxier) syncProxyRules() { start := time.Now() defer func() { - metrics.SyncProxyRulesLatency.Observe(metrics.SinceInMicroseconds(start)) + metrics.SyncProxyRulesLatency.Observe(metrics.SinceInSeconds(start)) + metrics.DeprecatedSyncProxyRulesLatency.Observe(metrics.SinceInMicroseconds(start)) klog.V(4).Infof("syncProxyRules took %v", time.Since(start)) }() // don't sync rules till we've received services and endpoints diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index f96aee0836..1b1af87b70 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -719,7 +719,8 @@ func (proxier *Proxier) syncProxyRules() { start := time.Now() defer func() { - metrics.SyncProxyRulesLatency.Observe(metrics.SinceInMicroseconds(start)) + metrics.SyncProxyRulesLatency.Observe(metrics.SinceInSeconds(start)) + metrics.DeprecatedSyncProxyRulesLatency.Observe(metrics.SinceInMicroseconds(start)) klog.V(4).Infof("syncProxyRules took %v", time.Since(start)) }() // don't sync rules till we've received services and endpoints diff --git a/pkg/proxy/metrics/metrics.go b/pkg/proxy/metrics/metrics.go index d442f2da32..c5c1d8feda 100644 --- a/pkg/proxy/metrics/metrics.go +++ b/pkg/proxy/metrics/metrics.go @@ -28,10 +28,20 @@ const kubeProxySubsystem = "kubeproxy" var ( // SyncProxyRulesLatency is the latency of one round of kube-proxy syncing proxy rules. SyncProxyRulesLatency = prometheus.NewHistogram( + prometheus.HistogramOpts{ + Subsystem: kubeProxySubsystem, + Name: "sync_proxy_rules_latency_seconds", + Help: "SyncProxyRules latency in seconds", + Buckets: prometheus.ExponentialBuckets(0.001, 2, 15), + }, + ) + + // DeprecatedSyncProxyRulesLatency is the latency of one round of kube-proxy syncing proxy rules. + DeprecatedSyncProxyRulesLatency = prometheus.NewHistogram( prometheus.HistogramOpts{ Subsystem: kubeProxySubsystem, Name: "sync_proxy_rules_latency_microseconds", - Help: "SyncProxyRules latency", + Help: "(Deprecated) SyncProxyRules latency in microseconds", Buckets: prometheus.ExponentialBuckets(1000, 2, 15), }, ) @@ -43,6 +53,7 @@ var registerMetricsOnce sync.Once func RegisterMetrics() { registerMetricsOnce.Do(func() { prometheus.MustRegister(SyncProxyRulesLatency) + prometheus.MustRegister(DeprecatedSyncProxyRulesLatency) }) } @@ -50,3 +61,8 @@ func RegisterMetrics() { func SinceInMicroseconds(start time.Time) float64 { return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds()) } + +// SinceInSeconds gets the time since the specified start in seconds. +func SinceInSeconds(start time.Time) float64 { + return time.Since(start).Seconds() +} diff --git a/pkg/proxy/winkernel/metrics.go b/pkg/proxy/winkernel/metrics.go index 100b6abba8..db91cf1e41 100644 --- a/pkg/proxy/winkernel/metrics.go +++ b/pkg/proxy/winkernel/metrics.go @@ -27,10 +27,19 @@ const kubeProxySubsystem = "kubeproxy" var ( SyncProxyRulesLatency = prometheus.NewHistogram( + prometheus.HistogramOpts{ + Subsystem: kubeProxySubsystem, + Name: "sync_proxy_rules_latency_seconds", + Help: "SyncProxyRules latency in seconds", + Buckets: prometheus.ExponentialBuckets(0.001, 2, 15), + }, + ) + + DeprecatedSyncProxyRulesLatency = prometheus.NewHistogram( prometheus.HistogramOpts{ Subsystem: kubeProxySubsystem, Name: "sync_proxy_rules_latency_microseconds", - Help: "SyncProxyRules latency", + Help: "(Deprecated) SyncProxyRules latency in microseconds", Buckets: prometheus.ExponentialBuckets(1000, 2, 15), }, ) @@ -41,6 +50,7 @@ var registerMetricsOnce sync.Once func RegisterMetrics() { registerMetricsOnce.Do(func() { prometheus.MustRegister(SyncProxyRulesLatency) + prometheus.MustRegister(DeprecatedSyncProxyRulesLatency) }) } @@ -48,3 +58,8 @@ func RegisterMetrics() { func sinceInMicroseconds(start time.Time) float64 { return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds()) } + +// Gets the time since the specified start in seconds. +func sinceInSeconds(start time.Time) float64 { + return time.Since(start).Seconds() +} diff --git a/pkg/proxy/winkernel/proxier.go b/pkg/proxy/winkernel/proxier.go index b0289ffe4d..83d3a92fe5 100644 --- a/pkg/proxy/winkernel/proxier.go +++ b/pkg/proxy/winkernel/proxier.go @@ -938,7 +938,8 @@ func (proxier *Proxier) syncProxyRules() { start := time.Now() defer func() { - SyncProxyRulesLatency.Observe(sinceInMicroseconds(start)) + SyncProxyRulesLatency.Observe(sinceInSeconds(start)) + DeprecatedSyncProxyRulesLatency.Observe(sinceInMicroseconds(start)) klog.V(4).Infof("syncProxyRules took %v", time.Since(start)) }() // don't sync rules till we've received services and endpoints