kube-proxy network programming latency on restarts

kube-proxy expose the metric network_programming_duration_seconds,
that is defined as the time it takes to program the network since
a a service or pod has changed. It uses an annotation on the endpoints
/endpointslices to calculate when the endpoint was created, however,
on restarts, kube-proxy process all the endpoints again, no matter
when those were generated, polluting the metrics.

To be safe, kube-proxy will estimate the latency only for those
endpoints that were generated after it started.
This commit is contained in:
Antonio Ojea
2021-04-07 19:09:59 +02:00
parent b0abe89ae2
commit ef76be37de
3 changed files with 42 additions and 16 deletions

View File

@@ -23,7 +23,7 @@ import (
"github.com/davecgh/go-spew/spew"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
discovery "k8s.io/api/discovery/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@@ -1294,7 +1294,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
for tci, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fp := newFakeProxier(v1.IPv4Protocol)
fp := newFakeProxier(v1.IPv4Protocol, time.Time{})
fp.hostname = nodeName
// First check that after adding all previous versions of endpoints,
@@ -1364,7 +1364,9 @@ func TestUpdateEndpointsMap(t *testing.T) {
}
func TestLastChangeTriggerTime(t *testing.T) {
t0 := time.Date(2018, 01, 01, 0, 0, 0, 0, time.UTC)
startTime := time.Date(2018, 01, 01, 0, 0, 0, 0, time.UTC)
t_1 := startTime.Add(-time.Second)
t0 := startTime.Add(time.Second)
t1 := t0.Add(time.Second)
t2 := t1.Add(time.Second)
t3 := t2.Add(time.Second)
@@ -1438,6 +1440,14 @@ func TestLastChangeTriggerTime(t *testing.T) {
},
expected: map[types.NamespacedName][]time.Time{},
},
{
name: "Endpoints create before tracker started",
scenario: func(fp *FakeProxier) {
e := createEndpoints("ns", "ep1", t_1)
fp.addEndpoints(e)
},
expected: map[types.NamespacedName][]time.Time{},
},
{
name: "addEndpoints then deleteEndpoints",
scenario: func(fp *FakeProxier) {
@@ -1469,7 +1479,7 @@ func TestLastChangeTriggerTime(t *testing.T) {
}
for _, tc := range testCases {
fp := newFakeProxier(v1.IPv4Protocol)
fp := newFakeProxier(v1.IPv4Protocol, startTime)
tc.scenario(fp)