Skip to content

Commit f93e6f3

Browse files
aojeaaroradaman
authored andcommitted
kube-proxy implement dual stack metrics
Signed-off-by: Daman Arora <[email protected]> Co-authored-by: Antonio Ojea <[email protected]>
1 parent 3bec245 commit f93e6f3

File tree

8 files changed

+98
-88
lines changed

8 files changed

+98
-88
lines changed

pkg/proxy/iptables/proxier.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func CleanupLeftovers(ctx context.Context, ipt utiliptables.Interface) (encounte
466466
err = ipt.Restore(utiliptables.TableNAT, natLines, utiliptables.NoFlushTables, utiliptables.RestoreCounters)
467467
if err != nil {
468468
logger.Error(err, "Failed to execute iptables-restore", "table", utiliptables.TableNAT)
469-
metrics.IPTablesRestoreFailuresTotal.Inc()
469+
metrics.IPTablesRestoreFailuresTotal.WithLabelValues(string(ipt.Protocol())).Inc()
470470
encounteredError = true
471471
}
472472
}
@@ -493,7 +493,7 @@ func CleanupLeftovers(ctx context.Context, ipt utiliptables.Interface) (encounte
493493
// Write it.
494494
if err := ipt.Restore(utiliptables.TableFilter, filterLines, utiliptables.NoFlushTables, utiliptables.RestoreCounters); err != nil {
495495
logger.Error(err, "Failed to execute iptables-restore", "table", utiliptables.TableFilter)
496-
metrics.IPTablesRestoreFailuresTotal.Inc()
496+
metrics.IPTablesRestoreFailuresTotal.WithLabelValues(string(ipt.Protocol())).Inc()
497497
encounteredError = true
498498
}
499499
}
@@ -527,7 +527,7 @@ func (proxier *Proxier) Sync() {
527527
if proxier.healthzServer != nil {
528528
proxier.healthzServer.QueuedUpdate(proxier.ipFamily)
529529
}
530-
metrics.SyncProxyRulesLastQueuedTimestamp.SetToCurrentTime()
530+
metrics.SyncProxyRulesLastQueuedTimestamp.WithLabelValues(string(proxier.ipFamily)).SetToCurrentTime()
531531
proxier.syncRunner.Run()
532532
}
533533

@@ -539,7 +539,7 @@ func (proxier *Proxier) SyncLoop() {
539539
}
540540

541541
// synthesize "last change queued" time as the informers are syncing.
542-
metrics.SyncProxyRulesLastQueuedTimestamp.SetToCurrentTime()
542+
metrics.SyncProxyRulesLastQueuedTimestamp.WithLabelValues(string(proxier.ipFamily)).SetToCurrentTime()
543543
proxier.syncRunner.Loop(wait.NeverStop)
544544
}
545545

