chore: trace spans: use crypto/rand for generating them
math/rand.Read is deprecated in newer Go versions. Also, it appears that crypto/rand is faster when used from multiple goroutines: https://gist.github.com/problame/0699acd6f99db4163f26f0b8a61569f3
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package trace
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"math/rand"
|
||||
"strings"
|
||||
|
||||
"github.com/zrepl/zrepl/util/envconst"
|
||||
@@ -20,12 +20,9 @@ func genID() string {
|
||||
var out strings.Builder
|
||||
enc := base64.NewEncoder(base64.RawStdEncoding, &out)
|
||||
buf := make([]byte, genIdNumBytes)
|
||||
for i := 0; i < len(buf); {
|
||||
n, err := rand.Read(buf[i:])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
i += n
|
||||
_, err := rand.Read(buf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
n, err := enc.Write(buf[:])
|
||||
if err != nil || n != len(buf) {
|
||||
|
||||
Reference in New Issue
Block a user