From 27f49eede9a0c4984e45fabb1ff2c220ae4f9e1c Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Fri, 10 Jan 2020 10:30:13 -0500 Subject: [PATCH] =?UTF-8?q?Move=20where=20the=20service-resolver=20watch?= =?UTF-8?q?=20is=20done=20so=20that=20it=20happen=E2=80=A6=20(#7025)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before we were issuing 1 watch for every service in the services listing which would have caused the agent to process many more identical events simultaneously. --- agent/proxycfg/state.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/agent/proxycfg/state.go b/agent/proxycfg/state.go index 8622d4ecc7..9f0d3e4f87 100644 --- a/agent/proxycfg/state.go +++ b/agent/proxycfg/state.go @@ -340,6 +340,18 @@ func (s *state) initWatchesMeshGateway() error { // gateways within those other datacenters. We cannot do that here because we don't // know what they are yet. + // Watch service-resolvers so we can setup service subset clusters + err = s.cache.Notify(s.ctx, cachetype.ConfigEntriesName, &structs.ConfigEntryQuery{ + Datacenter: s.source.Datacenter, + QueryOptions: structs.QueryOptions{Token: s.token}, + Kind: structs.ServiceResolver, + }, serviceResolversWatchID, s.ch) + + if err != nil { + s.logger.Printf("[ERR] mesh-gateway: failed to register watch for service-resolver config entries") + return err + } + return err } @@ -704,18 +716,6 @@ func (s *state) handleUpdateMeshGateway(u cache.UpdateEvent, snap *ConfigSnapsho cancel() return err } - - err = s.cache.Notify(ctx, cachetype.ConfigEntriesName, &structs.ConfigEntryQuery{ - Datacenter: s.source.Datacenter, - QueryOptions: structs.QueryOptions{Token: s.token}, - Kind: structs.ServiceResolver, - }, serviceResolversWatchID, s.ch) - - if err != nil { - s.logger.Printf("[ERR] mesh-gateway: failed to register watch for service-resolver config entries") - cancel() - return err - } snap.MeshGateway.WatchedServices[svcName] = cancel } }