diff --git a/filters/fadein/fadein.go b/filters/fadein/fadein.go index ecc10c384c..64105c3202 100644 --- a/filters/fadein/fadein.go +++ b/filters/fadein/fadein.go @@ -200,10 +200,6 @@ type PostProcessorOptions struct { // NewPostProcessor creates post-processor for maintaining the detection time of LB endpoints with fade-in // behavior. func NewPostProcessor(options PostProcessorOptions) routing.PostProcessor { - if options.EndpointRegistry == nil { - options.EndpointRegistry = routing.NewEndpointRegistry(routing.RegistryOptions{}) - } - return &postProcessor{ endpointRegisty: options.EndpointRegistry, detected: make(map[string]detectedFadeIn), @@ -245,9 +241,11 @@ func (p *postProcessor) Do(r []*routing.Route) []*routing.Route { } ep.Detected = detected - metrics := p.endpointRegisty.GetMetrics(ep.Host) - if endpointsCreated[key].After(metrics.DetectedTime()) { - metrics.SetDetected(endpointsCreated[key]) + if p.endpointRegisty != nil { + metrics := p.endpointRegisty.GetMetrics(ep.Host) + if endpointsCreated[key].After(metrics.DetectedTime()) { + metrics.SetDetected(endpointsCreated[key]) + } } p.detected[key] = detectedFadeIn{ when: detected, diff --git a/proxy/fadeintesting_test.go b/proxy/fadeintesting_test.go index 93d268bd29..975e74f7ff 100644 --- a/proxy/fadeintesting_test.go +++ b/proxy/fadeintesting_test.go @@ -264,12 +264,15 @@ func (p *fadeInProxy) addInstances(n int) { fr := make(filters.Registry) fr.Register(fadein.NewFadeIn()) fr.Register(fadein.NewEndpointCreated()) + + endpointRegistry := routing.NewEndpointRegistry(routing.RegistryOptions{}) rt := routing.New(routing.Options{ FilterRegistry: fr, DataClients: []routing.DataClient{client}, PostProcessors: []routing.PostProcessor{ loadbalancer.NewAlgorithmProvider(), - fadein.NewPostProcessor(fadein.PostProcessorOptions{}), + endpointRegistry, + fadein.NewPostProcessor(fadein.PostProcessorOptions{EndpointRegistry: endpointRegistry}), }, }) diff --git a/routing/endpointregistry.go b/routing/endpointregistry.go index 6c8ec39f53..5ea242c93a 100644 --- a/routing/endpointregistry.go +++ b/routing/endpointregistry.go @@ -60,11 +60,11 @@ func (e *entry) SetLastSeen(ts time.Time) { e.lastSeen.Store(ts) } -func newEntry() (result *entry) { - result = &entry{} +func newEntry() *entry { + result := &entry{} result.SetDetected(time.Time{}) result.SetLastSeen(time.Time{}) - return + return result } type EndpointRegistry struct { @@ -115,13 +115,11 @@ func NewEndpointRegistry(o RegistryOptions) *EndpointRegistry { o.LastSeenTimeout = defaultLastSeenTimeout } - result := &EndpointRegistry{ + return &EndpointRegistry{ data: sync.Map{}, lastSeenTimeout: o.LastSeenTimeout, now: time.Now, } - - return result } func (r *EndpointRegistry) GetMetrics(key string) Metrics { diff --git a/routing/endpointregistry_test.go b/routing/endpointregistry_test.go index 2bb41af925..902e3daeb4 100644 --- a/routing/endpointregistry_test.go +++ b/routing/endpointregistry_test.go @@ -263,7 +263,7 @@ func benchmarkIncInflightRequests(b *testing.B, name string, goroutines int) { } func BenchmarkIncInflightRequests(b *testing.B) { - goroutinesNums := []int{1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 48, 64, 128, 256, 512, 768, 1024, 1536, 2048, 4096} + goroutinesNums := []int{1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 48, 64, 128, 256, 512, 768, 1024, 1536, 2048, 4096, 8192, 16384, 32768} for _, goroutines := range goroutinesNums { benchmarkIncInflightRequests(b, fmt.Sprintf("%d goroutines", goroutines), goroutines) } @@ -304,7 +304,7 @@ func benchmarkGetInflightRequests(b *testing.B, name string, goroutines int) { } func BenchmarkGetInflightRequests(b *testing.B) { - goroutinesNums := []int{1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 48, 64, 128, 256, 512, 768, 1024, 1536, 2048, 4096} + goroutinesNums := []int{1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 48, 64, 128, 256, 512, 768, 1024, 1536, 2048, 4096, 8192, 16384, 32768} for _, goroutines := range goroutinesNums { benchmarkGetInflightRequests(b, fmt.Sprintf("%d goroutines", goroutines), goroutines) } @@ -345,7 +345,7 @@ func benchmarkGetDetectedTime(b *testing.B, name string, goroutines int) { } func BenchmarkGetDetectedTime(b *testing.B) { - goroutinesNums := []int{1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 48, 64, 128, 256, 512, 768, 1024, 1536, 2048, 4096} + goroutinesNums := []int{1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 48, 64, 128, 256, 512, 768, 1024, 1536, 2048, 4096, 8192, 16384, 32768} for _, goroutines := range goroutinesNums { benchmarkGetDetectedTime(b, fmt.Sprintf("%d goroutines", goroutines), goroutines) }