-
Notifications
You must be signed in to change notification settings - Fork 99
/
launcher-pummel.go
195 lines (175 loc) · 4.26 KB
/
launcher-pummel.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"os/signal"
"strconv"
"strings"
"time"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/env"
"github.com/kolide/kit/logutil"
"github.com/kolide/kit/version"
"github.com/kolide/launcher/pkg/simulator"
"github.com/pkg/errors"
)
func main() {
var (
flVersion = flag.Bool(
"version",
env.Bool("VERSION", false),
"Print version and exit",
)
flDebug = flag.Bool(
"debug",
env.Bool("DEBUG", false),
"Print debug logs",
)
flJson = flag.Bool(
"json",
env.Bool("JSON", false),
"Print logs in JSON format",
)
flHostPath = flag.String(
"host_path",
env.String("HOST_PATH", "simulator/hosts"),
"Directory path for loading host yaml files",
)
flServerURL = flag.String(
"server_url",
env.String("SERVER_URL", "localhost:8080"),
"URL of gRPC server to load test",
)
flEnrollSecret = flag.String(
"enroll_secret",
env.String("ENROLL_SECRET", ""),
"The enroll secret that is used in your environment",
)
flEnrollSecretPath = flag.String(
"enroll_secret_path",
env.String("ENROLL_SECRET_PATH", ""),
"Optionally, the path to your enrollment secret",
)
flHosts = flag.String(
"hosts",
env.String("HOSTS", ""),
"Comma-separated list of host type and quantity i.e.: linux:1000,macos:200",
)
flInsecureTLS = flag.Bool(
"insecure",
env.Bool("INSECURE", false),
"Do not verify TLS certs for outgoing connections (default: false)",
)
flInsecureGRPC = flag.Bool(
"insecure_grpc",
env.Bool("INSECURE_GRPC", false),
"Dial GRPC without a TLS config (default: false)",
)
)
flag.Parse()
var logger log.Logger
if *flJson {
logger = log.NewJSONLogger(log.NewSyncWriter(os.Stdout))
} else {
logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
}
logger = log.With(logger,
"ts", log.DefaultTimestampUTC,
"component", "simulator",
)
logger = level.NewInjector(logger, level.InfoValue())
logger = log.With(logger, "caller", log.DefaultCaller)
if *flDebug {
logger = level.NewFilter(logger, level.AllowDebug())
} else {
logger = level.NewFilter(logger, level.AllowInfo())
}
if *flVersion {
version.PrintFull()
os.Exit(0)
}
hosts, err := simulator.LoadHosts(*flHostPath, logger)
if err != nil {
logutil.Fatal(logger,
"msg", "error loading host definitions",
"err", err,
)
}
var enrollSecret string
if *flEnrollSecret != "" {
enrollSecret = *flEnrollSecret
} else if *flEnrollSecretPath != "" {
content, err := ioutil.ReadFile(*flEnrollSecretPath)
if err != nil {
logutil.Fatal(logger, "err", errors.Wrap(err, "could not read enroll_secret_path"), "enroll_secret_path", *flEnrollSecretPath)
}
enrollSecret = string(bytes.TrimSpace(content))
}
if len(enrollSecret) == 0 {
logutil.Fatal(logger, "msg", "--enroll_secret cannot be empty")
}
level.Info(logger).Log(
"msg", "starting load testing tool",
)
hostList := strings.Split(*flHosts, ",")
if len(hostList) == 0 {
logutil.Fatal(logger, "msg", "no hosts specified")
}
for _, hostSimulation := range hostList {
simulationParts := strings.Split(hostSimulation, ":")
if len(simulationParts) != 2 {
logutil.Fatal(logger,
"msg", "arguments should be of the form host_type:count",
"arg", hostSimulation,
)
}
hostType, countStr := simulationParts[0], simulationParts[1]
count, err := strconv.Atoi(countStr)
if err != nil {
logutil.Fatal(logger,
"msg", "unable to parse count",
"arg", hostSimulation,
)
}
host, ok := hosts[hostType]
if !ok {
logutil.Fatal(logger,
"msg", "unrecognized host type",
"type", hostType,
)
}
level.Info(logger).Log(
"msg", "starting hosts",
"count", count,
)
opts := []simulator.SimulationOption{}
if *flInsecureTLS {
opts = append(opts, simulator.WithInsecure())
}
if *flInsecureGRPC {
opts = append(opts, simulator.WithInsecureGrpc())
}
// Start hosts
for i := 0; i < count; i++ {
simulator.LaunchSimulation(
logger,
host,
*flServerURL,
fmt.Sprintf("%s_%d", hostType, i),
enrollSecret,
opts...,
)
time.Sleep(10 * time.Millisecond)
}
}
level.Info(logger).Log(
"msg", "all hosts started",
)
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt)
<-sig
}