@@ -813,11 +813,11 @@ func (proxier *Proxier) syncProxyRules() {
813813
// Keep track of how long syncs take.
814814
start := time.Now()
815815
defer func() {
816-
metrics.SyncProxyRulesLatency.Observe(metrics.SinceInSeconds(start))
816+
metrics.SyncProxyRulesLatency.WithLabelValues(string(proxier.ipFamily)).Observe(metrics.SinceInSeconds(start))
817817
if tryPartialSync {
818-
metrics.SyncPartialProxyRulesLatency.Observe(metrics.SinceInSeconds(start))
818+
metrics.SyncPartialProxyRulesLatency.WithLabelValues(string(proxier.ipFamily)).Observe(metrics.SinceInSeconds(start))
819819
} else {
820-
metrics.SyncFullProxyRulesLatency.Observe(metrics.SinceInSeconds(start))
820+
metrics.SyncFullProxyRulesLatency.WithLabelValues(string(proxier.ipFamily)).Observe(metrics.SinceInSeconds(start))
821821
}
822822
proxier.logger.V(2).Info("SyncProxyRules complete", "elapsed", time.Since(start))
823823
}()
@@ -833,7 +833,7 @@ func (proxier *Proxier) syncProxyRules() {
833833
proxier.logger.Info("Sync failed", "retryingTime", proxier.syncPeriod)
834834
proxier.syncRunner.RetryAfter(proxier.syncPeriod)
835835
if tryPartialSync {
836-
metrics.IPTablesPartialRestoreFailuresTotal.Inc()
836+
metrics.IPTablesPartialRestoreFailuresTotal.WithLabelValues(string(proxier.ipFamily)).Inc()
837837
}
838838
// proxier.serviceChanges and proxier.endpointChanges have already
839839
// been flushed, so we've lost the state needed to be able to do
@@ -1528,10 +1528,10 @@ func (proxier *Proxier) syncProxyRules() {
15281528
"-j", "ACCEPT",
15291529
)
15301530

1531-
metrics.IPTablesRulesTotal.WithLabelValues(string(utiliptables.TableFilter)).Set(float64(proxier.filterRules.Lines()))
1532-
metrics.IPTablesRulesLastSync.WithLabelValues(string(utiliptables.TableFilter)).Set(float64(proxier.filterRules.Lines()))
1533-
metrics.IPTablesRulesTotal.WithLabelValues(string(utiliptables.TableNAT)).Set(float64(proxier.natRules.Lines() + skippedNatRules.Lines() - deletedChains))
1534-
metrics.IPTablesRulesLastSync.WithLabelValues(string(utiliptables.TableNAT)).Set(float64(proxier.natRules.Lines() - deletedChains))
1531+
metrics.IPTablesRulesTotal.WithLabelValues(string(utiliptables.TableFilter), string(proxier.ipFamily)).Set(float64(proxier.filterRules.Lines()))
1532+
metrics.IPTablesRulesLastSync.WithLabelValues(string(utiliptables.TableFilter), string(proxier.ipFamily)).Set(float64(proxier.filterRules.Lines()))
1533+
metrics.IPTablesRulesTotal.WithLabelValues(string(utiliptables.TableNAT), string(proxier.ipFamily)).Set(float64(proxier.natRules.Lines() + skippedNatRules.Lines() - deletedChains))
1534+
metrics.IPTablesRulesLastSync.WithLabelValues(string(utiliptables.TableNAT), string(proxier.ipFamily)).Set(float64(proxier.natRules.Lines() - deletedChains))
15351535

15361536
// Sync rules.
15371537
proxier.iptablesData.Reset()
@@ -1563,7 +1563,7 @@ func (proxier *Proxier) syncProxyRules() {
15631563
} else {
15641564
proxier.logger.Error(err, "Failed to execute iptables-restore")
15651565
}
1566-
metrics.IPTablesRestoreFailuresTotal.Inc()
1566+
metrics.IPTablesRestoreFailuresTotal.WithLabelValues(string(proxier.ipFamily)).Inc()
15671567
return
15681568
}
15691569
success = true
@@ -1572,17 +1572,17 @@ func (proxier *Proxier) syncProxyRules() {
15721572
for name, lastChangeTriggerTimes := range endpointUpdateResult.LastChangeTriggerTimes {
15731573
for _, lastChangeTriggerTime := range lastChangeTriggerTimes {
15741574
latency := metrics.SinceInSeconds(lastChangeTriggerTime)
1575-
metrics.NetworkProgrammingLatency.Observe(latency)
1575+
metrics.NetworkProgrammingLatency.WithLabelValues(string(proxier.ipFamily)).Observe(latency)
15761576
proxier.logger.V(4).Info("Network programming", "endpoint", klog.KRef(name.Namespace, name.Name), "elapsed", latency)
15771577
}
15781578
}
15791579

1580-
metrics.SyncProxyRulesNoLocalEndpointsTotal.WithLabelValues("internal").Set(float64(serviceNoLocalEndpointsTotalInternal))
1581-
metrics.SyncProxyRulesNoLocalEndpointsTotal.WithLabelValues("external").Set(float64(serviceNoLocalEndpointsTotalExternal))
1580+
metrics.SyncProxyRulesNoLocalEndpointsTotal.WithLabelValues("internal", string(proxier.ipFamily)).Set(float64(serviceNoLocalEndpointsTotalInternal))
1581+
metrics.SyncProxyRulesNoLocalEndpointsTotal.WithLabelValues("external", string(proxier.ipFamily)).Set(float64(serviceNoLocalEndpointsTotalExternal))
15821582
if proxier.healthzServer != nil {
15831583
proxier.healthzServer.Updated(proxier.ipFamily)
15841584
}
1585-
metrics.SyncProxyRulesLastTimestamp.SetToCurrentTime()
1585+
metrics.SyncProxyRulesLastTimestamp.WithLabelValues(string(proxier.ipFamily)).SetToCurrentTime()
15861586

15871587
// Update service healthchecks. The endpoints list might include services that are
15881588
// not "OnlyLocal", but the services list will not, and the serviceHealthServer

0 commit comments

Comments
 (0)