Change proxy metrics to conform guideline

pull/564/head
danielqsj 2018-12-26 17:25:10 +08:00
parent 5252352ad8
commit 8975e62254
5 changed files with 39 additions and 5 deletions

View File

@ -643,7 +643,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

View File

@ -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

View File

@ -28,10 +28,20 @@ const kubeProxySubsystem = "kubeproxy"
var ( var (
// SyncProxyRulesLatency is the latency of one round of kube-proxy syncing proxy rules. // SyncProxyRulesLatency is the latency of one round of kube-proxy syncing proxy rules.
SyncProxyRulesLatency = prometheus.NewHistogram( 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{ prometheus.HistogramOpts{
Subsystem: kubeProxySubsystem, Subsystem: kubeProxySubsystem,
Name: "sync_proxy_rules_latency_microseconds", Name: "sync_proxy_rules_latency_microseconds",
Help: "SyncProxyRules latency", Help: "SyncProxyRules latency in microseconds",
Buckets: prometheus.ExponentialBuckets(1000, 2, 15), Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
}, },
) )
@ -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() {
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()
}

View File

@ -27,10 +27,19 @@ const kubeProxySubsystem = "kubeproxy"
var ( var (
SyncProxyRulesLatency = prometheus.NewHistogram( 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{ prometheus.HistogramOpts{
Subsystem: kubeProxySubsystem, Subsystem: kubeProxySubsystem,
Name: "sync_proxy_rules_latency_microseconds", Name: "sync_proxy_rules_latency_microseconds",
Help: "SyncProxyRules latency", Help: "SyncProxyRules latency in microseconds",
Buckets: prometheus.ExponentialBuckets(1000, 2, 15), Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
}, },
) )
@ -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() {
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()
}

View File

@ -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