From 58845d701206af077d2aef7c29ae63e4981a48e5 Mon Sep 17 00:00:00 2001 From: Dominic Wong Date: Wed, 1 Jul 2020 10:05:21 +0100 Subject: [PATCH] only prewarm the route table if requested (#1765) --- router/default.go | 8 +++++--- router/options.go | 11 ++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/router/default.go b/router/default.go index 5d20b953..552f06da 100644 --- a/router/default.go +++ b/router/default.go @@ -467,9 +467,11 @@ func (r *router) start() error { return nil } - // add all local service routes into the routing table - if err := r.manageRegistryRoutes(r.options.Registry, "create"); err != nil { - return fmt.Errorf("failed adding registry routes: %s", err) + if r.options.Prewarm { + // add all local service routes into the routing table + if err := r.manageRegistryRoutes(r.options.Registry, "create"); err != nil { + return fmt.Errorf("failed adding registry routes: %s", err) + } } // add default gateway into routing table diff --git a/router/options.go b/router/options.go index 94c96c07..cba10356 100644 --- a/router/options.go +++ b/router/options.go @@ -23,6 +23,8 @@ type Options struct { Advertise Strategy // Context for additional options Context context.Context + // Prewarm the route table on router startup + Prewarm bool } // Id sets Router Id @@ -60,13 +62,20 @@ func Registry(r registry.Registry) Option { } } -// Strategy sets route advertising strategy +// Advertise sets route advertising strategy func Advertise(a Strategy) Option { return func(o *Options) { o.Advertise = a } } +// Prewarm sets whether to prewarm the route table +func Prewarm(b bool) Option { + return func(o *Options) { + o.Prewarm = b + } +} + // DefaultOptions returns router default options func DefaultOptions() Options { return Options{