From d7cdb992b4f96603d444b7ab058594563c5fe043 Mon Sep 17 00:00:00 2001 From: janluk Date: Fri, 4 Oct 2019 17:48:43 +0200 Subject: Measure and expose DNS programming latency from Kubernetes plugin. (#3171) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For now metric is measure only for headless services. Informer has been slighlty refactored, so the code can measure latency without storing extra fields on Endpoint struct. Signed-off-by: Janek Łukaszewicz Suggestions from code review Co-Authored-By: Chris O'Haver --- plugin/kubernetes/controller.go | 72 +++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 17 deletions(-) (limited to 'plugin/kubernetes/controller.go') diff --git a/plugin/kubernetes/controller.go b/plugin/kubernetes/controller.go index f5a3e7ffd..98f82341b 100644 --- a/plugin/kubernetes/controller.go +++ b/plugin/kubernetes/controller.go @@ -88,8 +88,9 @@ type dnsControlOpts struct { namespaceLabelSelector *meta.LabelSelector namespaceSelector labels.Selector - zones []string - endpointNameMode bool + zones []string + endpointNameMode bool + skipAPIObjectsCleanup bool } // newDNSController creates a controller for CoreDNS. @@ -111,7 +112,7 @@ func newdnsController(kubeClient kubernetes.Interface, opts dnsControlOpts) *dns &api.Service{}, cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete}, cache.Indexers{svcNameNamespaceIndex: svcNameNamespaceIndexFunc, svcIPIndex: svcIPIndexFunc}, - object.ToService, + object.DefaultProcessor(object.ToService(opts.skipAPIObjectsCleanup)), ) if opts.initPodCache { @@ -123,7 +124,7 @@ func newdnsController(kubeClient kubernetes.Interface, opts dnsControlOpts) *dns &api.Pod{}, cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete}, cache.Indexers{podIPIndex: podIPIndexFunc}, - object.ToPod, + object.DefaultProcessor(object.ToPod(opts.skipAPIObjectsCleanup)), ) } @@ -134,9 +135,50 @@ func newdnsController(kubeClient kubernetes.Interface, opts dnsControlOpts) *dns WatchFunc: endpointsWatchFunc(dns.client, api.NamespaceAll, dns.selector), }, &api.Endpoints{}, - cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete}, + cache.ResourceEventHandlerFuncs{}, cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc}, - object.ToEndpoints) + func(clientState cache.Indexer, h cache.ResourceEventHandler) cache.ProcessFunc { + return func(obj interface{}) error { + for _, d := range obj.(cache.Deltas) { + + apiEndpoints, obj := object.ToEndpoints(d.Object) + + switch d.Type { + case cache.Sync, cache.Added, cache.Updated: + if old, exists, err := clientState.Get(obj); err == nil && exists { + if err := clientState.Update(obj); err != nil { + return err + } + h.OnUpdate(old, obj) + // endpoint updates can come frequently, make sure it's a change we care about + if !endpointsEquivalent(old.(*object.Endpoints), obj) { + dns.updateModifed() + recordDNSProgrammingLatency(dns.getServices(obj), apiEndpoints) + } + } else { + if err := clientState.Add(obj); err != nil { + return err + } + h.OnAdd(d.Object) + dns.updateModifed() + recordDNSProgrammingLatency(dns.getServices(obj), apiEndpoints) + } + case cache.Deleted: + if err := clientState.Delete(obj); err != nil { + return err + } + h.OnDelete(d.Object) + dns.updateModifed() + recordDNSProgrammingLatency(dns.getServices(obj), apiEndpoints) + } + if !opts.skipAPIObjectsCleanup { + *apiEndpoints = api.Endpoints{} + } + } + return nil + } + }) + } dns.nsLister, dns.nsController = cache.NewInformer( @@ -423,17 +465,6 @@ func (dns *dnsControl) detectChanges(oldObj, newObj interface{}) { switch ob := obj.(type) { case *object.Service: dns.updateModifed() - case *object.Endpoints: - if newObj == nil || oldObj == nil { - dns.updateModifed() - return - } - p := oldObj.(*object.Endpoints) - // endpoint updates can come frequently, make sure it's a change we care about - if endpointsEquivalent(p, ob) { - return - } - dns.updateModifed() case *object.Pod: dns.updateModifed() default: @@ -441,6 +472,10 @@ func (dns *dnsControl) detectChanges(oldObj, newObj interface{}) { } } +func (dns *dnsControl) getServices(endpoints *object.Endpoints) []*object.Service { + return dns.SvcIndex(object.EndpointsKey(endpoints.GetName(), endpoints.GetNamespace())) +} + // subsetsEquivalent checks if two endpoint subsets are significantly equivalent // I.e. that they have the same ready addresses, host names, ports (including protocol // and service names for SRV) @@ -483,6 +518,9 @@ func subsetsEquivalent(sa, sb object.EndpointSubset) bool { // endpointsEquivalent checks if the update to an endpoint is something // that matters to us or if they are effectively equivalent. func endpointsEquivalent(a, b *object.Endpoints) bool { + if a == nil || b == nil { + return false + } if len(a.Subsets) != len(b.Subsets) { return false -- cgit v1.2.3 Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2022-02-07[ci] yarn formatGravatar matthewp 1-1/+1
2022-02-07[ci] update lockfile (#2543)Gravatar Fred K. Schott 1-171/+178
2022-02-07improve debug logs (#2537)Gravatar Fred K. Schott 3-4/+19
2022-02-07[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-06[ci] update lockfile (#2527)Gravatar Fred K. Schott 1-208/+238
2022-02-06[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-05[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-04[ci] yarn formatGravatar natemoo-re 1-2/+3
2022-02-04fix: HTML/SVG boolean attributes (#2538)Gravatar Nate Moore 2-3/+21
2022-02-04[ci] yarn formatGravatar matthewp 1-4/+2
2022-02-04fix: import local plugins into markdown (#2534)Gravatar Juan Martín Seery 9-22/+41
2022-02-04[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-03Append to list of HMR modules, don't override (#2532)Gravatar Matthew Phillips 2-1/+6
2022-02-03add back dev server host support (#2531)Gravatar Fred K. Schott 2-1/+14
2022-02-03simplify status code regexGravatar Fred K. Schott 2-87/+4
2022-02-03Adding StackUp Digital to the list of sponsors (#2521)Gravatar Astroalex 3-0/+10
2022-02-03[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-03[ci] yarn formatGravatar FredKSchott 2-3/+85
2022-02-02Handles all http error code file names the same as 404 files. (#2525)Gravatar Zade Viggers 2-4/+7
2022-02-02fix(sitemap): remove debug if sitemap disabled (#2514)Gravatar Mark Pinero 1-2/+2
2022-02-02[ci] update lockfile (#2515)Gravatar Fred K. Schott 1-276/+279
2022-02-02[ci] yarn formatGravatar matthewp 1-8/+8
2022-02-02[ci] release (next) (#2523)astro@0.23.0-next.1Gravatar github-actions[bot] 28-34/+41
2022-02-02[ci] yarn formatGravatar matthewp 2-17/+29
2022-02-02Fix support for scss in static build (#2522)Gravatar Matthew Phillips 6-20/+114
2022-02-02[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-01[ci] yarn formatGravatar matthewp 2-12/+12
2022-02-01[ci] release (next) (#2492)astro@0.23.0-next.0@astrojs/test-static-build-pkg@0.0.2@astrojs/markdown-remark@0.6.1-next.0Gravatar github-actions[bot] 31-43/+93
2022-02-01[ci] collect statsGravatar FredKSchott 1-0/+1
2022-01-31update congratsbot format againGravatar Fred K. Schott 1-1/+1
2022-01-31update congratsbot againGravatar Fred K. Schott 1-1/+1
2022-01-31Remove SVG animation on GitHub/NPM (#2512)Gravatar Nate Moore 1-21/+0
2022-01-31[ci] yarn formatGravatar natemoo-re 2-4/+6
2022-01-31Add Shiki as an alternative to Prism (#2497)Gravatar Juan Martín Seery 26-9/+356
2022-01-31Deprecate unescaped HTML inside of expressions (#2489)Gravatar Nate Moore 9-31/+74