Add new partial/full sync time metrics for iptables kube-proxy

This commit is contained in:
Dan Winship 2023-01-11 11:37:54 -05:00
parent 8f3f997a98
commit cd51c1803e
2 changed files with 35 additions and 1 deletions

View File

@ -779,14 +779,20 @@ func (proxier *Proxier) syncProxyRules() {
return
}
tryPartialSync := !proxier.needFullSync && utilfeature.DefaultFeatureGate.Enabled(features.MinimizeIPTablesRestore)
// Keep track of how long syncs take.
start := time.Now()
defer func() {
metrics.SyncProxyRulesLatency.Observe(metrics.SinceInSeconds(start))
if tryPartialSync {
metrics.SyncPartialProxyRulesLatency.Observe(metrics.SinceInSeconds(start))
} else {
metrics.SyncFullProxyRulesLatency.Observe(metrics.SinceInSeconds(start))
}
klog.V(2).InfoS("SyncProxyRules complete", "elapsed", time.Since(start))
}()
tryPartialSync := !proxier.needFullSync && utilfeature.DefaultFeatureGate.Enabled(features.MinimizeIPTablesRestore)
var serviceChanged, endpointsChanged sets.Set[string]
if tryPartialSync {
serviceChanged = proxier.serviceChanges.PendingChanges()

View File

@ -28,6 +28,8 @@ const kubeProxySubsystem = "kubeproxy"
var (
// SyncProxyRulesLatency is the latency of one round of kube-proxy syncing proxy rules.
// (With the iptables proxy, if MinimizeIPTablesRestore is enabled, this includes both
// full and partial syncs.)
SyncProxyRulesLatency = metrics.NewHistogram(
&metrics.HistogramOpts{
Subsystem: kubeProxySubsystem,
@ -38,6 +40,30 @@ var (
},
)
// SyncFullProxyRulesLatency is the latency of one round of full rule syncing, when
// MinimizeIPTablesRestore is enabled.
SyncFullProxyRulesLatency = metrics.NewHistogram(
&metrics.HistogramOpts{
Subsystem: kubeProxySubsystem,
Name: "sync_full_proxy_rules_duration_seconds",
Help: "SyncProxyRules latency in seconds for full resyncs",
Buckets: metrics.ExponentialBuckets(0.001, 2, 15),
StabilityLevel: metrics.ALPHA,
},
)
// SyncPartialProxyRulesLatency is the latency of one round of partial rule syncing, when
// MinimizeIPTablesRestore is enabled.
SyncPartialProxyRulesLatency = metrics.NewHistogram(
&metrics.HistogramOpts{
Subsystem: kubeProxySubsystem,
Name: "sync_partial_proxy_rules_duration_seconds",
Help: "SyncProxyRules latency in seconds for partial resyncs",
Buckets: metrics.ExponentialBuckets(0.001, 2, 15),
StabilityLevel: metrics.ALPHA,
},
)
// SyncProxyRulesLastTimestamp is the timestamp proxy rules were last
// successfully synced.
SyncProxyRulesLastTimestamp = metrics.NewGauge(
@ -180,6 +206,8 @@ var registerMetricsOnce sync.Once
func RegisterMetrics() {
registerMetricsOnce.Do(func() {
legacyregistry.MustRegister(SyncProxyRulesLatency)
legacyregistry.MustRegister(SyncFullProxyRulesLatency)
legacyregistry.MustRegister(SyncPartialProxyRulesLatency)
legacyregistry.MustRegister(SyncProxyRulesLastTimestamp)
legacyregistry.MustRegister(NetworkProgrammingLatency)
legacyregistry.MustRegister(EndpointChangesPending)