add metrics aggregation (#3452)

This commit is contained in:
Denis Mishin 2022-06-30 10:52:45 -04:00 committed by GitHub
parent 86625a4ddb
commit f67b33484b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 229 additions and 77 deletions

22
pkg/netutil/netutil.go Normal file
View file

@ -0,0 +1,22 @@
// Package netutil contains various functions that help with networking.
package netutil
import "net"
// AllocatePorts allocates random ports suitable for listening.
func AllocatePorts(count int) ([]string, error) {
var ports []string
for i := 0; i < count; i++ {
li, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return nil, err
}
_, port, _ := net.SplitHostPort(li.Addr().String())
err = li.Close()
if err != nil {
return nil, err
}
ports = append(ports, port)
}
return ports, nil
}