Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

udating math/rand #6740

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/prometheus-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,42 @@ due to a non-default GODEBUG=installgoroot=... setting. Sourced from
/godebug/non-default-behavior/installgoroot:events
- **go_godebug_non_default_behavior_multipartmaxheaders_events_total:**
The number of non-default behaviors executed by the mime/multipart package
<<<<<<< HEAD
due to a non-default GODEBUG=multipartmaxheaders=... setting.
- **go_godebug_non_default_behavior_multipartmaxparts_events_total:** The
number of non-default behaviors executed by the mime/multipart package due
to a non-default GODEBUG=multipartmaxparts=... setting.
- **go_godebug_non_default_behavior_multipathtcp_events_total:** The number
of non-default behaviors executed by the net package due to a non-default
GODEBUG=multipathtcp=... setting.
- **go_godebug_non_default_behavior_netedns0_events_total:** The number
of non-default behaviors executed by the net package due to a non-default
GODEBUG=netedns0=... setting.
- **go_godebug_non_default_behavior_panicnil_events_total:** The number of
non-default behaviors executed by the runtime package due to a non-default
GODEBUG=panicnil=... setting.
- **go_godebug_non_default_behavior_randautoseed_events_total:** The number of
non-default behaviors executed by the math/rand/v2 package due to a non-default
GODEBUG=randautoseed=... setting.
- **go_godebug_non_default_behavior_tarinsecurepath_events_total:** The
number of non-default behaviors executed by the archive/tar package due to
a non-default GODEBUG=tarinsecurepath=... setting.
- **go_godebug_non_default_behavior_tls10server_events_total:** The number of
non-default behaviors executed by the crypto/tls package due to a non-default
GODEBUG=tls10server=... setting.
- **go_godebug_non_default_behavior_tls3des_events_total:** The number of
non-default behaviors executed by the crypto/tls package due to a non-default
GODEBUG=tls3des=... setting.
- **go_godebug_non_default_behavior_tlsmaxrsasize_events_total:** The
number of non-default behaviors executed by the crypto/tls package due to
a non-default GODEBUG=tlsmaxrsasize=... setting.
- **go_godebug_non_default_behavior_tlsrsakex_events_total:** The number of
non-default behaviors executed by the crypto/tls package due to a non-default
GODEBUG=tlsrsakex=... setting.
- **go_godebug_non_default_behavior_tlsunsafeekm_events_total:** The number of
non-default behaviors executed by the crypto/tls package due to a non-default
GODEBUG=tlsunsafeekm=... setting.
=======
due to a non-default GODEBUG=multipartmaxheaders=... setting. Sourced from
/godebug/non-default-behavior/multipartmaxheaders:events
- **go_godebug_non_default_behavior_multipartmaxparts_events_total:**
Expand Down Expand Up @@ -551,6 +587,7 @@ due to a non-default GODEBUG=tlsrsakex=... setting. Sourced from
number of non-default behaviors executed by the crypto/tls package
due to a non-default GODEBUG=tlsunsafeekm=... setting. Sourced from
/godebug/non-default-behavior/tlsunsafeekm:events
>>>>>>> a419c8c95448136b1897783cbd01aaf3236134db
- **go_godebug_non_default_behavior_winreadlinkvolume_events_total:**
The number of non-default behaviors executed by the os package due
to a non-default GODEBUG=winreadlinkvolume=... setting. Sourced from
Expand Down
4 changes: 2 additions & 2 deletions multicluster/test/e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package e2e
import (
"encoding/json"
"fmt"
"math/rand"
"math/rand/v2"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -509,7 +509,7 @@ func (data *MCTestData) getNodeNamesFromCluster(clusterName string) (string, str
return "", "", fmt.Errorf("error when getting Node list: %v, stderr: %s", err, stderr)
}
nodes := strings.Split(strings.TrimRight(output, " "), " ")
gwIdx := rand.Intn(len(nodes)) // #nosec G404: for test only
gwIdx := rand.IntN(len(nodes)) // #nosec G404: for test only
var regularNode string
for i, node := range nodes {
if i != gwIdx {
Expand Down
16 changes: 9 additions & 7 deletions pkg/agent/controller/egress/ip_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,15 @@ func TestSchedule(t *testing.T) {
}

func BenchmarkSchedule(b *testing.B) {
var egresses []runtime.Object
for i := 0; i < 1000; i++ {
egresses = append(egresses, &crdv1b1.Egress{
ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("egress-%d", i), UID: types.UID(fmt.Sprintf("uid-%d", i)), CreationTimestamp: metav1.NewTime(time.Unix(int64(i), 0))},
Spec: crdv1b1.EgressSpec{EgressIP: fmt.Sprintf("1.1.%d.%d", rand.Intn(256), rand.Intn(256)), ExternalIPPool: "pool1"},
})
}
rnd := rand.New(rand.NewSource(time.Now().UnixNano())) // Create a new source of randomness
var egresses []runtime.Object
for i := 0; i < 1000; i++ {
egresses = append(egresses, &crdv1b1.Egress{
ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("egress-%d", i), UID: types.UID(fmt.Sprintf("uid-%d", i)), CreationTimestamp: metav1.NewTime(time.Unix(int64(i), 0))},
Spec: crdv1b1.EgressSpec{EgressIP: fmt.Sprintf("1.1.%d.%d", rnd.Intn(256), rnd.Intn(256)), ExternalIPPool: "pool1"},
})
}
}
var nodes []string
for i := 0; i < 1000; i++ {
nodes = append(nodes, fmt.Sprintf("node-%d", i))
Expand Down
6 changes: 3 additions & 3 deletions pkg/agent/flowexporter/exporter/exporter_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"flag"
"fmt"
"math"
"math/big"
"net"
"net/netip"
"testing"
Expand Down Expand Up @@ -332,8 +331,9 @@ func addDenyConns(connStore *connections.DenyConnectionStore, expirePriorityQueu
}

func getRandomNum(value int64) uint64 {
number, _ := rand.Int(rand.Reader, big.NewInt(value))
return number.Uint64()
rnd := rand.New(rand.NewSource(time.Now().UnixNano())) // Create a new source of randomness
return uint64(rnd.IntN(value)) // Use IntN to generate a random number

}

func disableLogToStderr() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/monitortool/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package monitortool

import (
"context"
"math/rand"
"math/rand/v2"
"net"
"sync"
"sync/atomic"
Expand All @@ -40,7 +40,7 @@ import (
)

// #nosec G404: random number generator not used for security purposes.
var icmpEchoID = rand.Int31n(1 << 16)
var icmpEchoID = rand.IntN(1 << 16)

const (
ipv4ProtocolICMPRaw = "ip4:icmp"
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/multicast/mcast_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package multicast
import (
"context"
"fmt"
"math/rand"
"math/rand/v2"
"net"
"os"
"sync"
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/openflow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package openflow

import (
"fmt"
"math/rand"
"math/rand/v2"
"net"

"antrea.io/libOpenflow/openflow15"
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/openflow/cookie/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package cookie

import (
"math/rand"
"math/rand/v2"
"sync"
"testing"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ func statMaxMemAlloc(maxAlloc *uint64, interval time.Duration, stopCh chan struc
}

func getRandomIP() string {
return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(256))
return fmt.Sprintf("%d.%d.%d.%d", rand.IntN(256), rand.IntN(256), rand.IntN(256), rand.IntN(256))
}

func getRandomNodeName() string {
return fmt.Sprintf("Node-%d", rand.Intn(1000))
return fmt.Sprintf("Node-%d", rand.IntN(1000))
}

// getXObjects calls the provided getObjectsFunc x times and aggregate the objects.
Expand Down
3 changes: 2 additions & 1 deletion pkg/flowaggregator/s3uploader/s3uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package s3uploader
import (
"bytes"
"compress/gzip"

"context"
"fmt"
"io"
"math/rand"
"math/rand/v2"
"sync"
"time"

Expand Down
2 changes: 1 addition & 1 deletion pkg/ovs/openflow/ofctrl_packetout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package openflow

import (
"math/rand"
"math/rand/v2"
"net"
"reflect"
"testing"
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/podstore/podstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func BenchmarkGetPodByIPAndTime(b *testing.B) {
b.Run(fmt.Sprintf("input_size_%d", v.input), func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
randomPod := podArray[rand.Intn(v.input)]
randomPod := podArray[rand.IntN(v.input)]
creationTime := podStore.timestampMap[randomPod.UID].CreationTimestamp
_, ok := podStore.GetPodByIPAndTime(randomPod.Status.PodIPs[0].IP, creationTime.Add(time.Millisecond))
total++
Expand Down Expand Up @@ -523,7 +523,7 @@ func addPods(number int, k8sClient kubernetes.Interface) ([]*v1.Pod, error) {
func generatePod() *v1.Pod {
ip := getRandomIP()
uid := uuid.New().String()
startTime := rand.Intn(360000000)
startTime := rand.IntN(360000000)
creationTime := refTime.Add(time.Duration(startTime))
deletionTime := creationTime.Add(time.Hour)
pod := &v1.Pod{
Expand All @@ -546,5 +546,5 @@ func generatePod() *v1.Pod {
}

func getRandomIP() string {
return fmt.Sprintf("%d.%d.%d.%d", rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(256))
return fmt.Sprintf("%d.%d.%d.%d", rand.IntN(256), rand.IntN(256), rand.IntN(256), rand.IntN(256))
}
4 changes: 2 additions & 2 deletions test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"encoding/json"
"fmt"
"io"
"math/rand"
"math/rand/v2"
"net"
"os"
"path"
Expand Down Expand Up @@ -2201,7 +2201,7 @@ func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
// #nosec G404: random number generator not used for security purposes
randIdx := rand.Intn(len(lettersAndDigits))
randIdx := rand.IntN(len(lettersAndDigits))
b[i] = lettersAndDigits[randIdx]
}
return string(b)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"flag"
"fmt"
"math/rand"
"math/rand/v2"
"net/url"
"strings"
"testing"
Expand Down
Empty file added test/e2e/performance_test.go
Empty file.
2 changes: 1 addition & 1 deletion test/integration/agent/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package agent

import (
"fmt"
"math/rand"
"math/rand/v2"
"net"
"testing"

Expand Down
Empty file added vim
Empty file.