only prewarm the route table if requested (#1765)

This commit is contained in:
Dominic Wong 2020-07-01 10:05:21 +01:00 committed by GitHub
parent dcf01ebbf0
commit 58845d7012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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{