(endpointAges []float64, algorithmName string, fadeInDuration time.Duration)
| 54 | } |
| 55 | |
| 56 | func 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 |
no test coverage detected
searching dependent graphs…