Skip to content

Commit 4833eb5

Browse files
committed
Made the router skip health checks when there is one endpoint
If there is only one endpoint for a route, there is no point to doing health checks. If the endpoint is down, haproxy will fail to connect. Skipping the checks helps tremendously on servers with large numbers of routes, because reducing any checking means the router doesn't spend a lot of time doing health checks pointlessly. Fixes bug 1492189 (https://bugzilla.redhat.com/show_bug.cgi?id=1492189)
1 parent 5295973 commit 4833eb5

File tree

2 files changed

+152
-10
lines changed

2 files changed

+152
-10
lines changed

pkg/router/template/plugin.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ func createRouterEndpoints(endpoints *kapi.Endpoints, excludeUDP bool, lookupSvc
265265
wasIdled = true
266266
}
267267

268+
// Take a reasonable guess at the number of endpoints to avoid reallocating the out array when we append
268269
out := make([]Endpoint, 0, len(endpoints.Subsets)*4)
269270

270-
// TODO: review me for sanity
271+
// Now build the actual endpoints we pass to the template
271272
for _, s := range subsets {
272273
for _, p := range s.Ports {
273274
if excludeUDP && p.Protocol == kapi.ProtocolUDP {
@@ -306,5 +307,11 @@ func createRouterEndpoints(endpoints *kapi.Endpoints, excludeUDP bool, lookupSvc
306307
}
307308
}
308309

310+
// We want to disable endpoint checks if there is only one endpoint
311+
// We skip the case where it is idled, since we set NoHealthCheck above
312+
if wasIdled == false && len(out) == 1 {
313+
out[0].NoHealthCheck = true
314+
}
315+
309316
return out
310317
}

pkg/router/template/plugin_test.go

+144-9
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,16 @@ func TestHandleEndpoints(t *testing.T) {
271271
Name: "foo/test", //service name from kapi.endpoints object
272272
EndpointTable: []Endpoint{
273273
{
274-
ID: "ept:test:1.1.1.1:345",
275-
IP: "1.1.1.1",
276-
Port: "345",
274+
ID: "ept:test:1.1.1.1:345",
275+
IP: "1.1.1.1",
276+
Port: "345",
277+
NoHealthCheck: true,
277278
},
278279
},
279280
},
280281
},
281282
{
282-
name: "Endpoint mod",
283+
name: "Endpoint mod (one ep, one address)",
283284
eventType: watch.Modified,
284285
endpoints: &kapi.Endpoints{
285286
ObjectMeta: metav1.ObjectMeta{
@@ -295,9 +296,143 @@ func TestHandleEndpoints(t *testing.T) {
295296
Name: "foo/test",
296297
EndpointTable: []Endpoint{
297298
{
298-
ID: "pod:pod-1:test:2.2.2.2:8080",
299-
IP: "2.2.2.2",
300-
Port: "8080",
299+
ID: "pod:pod-1:test:2.2.2.2:8080",
300+
IP: "2.2.2.2",
301+
Port: "8080",
302+
NoHealthCheck: true,
303+
},
304+
},
305+
},
306+
},
307+
{
308+
name: "Endpoint mod (second ep, one address each)",
309+
eventType: watch.Modified,
310+
endpoints: &kapi.Endpoints{
311+
ObjectMeta: metav1.ObjectMeta{
312+
Namespace: "foo",
313+
Name: "test",
314+
},
315+
Subsets: []kapi.EndpointSubset{
316+
{
317+
Addresses: []kapi.EndpointAddress{{IP: "2.2.2.2", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-1"}}},
318+
Ports: []kapi.EndpointPort{{Port: 8080}},
319+
},
320+
{
321+
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-2"}}},
322+
Ports: []kapi.EndpointPort{{Port: 8081}},
323+
},
324+
},
325+
},
326+
expectedServiceUnit: &ServiceUnit{
327+
Name: "foo/test",
328+
EndpointTable: []Endpoint{
329+
{
330+
ID: "pod:pod-1:test:2.2.2.2:8080",
331+
IP: "2.2.2.2",
332+
Port: "8080",
333+
NoHealthCheck: false,
334+
},
335+
{
336+
ID: "pod:pod-2:test:3.3.3.3:8081",
337+
IP: "3.3.3.3",
338+
Port: "8081",
339+
NoHealthCheck: false,
340+
},
341+
},
342+
},
343+
},
344+
{
345+
name: "Endpoint mod (one ep, two addresses)",
346+
eventType: watch.Modified,
347+
endpoints: &kapi.Endpoints{
348+
ObjectMeta: metav1.ObjectMeta{
349+
Namespace: "foo",
350+
Name: "test",
351+
},
352+
Subsets: []kapi.EndpointSubset{
353+
{
354+
Addresses: []kapi.EndpointAddress{
355+
{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-2"}},
356+
{IP: "4.4.4.4", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-3"}},
357+
},
358+
Ports: []kapi.EndpointPort{{Port: 8080}},
359+
},
360+
},
361+
},
362+
expectedServiceUnit: &ServiceUnit{
363+
Name: "foo/test",
364+
EndpointTable: []Endpoint{
365+
{
366+
ID: "pod:pod-2:test:3.3.3.3:8080",
367+
IP: "3.3.3.3",
368+
Port: "8080",
369+
NoHealthCheck: false,
370+
},
371+
{
372+
ID: "pod:pod-3:test:4.4.4.4:8080",
373+
IP: "4.4.4.4",
374+
Port: "8080",
375+
NoHealthCheck: false,
376+
},
377+
},
378+
},
379+
},
380+
{
381+
name: "Endpoint mod (one ep, two ports)",
382+
eventType: watch.Modified,
383+
endpoints: &kapi.Endpoints{
384+
ObjectMeta: metav1.ObjectMeta{
385+
Namespace: "foo",
386+
Name: "test",
387+
},
388+
Subsets: []kapi.EndpointSubset{
389+
{
390+
Addresses: []kapi.EndpointAddress{
391+
{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-2"}},
392+
},
393+
Ports: []kapi.EndpointPort{{Port: 8080}, {Port: 8081}},
394+
},
395+
},
396+
},
397+
expectedServiceUnit: &ServiceUnit{
398+
Name: "foo/test",
399+
EndpointTable: []Endpoint{
400+
{
401+
ID: "pod:pod-2:test:3.3.3.3:8080",
402+
IP: "3.3.3.3",
403+
Port: "8080",
404+
NoHealthCheck: false,
405+
},
406+
{
407+
ID: "pod:pod-2:test:3.3.3.3:8081",
408+
IP: "3.3.3.3",
409+
Port: "8081",
410+
NoHealthCheck: false,
411+
},
412+
},
413+
},
414+
},
415+
{
416+
name: "Endpoint mod (back to one ep)",
417+
eventType: watch.Modified,
418+
endpoints: &kapi.Endpoints{
419+
ObjectMeta: metav1.ObjectMeta{
420+
Namespace: "foo",
421+
Name: "test",
422+
},
423+
Subsets: []kapi.EndpointSubset{{
424+
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-1"}}},
425+
Ports: []kapi.EndpointPort{{Port: 8080}},
426+
}},
427+
},
428+
expectedServiceUnit: &ServiceUnit{
429+
Name: "foo/test",
430+
EndpointTable: []Endpoint{
431+
{
432+
ID: "pod:pod-1:test:3.3.3.3:8080",
433+
IP: "3.3.3.3",
434+
Port: "8080",
435+
NoHealthCheck: true,
301436
},
302437
},
303438
},
@@ -311,8 +446,8 @@ func TestHandleEndpoints(t *testing.T) {
311446
Name: "test",
312447
},
313448
Subsets: []kapi.EndpointSubset{{
314-
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3"}},
315-
Ports: []kapi.EndpointPort{{Port: 0}},
449+
Addresses: []kapi.EndpointAddress{{IP: "3.3.3.3", TargetRef: &kapi.ObjectReference{Kind: "Pod", Name: "pod-1"}}},
450+
Ports: []kapi.EndpointPort{{Port: 8080}},
316451
}},
317452
},
318453
expectedServiceUnit: &ServiceUnit{

0 commit comments

Comments
 (0)