/
options.go
127 lines (105 loc) · 2.87 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
package options
import (
"database/sql"
"time"
"github.com/APITeamLimited/globe-test/orchestrator/libOrch"
"github.com/APITeamLimited/globe-test/orchestrator/options/validators"
"github.com/APITeamLimited/globe-test/worker/libWorker"
"github.com/APITeamLimited/globe-test/worker/libWorker/types"
"github.com/APITeamLimited/globe-test/worker/workerMetrics"
"gopkg.in/guregu/null.v3"
)
// Import script to determine options on the orchestrator
func DetermineRuntimeOptions(job libOrch.Job, gs libOrch.BaseGlobalState) (*libWorker.Options, error) {
options, err := getCompiledOptions(job, gs)
if err != nil {
return nil, err
}
// TODO: Check if MetricSamplesBufferSize config option is needed
options.MetricSamplesBufferSize = null.Int{
NullInt64: sql.NullInt64{
Int64: 0,
Valid: false,
},
}
// Prevent the user from accessing internal ip ranges
localhostIPNets := generateBannedIPNets(gs)
// validate the options
validators.BlacklistIPs(options, localhostIPNets)
err = validators.Batch(options)
if err != nil {
return nil, err
}
err = validators.BatchPerHost(options)
if err != nil {
return nil, err
}
if options.Duration.Valid {
err = validators.Duration(options, job)
if err != nil {
return nil, err
}
}
err = validators.Hosts(options, localhostIPNets)
if err != nil {
return nil, err
}
err = validators.MinIterationDuration(options)
if err != nil {
return nil, err
}
err = validators.TeardownTimeout(options)
if err != nil {
return nil, err
}
err = validators.ExecutionMode(options)
if err != nil {
return nil, err
}
err = validators.LoadDistribution(options, gs, job)
if err != nil {
return nil, err
}
err = validators.OutputConfig(options, gs.Standalone())
if err != nil {
return nil, err
}
// Check the generated and user supplied options are valid
checkedOptions, err := deriveScenariosFromShortcuts(applyDefault(options), gs.Logger())
if err != nil {
return nil, err
}
err = validators.MaxVUs(&checkedOptions, job)
if err != nil {
return nil, err
}
return &checkedOptions, nil
}
func applyDefault(options *libWorker.Options) libWorker.Options {
if options.SystemTags == nil {
options.SystemTags = &workerMetrics.DefaultSystemTagSet
}
if options.SummaryTrendStats == nil {
options.SummaryTrendStats = libWorker.DefaultSummaryTrendStats
}
defDNS := types.DefaultDNSConfig()
if !options.DNS.TTL.Valid {
options.DNS.TTL = defDNS.TTL
}
if !options.DNS.Select.Valid {
options.DNS.Select = defDNS.Select
}
if !options.DNS.Policy.Valid {
options.DNS.Policy = defDNS.Policy
}
if !options.SetupTimeout.Valid {
options.SetupTimeout.Duration = types.Duration(60 * time.Second)
}
if !options.TeardownTimeout.Valid {
options.TeardownTimeout.Duration = types.Duration(60 * time.Second)
}
if !options.InsecureSkipTLSVerify.Valid {
options.InsecureSkipTLSVerify = null.BoolFrom(false)
}
return *options
}