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

refactor: use rand.New(rand.NewSource) instead of deprecated rand.Seed #25279

Open
wants to merge 1 commit into
base: master-1.x
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func writePoints(clnt client.Client) {
log.Fatal(err)
}

rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < sampleSize; i++ {
regions := []string{"us-west1", "us-west2", "us-west3", "us-east1"}
tags := map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion client/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func ExampleClient_Write() {
pts = make([]client.Point, sampleSize)
)

rand.Seed(42)
rand.New(rand.NewSource(42))
for i := 0; i < sampleSize; i++ {
pts[i] = client.Point{
Measurement: "shapes",
Expand Down
2 changes: 1 addition & 1 deletion client/v2/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func ExampleClient_write1000() {
}
defer c.Close()

rand.Seed(42)
rand.New(rand.NewSource(42))

bp, _ := client.NewBatchPoints(client.BatchPointsConfig{
Database: "systemstats",
Expand Down
2 changes: 1 addition & 1 deletion cmd/influxd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
}

func main() {
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))

m := NewMain()
if err := m.Run(os.Args[1:]...); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// MakeSentence returns a string made up of n words.
// MakeSentence uses rand.Int31n and therefore calling rand.Seed will produce
// MakeSentence uses rand.Int31n and therefore calling rand.New(rand.NewSource) will produce
// deterministic results.
func MakeSentence(n int) string {
s := make([]string, n)
Expand Down
2 changes: 1 addition & 1 deletion models/tagkeysset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func BenchmarkTagKeysSet_UnionBytes(b *testing.B) {
bytes.Split([]byte("tag04,tag05"), commaB),
}

rand.Seed(20040409)
rand.New(rand.NewSource(20040409))

tests := []int{
10,
Expand Down
2 changes: 1 addition & 1 deletion pkg/encoding/simple8b/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func combine(fns ...func() []uint64) func() []uint64 {
// TestEncodeAll ensures 100% test coverage of simple8b.EncodeAll and
// verifies all output by comparing the original input with the output of simple8b.DecodeAll
func TestEncodeAll(t *testing.T) {
rand.Seed(0)
rand.New(rand.NewSource(0))

tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion services/meta/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func init() {
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
}

func Test_Data_DropDatabase(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions storage/reads/keymerger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func BenchmarkKeyMerger_MergeKeys(b *testing.B) {
bytes.Split([]byte("tag04,tag05"), commaB),
}

rand.Seed(20040409)
rand.New(rand.NewSource(20040409))

tests := []int{
10,
Expand Down Expand Up @@ -180,7 +180,7 @@ func BenchmarkKeyMerger_MergeTagKeys(b *testing.B) {
models.ParseTags([]byte("foo,tag04=v0,tag05=v0")),
}

rand.Seed(20040409)
rand.New(rand.NewSource(20040409))

tests := []int{
10,
Expand Down
2 changes: 1 addition & 1 deletion tests/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestMain(m *testing.M) {
if seed == 0 {
seed = time.Now().UnixNano()
}
rand.Seed(seed)
rand.New(rand.NewSource(seed))

var r int
for _, indexType = range tsdb.RegisteredIndexes() {
Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/tsm1/array_encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func BenchmarkDecodeIntegerArrayBlock(b *testing.B) {
}
for _, bm := range cases {
b.Run(fmt.Sprintf("%s_%d", bm.enc, bm.n), func(b *testing.B) {
rand.Seed(int64(bm.n * 1e3))
rand.New(rand.NewSource(int64(bm.n * 1e3)))

valueCount := bm.n
times := getTimes(valueCount, 60, time.Second)
Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/tsm1/batch_boolean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func Test_BooleanArrayDecodeAll_Multi_Compressed(t *testing.T) {

for _, tc := range cases {
t.Run(fmt.Sprintf("%d_%0.2f", tc.n, tc.p), func(t *testing.T) {
rand.Seed(int64(tc.n * tc.n))
rand.New(rand.NewSource(int64(tc.n * tc.n)))

enc := tsm1.NewBooleanEncoder(tc.n)
values := make([]bool, tc.n)
Expand Down
6 changes: 3 additions & 3 deletions tsdb/engine/tsm1/batch_integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ func BenchmarkIntegerArrayDecodeAllUncompressed(b *testing.B) {
}

for _, size := range benchmarks {
rand.Seed(int64(size * 1e3))
rand.New(rand.NewSource(int64(size * 1e3)))

enc := NewIntegerEncoder(size)
for i := 0; i < size; i++ {
Expand Down Expand Up @@ -1130,7 +1130,7 @@ func BenchmarkIntegerArrayDecodeAllPackedSimple(b *testing.B) {
1000,
}
for _, size := range benchmarks {
rand.Seed(int64(size * 1e3))
rand.New(rand.NewSource(int64(size * 1e3)))

enc := NewIntegerEncoder(size)
for i := 0; i < size; i++ {
Expand Down Expand Up @@ -1163,7 +1163,7 @@ func BenchmarkIntegerArrayDecodeAllRLE(b *testing.B) {
{1000, 0},
}
for _, bm := range benchmarks {
rand.Seed(int64(bm.n * 1e3))
rand.New(rand.NewSource(int64(bm.n * 1e3)))

enc := NewIntegerEncoder(bm.n)
acc := int64(0)
Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/tsm1/batch_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func BenchmarkStringArrayDecodeAll(b *testing.B) {
{1000, 10},
}
for _, bm := range benchmarks {
rand.Seed(int64(bm.n * 1e3))
rand.New(rand.NewSource(int64(bm.n * 1e3)))

s := NewStringEncoder(bm.n)
for c := 0; c < bm.n; c++ {
Expand Down
4 changes: 2 additions & 2 deletions tsdb/engine/tsm1/batch_timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ func BenchmarkTimeArrayDecodeAllUncompressed(b *testing.B) {
}

for _, size := range benchmarks {
rand.Seed(int64(size * 1e3))
rand.New(rand.NewSource(int64(size * 1e3)))

enc := NewTimeEncoder(size)
for i := 0; i < size; i++ {
Expand Down Expand Up @@ -1118,7 +1118,7 @@ func BenchmarkTimeArrayDecodeAllPackedSimple(b *testing.B) {
1000,
}
for _, size := range benchmarks {
rand.Seed(int64(size * 1e3))
rand.New(rand.NewSource(int64(size * 1e3)))

enc := NewTimeEncoder(size)
for i := 0; i < size; i++ {
Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/tsm1/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ func BenchmarkDecodeIntegerBlock(b *testing.B) {
}
for _, bm := range cases {
b.Run(fmt.Sprintf("%s_%d", bm.enc, bm.n), func(b *testing.B) {
rand.Seed(int64(bm.n * 1e3))
rand.New(rand.NewSource(int64(bm.n * 1e3)))

valueCount := bm.n
times := getTimes(valueCount, 60, time.Second)
Expand Down
4 changes: 2 additions & 2 deletions tsdb/engine/tsm1/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ func BenchmarkIntegerBatch_DecodeAllUncompressed(b *testing.B) {
}

for _, bm := range benchmarks {
rand.Seed(int64(bm.n * 1e3))
rand.New(rand.NewSource(int64(bm.n * 1e3)))

enc := NewIntegerEncoder(bm.n)
for i := 0; i < bm.n; i++ {
Expand Down Expand Up @@ -663,7 +663,7 @@ func BenchmarkIntegerBatch_DecodeAllPackedSimple(b *testing.B) {
{1000},
}
for _, bm := range benchmarks {
rand.Seed(int64(bm.n * 1e3))
rand.New(rand.NewSource(int64(bm.n * 1e3)))

enc := NewIntegerEncoder(bm.n)
for i := 0; i < bm.n; i++ {
Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/tsm1/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func BenchmarkStringDecoder_DecodeAll(b *testing.B) {
{1000, 10},
}
for _, bm := range benchmarks {
rand.Seed(int64(bm.n * 1e3))
rand.New(rand.NewSource(int64(bm.n * 1e3)))

s := NewStringEncoder(bm.n)
for c := 0; c < bm.n; c++ {
Expand Down
4 changes: 2 additions & 2 deletions tsdb/engine/tsm1/timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func BenchmarkTimeBatch_DecodeAllUncompressed(b *testing.B) {
}

for _, size := range benchmarks {
rand.Seed(int64(size * 1e3))
rand.New(rand.NewSource(int64(size * 1e3)))

enc := NewTimeEncoder(size)
for i := 0; i < size; i++ {
Expand Down Expand Up @@ -661,7 +661,7 @@ func BenchmarkTimeBatch_DecodeAllPackedSimple(b *testing.B) {
{1000},
}
for _, bm := range benchmarks {
rand.Seed(int64(bm.n * 1e3))
rand.New(rand.NewSource(int64(bm.n * 1e3)))

enc := NewTimeEncoder(bm.n)
for i := 0; i < bm.n; i++ {
Expand Down
2 changes: 1 addition & 1 deletion tsdb/index/tsi1/log_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestLogFile_SeriesStoredInOrder(t *testing.T) {

// Generate and add test data
tvm := make(map[string]struct{})
rand.Seed(time.Now().Unix())
rand.New(rand.NewSource(time.Now().Unix()))
for i := 0; i < 100; i++ {
tv := fmt.Sprintf("server-%d", rand.Intn(50)) // Encourage adding duplicate series.
tvm[tv] = struct{}{}
Expand Down
Loading