Unverified Commit b8d6de32 authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #72334 from danielqsj/kp

Change proxy metrics to conform metrics guidelines
parents ac8e7720 1fb91a72
...@@ -639,7 +639,8 @@ func (proxier *Proxier) syncProxyRules() { ...@@ -639,7 +639,8 @@ func (proxier *Proxier) syncProxyRules() {
start := time.Now() start := time.Now()
defer func() { 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)) klog.V(4).Infof("syncProxyRules took %v", time.Since(start))
}() }()
// don't sync rules till we've received services and endpoints // don't sync rules till we've received services and endpoints
......
...@@ -719,7 +719,8 @@ func (proxier *Proxier) syncProxyRules() { ...@@ -719,7 +719,8 @@ func (proxier *Proxier) syncProxyRules() {
start := time.Now() start := time.Now()
defer func() { 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)) klog.V(4).Infof("syncProxyRules took %v", time.Since(start))
}() }()
// don't sync rules till we've received services and endpoints // don't sync rules till we've received services and endpoints
......
...@@ -30,8 +30,18 @@ var ( ...@@ -30,8 +30,18 @@ var (
SyncProxyRulesLatency = prometheus.NewHistogram( SyncProxyRulesLatency = prometheus.NewHistogram(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: kubeProxySubsystem, 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", Name: "sync_proxy_rules_latency_microseconds",
Help: "SyncProxyRules latency", Help: "(Deprecated) SyncProxyRules latency in microseconds",
Buckets: prometheus.ExponentialBuckets(1000, 2, 15), Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
}, },
) )
...@@ -43,6 +53,7 @@ var registerMetricsOnce sync.Once ...@@ -43,6 +53,7 @@ var registerMetricsOnce sync.Once
func RegisterMetrics() { func RegisterMetrics() {
registerMetricsOnce.Do(func() { registerMetricsOnce.Do(func() {
prometheus.MustRegister(SyncProxyRulesLatency) prometheus.MustRegister(SyncProxyRulesLatency)
prometheus.MustRegister(DeprecatedSyncProxyRulesLatency)
}) })
} }
...@@ -50,3 +61,8 @@ func RegisterMetrics() { ...@@ -50,3 +61,8 @@ func RegisterMetrics() {
func SinceInMicroseconds(start time.Time) float64 { func SinceInMicroseconds(start time.Time) float64 {
return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds()) 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()
}
...@@ -29,8 +29,17 @@ var ( ...@@ -29,8 +29,17 @@ var (
SyncProxyRulesLatency = prometheus.NewHistogram( SyncProxyRulesLatency = prometheus.NewHistogram(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Subsystem: kubeProxySubsystem, 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", Name: "sync_proxy_rules_latency_microseconds",
Help: "SyncProxyRules latency", Help: "(Deprecated) SyncProxyRules latency in microseconds",
Buckets: prometheus.ExponentialBuckets(1000, 2, 15), Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
}, },
) )
...@@ -41,6 +50,7 @@ var registerMetricsOnce sync.Once ...@@ -41,6 +50,7 @@ var registerMetricsOnce sync.Once
func RegisterMetrics() { func RegisterMetrics() {
registerMetricsOnce.Do(func() { registerMetricsOnce.Do(func() {
prometheus.MustRegister(SyncProxyRulesLatency) prometheus.MustRegister(SyncProxyRulesLatency)
prometheus.MustRegister(DeprecatedSyncProxyRulesLatency)
}) })
} }
...@@ -48,3 +58,8 @@ func RegisterMetrics() { ...@@ -48,3 +58,8 @@ func RegisterMetrics() {
func sinceInMicroseconds(start time.Time) float64 { func sinceInMicroseconds(start time.Time) float64 {
return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds()) 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()
}
...@@ -938,7 +938,8 @@ func (proxier *Proxier) syncProxyRules() { ...@@ -938,7 +938,8 @@ func (proxier *Proxier) syncProxyRules() {
start := time.Now() start := time.Now()
defer func() { defer func() {
SyncProxyRulesLatency.Observe(sinceInMicroseconds(start)) SyncProxyRulesLatency.Observe(sinceInSeconds(start))
DeprecatedSyncProxyRulesLatency.Observe(sinceInMicroseconds(start))
klog.V(4).Infof("syncProxyRules took %v", time.Since(start)) klog.V(4).Infof("syncProxyRules took %v", time.Since(start))
}() }()
// don't sync rules till we've received services and endpoints // don't sync rules till we've received services and endpoints
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment