/
rand_deprecated.go
124 lines (110 loc) · 4.33 KB
/
rand_deprecated.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Unless explicitly stated otherwise all files in this repository are licensed
// under the MIT License.
// This product includes software developed at Guance Cloud (https://www.guance.com/).
// Copyright 2021-present Guance, Inc.
//nolint:gosec
package point
import (
"fmt"
mrand "math/rand" //nolint:gosec
"time"
"github.com/GuanceCloud/cliutils"
anypb "google.golang.org/protobuf/types/known/anypb"
)
// doRandomPoints deprecated.
func doRandomPoints(count int) ([]*Point, error) {
if count <= 0 {
return nil, nil
}
var pts []*Point
for i := 0; i < count; i++ {
if pt, err := NewPoint(cliutils.CreateRandomString(30),
map[string]string{ // 4 tags
cliutils.CreateRandomString(10): sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
cliutils.CreateRandomString(11): sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
cliutils.CreateRandomString(12): sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
cliutils.CreateRandomString(13): sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
},
map[string]interface{}{
"message": sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
cliutils.CreateRandomString(10): mrand.Int63(),
cliutils.CreateRandomString(10): mrand.Int63(),
cliutils.CreateRandomString(10): mrand.Int63(),
cliutils.CreateRandomString(10): mrand.Int63(),
cliutils.CreateRandomString(10): mrand.Int63(),
cliutils.CreateRandomString(10): mrand.Int63(),
cliutils.CreateRandomString(10): mrand.Int63(),
cliutils.CreateRandomString(10): mrand.Int63(),
cliutils.CreateRandomString(10): mrand.Int63(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): false,
cliutils.CreateRandomString(10): true,
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
cliutils.CreateRandomString(10): mrand.NormFloat64(),
}); err != nil {
return nil, err
} else {
pts = append(pts, pt)
}
}
return pts, nil
}
// RandPoints deprecated.
func RandPoints(count int) []*Point {
if pts, err := doRandomPoints(count); err != nil {
panic(fmt.Sprintf("doRandomPoints failed: %s", err))
} else {
return pts
}
}
// doRandomPBPoints deprecated.
func doRandomPBPoints(count int) (*PBPoints, error) {
if count <= 0 {
return nil, nil
}
pts := &PBPoints{}
for i := 0; i < count; i++ {
pts.Arr = append(pts.Arr, &PBPoint{
Name: cliutils.CreateRandomString(30),
Fields: []*Field{
{IsTag: true, Key: cliutils.CreateRandomString(10), Val: &Field_S{cliutils.CreateRandomString(37)}},
{IsTag: true, Key: cliutils.CreateRandomString(11), Val: &Field_S{cliutils.CreateRandomString(38)}},
{IsTag: true, Key: cliutils.CreateRandomString(12), Val: &Field_S{cliutils.CreateRandomString(39)}},
{IsTag: true, Key: cliutils.CreateRandomString(13), Val: &Field_S{cliutils.CreateRandomString(40)}},
{Key: cliutils.CreateRandomString(9), Val: &Field_S{cliutils.CreateRandomString(37)}},
{Key: cliutils.CreateRandomString(10), Val: &Field_D{[]byte(cliutils.CreateRandomString(37))}},
{Key: cliutils.CreateRandomString(11), Val: &Field_I{mrand.Int63()}},
{Key: cliutils.CreateRandomString(12), Val: &Field_F{mrand.NormFloat64()}},
{Key: cliutils.CreateRandomString(13), Val: &Field_B{false}},
{Key: cliutils.CreateRandomString(14), Val: &Field_B{true}},
{Key: cliutils.CreateRandomString(15), Val: &Field_A{A: func() *anypb.Any {
x, err := anypb.New(&AnyDemo{Demo: "random point"})
if err != nil {
panic(fmt.Sprintf("anypb.New: %s", err))
}
return x
}()}},
},
Time: time.Now().UnixNano(),
})
}
return pts, nil
}
// RandPBPoints deprecated.
func RandPBPoints(count int) *PBPoints {
if pts, err := doRandomPBPoints(count); err != nil {
panic(fmt.Sprintf("doRandomPoints failed: %s", err))
} else {
return pts
}
}