(ctx context.Context, secrets string, n int, proxyHost string)
| 31 | } |
| 32 | |
| 33 | func Random(ctx context.Context, secrets string, n int, proxyHost string) error { |
| 34 | l := zerolog.Ctx(ctx) |
| 35 | |
| 36 | if secrets == "" { |
| 37 | return errors.New("secrets required") |
| 38 | } |
| 39 | |
| 40 | if n <= 0 { |
| 41 | return errors.New("node count must be positive") |
| 42 | } |
| 43 | |
| 44 | if proxyHost == "" { |
| 45 | return errors.New("proxy host required") |
| 46 | } |
| 47 | |
| 48 | secretValue := strings.TrimSpace(secrets) |
| 49 | |
| 50 | // Parse the SAS URLs from the secret value |
| 51 | upstreamSasUrls := strings.Fields(secretValue) |
| 52 | p2pSasUrls := getP2pSasUrls(strings.Fields(secretValue), proxyHost) |
| 53 | |
| 54 | var g errgroup.Group |
| 55 | var upstreamPercentiles, p2pPercentiles []float64 |
| 56 | var upstreamErrorRate, p2pErrorRate float64 |
| 57 | |
| 58 | g.Go(func() error { |
| 59 | upstreamPercentiles, upstreamErrorRate = benchmark(l, "upstream", upstreamSasUrls, n) |
| 60 | return nil |
| 61 | }) |
| 62 | |
| 63 | delay(l) |
| 64 | |
| 65 | g.Go(func() error { |
| 66 | p2pPercentiles, p2pErrorRate = benchmark(l, "p2p", p2pSasUrls, n) |
| 67 | return nil |
| 68 | }) |
| 69 | |
| 70 | _ = g.Wait() |
| 71 | |
| 72 | // Print the results |
| 73 | if len(upstreamPercentiles) > 0 { |
| 74 | l.Info(). |
| 75 | Float64("upstream.p50", upstreamPercentiles[0]). |
| 76 | Float64("upstream.p75", upstreamPercentiles[1]). |
| 77 | Float64("upstream.p90", upstreamPercentiles[2]). |
| 78 | Float64("upstream.p95", upstreamPercentiles[3]). |
| 79 | Float64("upstream.p100", upstreamPercentiles[4]). |
| 80 | Msg("speeds (MB/s)") |
| 81 | } |
| 82 | |
| 83 | if len(p2pPercentiles) > 0 { |
| 84 | l.Info(). |
| 85 | Float64("p2p.p50", p2pPercentiles[0]). |
| 86 | Float64("p2p.p75", p2pPercentiles[1]). |
| 87 | Float64("p2p.p90", p2pPercentiles[2]). |
| 88 | Float64("p2p.p95", p2pPercentiles[3]). |
| 89 | Float64("p2p.p100", p2pPercentiles[4]). |
| 90 | Msg("speeds (MB/s)") |
no test coverage detected