-
Notifications
You must be signed in to change notification settings - Fork 44
/
rum-client.go
82 lines (68 loc) · 1.56 KB
/
rum-client.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
// 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.
package main
import (
"crypto/rand"
"flag"
"fmt"
"io"
"log"
"math"
"math/big"
"net/http"
)
var (
fHost = flag.String("host", "", "")
fReqCnt = flag.Int("req-cnt", 100, "")
)
func rangeRand(min, max int64) int64 {
if min > max {
panic("the min is greater than max!")
}
if min < 0 {
f64Min := math.Abs(float64(min))
i64Min := int64(f64Min)
result, err := rand.Int(rand.Reader, big.NewInt(max+1+i64Min))
if err != nil {
return -1
}
return result.Int64() - i64Min
}
result, err := rand.Int(rand.Reader, big.NewInt(max-min+1))
if err != nil {
return -1
}
return min + result.Int64()
}
func main() {
flag.Parse()
cli := http.Client{}
for i := 0; i < *fReqCnt; i++ {
req, err := http.NewRequest("GET", *fHost, nil)
if err != nil {
log.Fatal(err)
}
i := rangeRand(1000000000000000000, 8888888888888888888)
log.Println(i)
req.Header.Set("X-Datadog-Origin", "rum")
req.Header.Set("X-Datadog-Trace-ID", fmt.Sprintf("%d", i))
req.Header.Set("X-Datadog-Sampled", "0")
req.Header.Set("X-Datadog-Origin", "rum")
req.Header.Set("x-datadog-sampling-priority", "0")
resp, err := cli.Do(req)
if err != nil {
log.Println(err)
continue
}
_, err = io.ReadAll(resp.Body)
if err != nil {
log.Println(err)
continue
}
if err := resp.Body.Close(); err != nil {
panic(err)
}
}
}