Skip to content

Commit 6e4aa0f

Browse files
committed
Fix reporting network_programming_latency metrics in kube-proxy
1 parent e99df0e commit 6e4aa0f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

pkg/proxy/endpoints.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ func (ect *EndpointChangeTracker) Update(previous, current *v1.Endpoints) bool {
167167
ect.items[namespacedName] = change
168168
}
169169

170-
if t := getLastChangeTriggerTime(endpoints.Annotations); !t.IsZero() {
170+
// In case of Endpoints deletion, the LastChangeTriggerTime annotation is
171+
// by-definition coming from the time of last update, which is not what
172+
// we want to measure. So we simply ignore it in this cases.
173+
if t := getLastChangeTriggerTime(endpoints.Annotations); !t.IsZero() && current != nil {
171174
ect.lastChangeTriggerTimes[namespacedName] = append(ect.lastChangeTriggerTimes[namespacedName], t)
172175
}
173176

@@ -222,7 +225,12 @@ func (ect *EndpointChangeTracker) EndpointSliceUpdate(endpointSlice *discovery.E
222225

223226
if changeNeeded {
224227
metrics.EndpointChangesPending.Inc()
225-
if t := getLastChangeTriggerTime(endpointSlice.Annotations); !t.IsZero() {
228+
// In case of Endpoints deletion, the LastChangeTriggerTime annotation is
229+
// by-definition coming from the time of last update, which is not what
230+
// we want to measure. So we simply ignore it in this cases.
231+
// TODO(wojtek-t, robscott): Address the problem for EndpointSlice deletion
232+
// when other EndpointSlice for that service still exist.
233+
if t := getLastChangeTriggerTime(endpointSlice.Annotations); !t.IsZero() && !removeSlice {
226234
ect.lastChangeTriggerTimes[namespacedName] =
227235
append(ect.lastChangeTriggerTimes[namespacedName], t)
228236
}

pkg/proxy/endpoints_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,14 @@ func TestLastChangeTriggerTime(t *testing.T) {
14131413
},
14141414
expected: map[types.NamespacedName][]time.Time{createName("ns", "ep1"): {t2}},
14151415
},
1416+
{
1417+
name: "delete",
1418+
scenario: func(fp *FakeProxier) {
1419+
e := createEndpoints("ns", "ep1", t1)
1420+
fp.deleteEndpoints(e)
1421+
},
1422+
expected: map[types.NamespacedName][]time.Time{},
1423+
},
14161424
}
14171425

14181426
for _, tc := range testCases {

0 commit comments

Comments
 (0)