Skip to content

Commit

Permalink
Fixed the remaining comments from previous endpointregistry PR (#2821)
Browse files Browse the repository at this point in the history
#2795

Signed-off-by: Roman Zavodskikh <roman.zavodskikh@zalando.de>
Co-authored-by: Roman Zavodskikh <roman.zavodskikh@zalando.de>
  • Loading branch information
RomanZavodskikh and Roman Zavodskikh authored Jan 3, 2024
1 parent c607fdf commit 2f067f2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
12 changes: 5 additions & 7 deletions filters/fadein/fadein.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion proxy/fadeintesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
},
})

Expand Down
10 changes: 4 additions & 6 deletions routing/endpointregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions routing/endpointregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 2f067f2

Please sign in to comment.