Skip to content

Commit

Permalink
Merge pull request #95363 from wojtek-t/fix_npl_reporting_in_kube_proxy
Browse files Browse the repository at this point in the history
Fix reporting network_programming_latency metrics in kube-proxy
  • Loading branch information
k8s-ci-robot committed Oct 7, 2020
2 parents c1ce63a + 6e4aa0f commit c9c24b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/proxy/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ func (ect *EndpointChangeTracker) Update(previous, current *v1.Endpoints) bool {
ect.items[namespacedName] = change
}

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

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

if changeNeeded {
metrics.EndpointChangesPending.Inc()
if t := getLastChangeTriggerTime(endpointSlice.Annotations); !t.IsZero() {
// In case of Endpoints deletion, the LastChangeTriggerTime annotation is
// by-definition coming from the time of last update, which is not what
// we want to measure. So we simply ignore it in this cases.
// TODO(wojtek-t, robscott): Address the problem for EndpointSlice deletion
// when other EndpointSlice for that service still exist.
if t := getLastChangeTriggerTime(endpointSlice.Annotations); !t.IsZero() && !removeSlice {
ect.lastChangeTriggerTimes[namespacedName] =
append(ect.lastChangeTriggerTimes[namespacedName], t)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/proxy/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,14 @@ func TestLastChangeTriggerTime(t *testing.T) {
},
expected: map[types.NamespacedName][]time.Time{createName("ns", "ep1"): {t2}},
},
{
name: "delete",
scenario: func(fp *FakeProxier) {
e := createEndpoints("ns", "ep1", t1)
fp.deleteEndpoints(e)
},
expected: map[types.NamespacedName][]time.Time{},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit c9c24b4

Please sign in to comment.