-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathflags.go
More file actions
365 lines (349 loc) · 9.18 KB
/
flags.go
File metadata and controls
365 lines (349 loc) · 9.18 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*
* Warp (C) 2019-2020 MinIO, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cli
import (
"fmt"
"os"
"strings"
"sync"
"github.com/minio/cli"
"github.com/minio/mc/pkg/probe"
"github.com/minio/pkg/v3/console"
"github.com/minio/warp/pkg/bench"
"github.com/minio/warp/pkg/generator"
"golang.org/x/time/rate"
)
// Collection of warp flags currently supported
var globalFlags = []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
Usage: "disable progress bar display",
Hidden: true,
},
cli.BoolFlag{
Name: "no-color",
Usage: "disable color theme",
},
cli.BoolFlag{
Name: "json",
Usage: "enable JSON formatted output",
Hidden: true,
},
cli.BoolFlag{
Name: "debug",
Usage: "enable debug output",
},
cli.BoolFlag{
Name: "insecure",
Usage: "disable TLS certificate verification",
},
cli.BoolFlag{
Name: "autocompletion",
Usage: "install auto-completion for your shell",
},
}
var profileFlags = []cli.Flag{
cli.StringFlag{
Name: "pprofdir",
Usage: "Write profiles to this folder",
Value: "pprof",
Hidden: true,
},
cli.BoolFlag{
Name: "cpu",
Usage: "Write a local CPU profile",
Hidden: true,
},
cli.BoolFlag{
Name: "mem",
Usage: "Write an local allocation profile",
Hidden: true,
},
cli.BoolFlag{
Name: "block",
Usage: "Write a local goroutine blocking profile",
Hidden: true,
},
cli.BoolFlag{
Name: "mutex",
Usage: "Write a mutex contention profile",
Hidden: true,
},
cli.BoolFlag{
Name: "threads",
Usage: "Write a threas create profile",
Hidden: true,
},
cli.BoolFlag{
Name: "trace",
Usage: "Write an local execution trace",
Hidden: true,
},
}
var globalWG sync.WaitGroup
// Set global states. NOTE: It is deliberately kept monolithic to ensure we dont miss out any flags.
func setGlobalsFromContext(ctx *cli.Context) error {
quiet := ctx.Bool("quiet")
debug := ctx.Bool("debug")
json := ctx.Bool("json")
noColor := ctx.Bool("no-color")
setGlobals(quiet, debug, json, noColor)
return nil
}
// Set global states. NOTE: It is deliberately kept monolithic to ensure we dont miss out any flags.
func setGlobals(quiet, debug, json, noColor bool) {
globalQuiet = globalQuiet || quiet
globalDebug = globalDebug || debug
globalJSON = globalJSON || json
globalNoColor = globalNoColor || noColor
// Disable colorified messages if requested.
if globalNoColor || globalQuiet {
console.SetColorOff()
}
}
// commandLine attempts to reconstruct the commandline.
func commandLine(ctx *cli.Context) string {
s := os.Args[0] + " " + ctx.Command.Name
for _, flag := range ctx.Command.Flags {
name := strings.Split(flag.GetName(), ",")[0]
val, err := flagToJSON(ctx, flag, name)
if err != nil || val == "" {
continue
}
switch name {
case "access-key", "secret-key", "influxdb", "sts-web-token":
val = "*REDACTED*"
}
s += " --" + flag.GetName() + "=" + val
}
return s
}
// Flags common across all I/O commands such as cp, mirror, stat, pipe etc.
var ioFlags = []cli.Flag{
cli.StringFlag{
Name: "host",
Usage: "host. Multiple hosts can be specified as a comma separated list.",
EnvVar: appNameUC + "_HOST",
Value: "127.0.0.1:9000",
},
cli.StringFlag{
Name: "access-key",
Usage: "Specify access key",
EnvVar: appNameUC + "_ACCESS_KEY",
Value: "",
},
cli.StringFlag{
Name: "secret-key",
Usage: "Specify secret key",
EnvVar: appNameUC + "_SECRET_KEY",
Value: "",
},
cli.StringFlag{
Name: "session-token",
Usage: "Specify secret key",
EnvVar: appNameUC + "_SESSION_TOKEN",
Value: "",
},
cli.BoolFlag{
Name: "tls",
Usage: "Use TLS (HTTPS) for transport",
EnvVar: appNameUC + "_TLS",
},
cli.BoolFlag{
Name: "ktls",
Usage: "Use Kernel TLS (HTTPS) for transport if available",
EnvVar: appNameUC + "_KTLS",
},
cli.StringFlag{
Name: "region",
Usage: "Specify a custom region",
EnvVar: appNameUC + "_REGION",
},
cli.StringFlag{
Name: "sts-web-token",
Usage: "Specify the STS web token (prefix with file: to load from a file)",
EnvVar: appNameUC + "_STS_WEB_TOKEN",
},
cli.StringFlag{
Name: "signature",
Usage: "Specify a signature method. Available values are S3V2, S3V4, IAM, STS_WEB_TOKEN",
Value: "S3V4",
Hidden: true,
},
cli.BoolFlag{
Name: "encrypt",
Usage: "encrypt/decrypt objects (using server-side encryption with random keys)",
},
cli.BoolFlag{
Name: "sse-s3-encrypt",
Usage: "server-side sse-s3 encrypt/decrypt objects",
},
cli.StringFlag{
Name: "bucket",
Value: appName + "-benchmark-bucket",
Usage: "Bucket to use for benchmark data. ALL DATA WILL BE DELETED IN BUCKET!",
},
cli.StringFlag{
Name: "host-select",
Value: string(hostSelectTypeWeighed),
Usage: fmt.Sprintf("Host selection algorithm. Can be %q or %q", hostSelectTypeWeighed, hostSelectTypeRoundrobin),
},
cli.BoolFlag{
Name: "resolve-host",
Usage: "Resolve the host(s) ip(s) (including multiple A/AAAA records)",
Hidden: true,
},
cli.IntFlag{
Name: "concurrent",
Value: 20,
Usage: "Run this many concurrent operations per warp client",
},
cli.IntFlag{
Name: "sndbuf",
Value: 32 * 1024, // 32KiB up from 4KiB default
Usage: "specify custom write socket buffer size in bytes",
Hidden: true,
},
cli.IntFlag{
Name: "rcvbuf",
Value: 32 * 1024, // 32KiB up from 4KiB default
Usage: "specify custom read socket buffer size in bytes",
Hidden: true,
},
cli.BoolFlag{
Name: "noprefix",
Usage: "Do not use separate prefix for each thread",
},
cli.StringFlag{
Name: "prefix",
Usage: "Use a custom prefix for each thread",
},
cli.BoolFlag{
Name: "disable-multipart",
Usage: "disable multipart uploads",
},
cli.BoolFlag{
Name: "disable-sha256-payload",
Usage: "disable calculating sha256 on client side for uploads",
},
cli.BoolFlag{
Name: "md5",
Usage: "Add MD5 sum to uploads",
},
cli.StringFlag{
Name: "storage-class",
Value: "",
Usage: "Specify custom storage class, for instance 'STANDARD' or 'REDUCED_REDUNDANCY'.",
},
cli.BoolFlag{
Name: "disable-http-keepalive",
Usage: "Disable HTTP Keep-Alive",
Hidden: true,
},
cli.BoolFlag{
Name: "http2",
Usage: "enable HTTP2 support if server supports it",
Hidden: true,
},
cli.BoolFlag{
Name: "stress",
Usage: "stress test only and discard output",
},
cli.StringFlag{
Name: "influxdb",
EnvVar: appNameUC + "_INFLUXDB_CONNECT",
Usage: "Send operations to InfluxDB. Specify as 'http://<token>@<hostname>:<port>/<bucket>/<org>'",
},
cli.Float64Flag{
Name: "rps-limit",
Value: 0,
Usage: "Rate limit each instance to this number of requests per second (0 to disable)",
},
cli.BoolFlag{
Name: "stdout",
Usage: "Send operations to stdout",
Hidden: true,
},
cli.StringFlag{
Name: "lookup",
Usage: "Force requests to be 'host' for host-style or 'path' for path-style lookup. Default will attempt autodetect based on remote host name.",
},
cli.StringFlag{
Name: "checksum",
Usage: "Add checksum to uploaded object. Values: CRC64NVME, CRC32[-FO], CRC32C[-FO], SHA1, SHA256, MD5, MD5CS, SHA512, XXH64, XXH3 or XXH128. Requires server trailing headers (AWS, MinIO)",
Value: "",
},
}
func getCommon(ctx *cli.Context, src func() generator.Source) bench.Common {
var extra []chan<- bench.Operation
u, err := parseInfluxURL(ctx)
if err != nil {
fatalIf(probe.NewError(err), "invalid influx config")
}
if u != nil {
if in := newInfluxDB(ctx, &globalWG); in != nil {
extra = append(extra, in)
}
}
statusln := func(s string) {
console.Eraseline()
console.Print(s)
}
if globalQuiet {
statusln = func(_ string) {}
}
if ctx.Bool("stdout") {
globalQuiet = true
statusln = func(_ string) {}
so := make(chan bench.Operation, 1000)
go func() {
i := 0
var errState bool
for op := range so {
if errState {
continue
}
errState = op.WriteCSV(os.Stdout, i) != nil
i++
}
}()
extra = append(extra, so)
}
noOps := ctx.Bool("stress")
rpsLimit := ctx.Float64("rps-limit")
var rpsLimiter *rate.Limiter
if rpsLimit > 0 {
// Allow for concurrent bursts.
rpsLimiter = rate.NewLimiter(rate.Limit(rpsLimit), ctx.Int("concurrent"))
}
// Create put options now, so ensure that trailing headers are set.
putOpts := putOpts(ctx)
return bench.Common{
Client: newClient(ctx),
Concurrency: ctx.Int("concurrent"),
Source: src,
Bucket: ctx.String("bucket"),
Location: ctx.String("region"),
PutOpts: putOpts,
DiscardOutput: noOps,
ExtraOut: extra,
RpsLimiter: rpsLimiter,
Transport: clientTransport(ctx),
UpdateStatus: statusln,
TotalClients: 1, // Default to 1 for single-client mode
}
}