elastic / elastic-agent

Elastic Agent - single, unified way to add monitoring for logs, metrics, and other types of data to a host.
Other
16 stars 143 forks source link

Use math/rand/v2 in place of math/rand #5335

Closed mauri870 closed 2 months ago

mauri870 commented 2 months ago

Describe the enhancement:

In Go 1.22 we got a new package math/rand/v2 that replaces the aging math/rand.

Some improvements include better performance and scalability as well as safer algorithms. See Evolving the Go Standard Library with math/rand/v2.

Since our go.mod file requires go1.22.4 minimum we can safely depend on this new package.

What is the definition of done?

All occurrences of math/rand are replaced with math/rand/v2.

Grepping for math/rand usage I got:

$ rg -l '"math/rand"' | xargs rg 'rand\.'
main.go
39:     rand.Seed(time.Now().UnixNano())

internal/pkg/scheduler/scheduler.go
133:    return time.Duration(rand.Int63n(t))

magefile.go
2109:           bkpName := fmt.Sprintf("./env.sh-%d", rand.Int())

internal/pkg/remote/client.go
267:    rand.Shuffle(len(clients), func(i, j int) {

internal/pkg/core/backoff/equal_jitter.go
33:             nextRand: time.Duration(rand.Int63n(int64(init))), //nolint:gosec
54:     b.nextRand = time.Duration(rand.Int63n(int64(b.duration)))

testing/integration/install_test.go
337:    rand.Seed(time.Now().UnixNano())
342:            runes[i] = letters[rand.Intn(len(letters))]

internal/pkg/agent/cmd/enroll_cmd.go
707:    t := time.NewTimer(time.Duration(rand.Int63n(int64(d))))

internal/pkg/agent/application/upgrade/marker_access_test.go
162:            rune := chars[rand.Intn(len(chars))]

internal/pkg/agent/application/upgrade/artifact/download/http/verifier_test.go
114:    first := rand.Intn(len(tt))
115:    second := rand.Intn(len(tt))
elasticmachine commented 2 months ago

Pinging @elastic/elastic-agent (Team:Elastic-Agent)