-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathoptions.go
128 lines (111 loc) · 4.28 KB
/
options.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
package config
import (
"bufio"
"flag"
"fmt"
"io"
"os"
"time"
"k8s.io/apimachinery/pkg/api/resource"
log "github.com/ViaQ/logerr/v2/log/static"
"github.com/openshift/cluster-logging-operator/internal/constants"
"github.com/openshift/cluster-logging-operator/test"
)
const (
LogStressorImage = "quay.io/openshift-logging/cluster-logging-load-client:0.2"
imageVector = "quay.io/openshift-logging/vector:6.0"
)
type Options struct {
Image string
TotalMessages int
MsgSize int
BaseLine bool
DoCleanup bool
Sample bool
Platform string
Output string
TotalLogStressors int
LinesPerSecond int
ArtifactDir string
CollectorConfigPath string
CollectorConfig string
ReadTimeout string
RunDuration string
SampleDuration string
PayloadSource string
RequestCPU string
}
func InitOptions() Options {
options := Options{
ReadTimeout: test.SuccessTimeout().String(),
}
fs := flag.NewFlagSet("functional-benchmarker", flag.ExitOnError)
fs.StringVar(&options.Image, "image", imageVector, "The Image to use to run the benchmark (default: "+imageVector+")")
//fs.IntVar(&options.TotalMessages, "tot-messages", 10000, "The number of messages to write per stressor")
fs.IntVar(&options.MsgSize, "size", 1024, "The message size in bytes per stressor for 'synthetic' payload")
fs.IntVar(&options.LinesPerSecond, "lines-per-sec", 1, "The log lines per second per stressor")
fs.BoolVar(&options.DoCleanup, "do-cleanup", true, "set to false to preserve the namespace")
//fs.BoolVar(&options.BaseLine, "baseline", false, "run the test with a baseline config. This supercedes --collector-config")
//fs.StringVar(&options.Platform, "platform", "cluster", "The runtime environment: cluster, local. local requires podman")
fs.StringVar(&options.PayloadSource, "payload-source", "synthetic", "The load message profile: synthetic,application,simple")
fs.StringVar(&options.ReadTimeout, "read-timeout", test.SuccessTimeout().String(), "The read timeout duration to wait for logs")
fs.StringVar(&options.RunDuration, "run-duration", "5m", "The duration of the test run")
fs.StringVar(&options.SampleDuration, "sample-duration", "1s", "The frequency to sample cpu and memory")
fs.IntVar(&options.TotalLogStressors, "tot-stressors", 1, "Total log stressors")
fs.StringVar(&options.CollectorConfigPath, "collector-config", "", "The path to the collector config to use")
fs.StringVar(&options.ArtifactDir, "artifact-dir", "", "The directory to write artifacts (default: Time.now())")
fs.StringVar(&options.RequestCPU, "request-cpu", "", "The amount of CPU request to allocate for the collector")
if err := fs.Parse(os.Args[1:]); err != nil {
fmt.Printf("Error parsing argument: %v", err)
os.Exit(1)
}
log.V(3).Info("Parsed options", "options", options)
if options.RequestCPU != "" {
if _, err := resource.ParseQuantity(options.RequestCPU); err != nil {
fmt.Printf("Error parsing request-cpu %q: %v", options.RequestCPU, err)
os.Exit(1)
}
}
log.V(1).Info("Starting functional benchmarker", "args", options)
imageEnvVar := constants.VectorImageEnvVar
if err := os.Setenv(imageEnvVar, options.Image); err != nil {
log.Error(err, "Error setting collector Image env var")
os.Exit(1)
}
return options
}
func ReadConfig(configFile string, baseline bool) string {
if baseline {
log.V(0).Info("Using the baseline config. Modifying source to collect only loader")
return ""
}
var reader func() ([]byte, error)
switch configFile {
case "-":
log.V(1).Info("Reading from stdin")
reader = func() ([]byte, error) {
stdin := bufio.NewReader(os.Stdin)
return io.ReadAll(stdin)
}
case "":
log.V(1).Info("received empty configFile. Generating from CLF")
return ""
default:
log.V(1).Info("reading configfile", "filename", configFile)
reader = func() ([]byte, error) { return os.ReadFile(configFile) }
}
content, err := reader()
if err != nil {
log.Error(err, "Error reading config")
os.Exit(1)
}
return string(content)
}
func MustParseDuration(durationString, optionName string) time.Duration {
duration, err := time.ParseDuration(durationString)
if err != nil {
log.Error(err, "Unable to parse duration", "option", optionName)
os.Exit(1)
}
return duration
}