MCPcopy Index your code
hub / github.com/zalando/skipper / initializeEndpoints

Function initializeEndpoints

proxy/fadein_internal_test.go:56–97  ·  view source on GitHub ↗
(endpointAges []float64, algorithmName string, fadeInDuration time.Duration)

Source from the content-addressed store, hash-verified

54}
55
56func initializeEndpoints(endpointAges []float64, algorithmName string, fadeInDuration time.Duration) (*routing.Route, *Proxy, []string) {
57 var detectionTimes []time.Time
58 now := time.Now()
59 for _, ea := range endpointAges {
60 endpointAgeDuration := multiply(ea, fadeInDuration)
61 detectionTimes = append(detectionTimes, now.Add(-endpointAgeDuration))
62 }
63
64 var eps []string
65 for i, ea := range endpointAges {
66 endpointAgeDuration := multiply(ea, fadeInDuration)
67 eps = append(eps, fmt.Sprintf("http://ep-%d-%s.test", i, endpointAgeDuration))
68 }
69
70 registry := routing.NewEndpointRegistry(routing.RegistryOptions{})
71 eskipRoute := eskip.Route{BackendType: eskip.LBBackend, LBAlgorithm: algorithmName}
72 for i := range eps {
73 eskipRoute.LBEndpoints = append(eskipRoute.LBEndpoints, &eskip.LBEndpoint{Address: eps[i]})
74 registry.GetMetrics(eps[i]).SetDetected(detectionTimes[i])
75 }
76
77 route := &routing.Route{
78 Route: eskipRoute,
79 LBFadeInDuration: fadeInDuration,
80 LBFadeInExponent: 1,
81 LBEndpoints: []routing.LBEndpoint{},
82 }
83
84 rt := loadbalancer.NewAlgorithmProvider().Do([]*routing.Route{route})
85 route = rt[0]
86 registry.Do([]*routing.Route{route})
87
88 eps = []string{}
89 for i, ea := range endpointAges {
90 endpointAgeDuration := multiply(ea, fadeInDuration)
91 eps = append(eps, fmt.Sprintf("ep-%d-%s.test:80", i, endpointAgeDuration))
92 registry.GetMetrics(eps[i]).SetDetected(detectionTimes[i])
93 }
94
95 proxy := &Proxy{registry: registry, fadein: &fadeIn{rnd: rand.New(rand.NewPCG(0, 0))}, quit: make(chan struct{})}
96 return route, proxy, eps
97}
98
99// This function is needed to calculate the duration needed to send fadeInRequestCount requests.
100// It is needed to send number of requests close to fadeInRequestCount on one hand and to have them sent exactly

Calls 9

GetMetricsMethod · 0.95
DoMethod · 0.95
NewEndpointRegistryFunction · 0.92
NewAlgorithmProviderFunction · 0.92
multiplyFunction · 0.85
NewMethod · 0.80
AddMethod · 0.65
SetDetectedMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…