-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path00-main.go
More file actions
150 lines (122 loc) · 2.77 KB
/
00-main.go
File metadata and controls
150 lines (122 loc) · 2.77 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
package main
import (
"flag"
"os"
"strconv"
"strings"
"sync"
"time"
)
const regexpIdentifier = "⧆"
const substitutionIdentifier = "⧈"
const defaultMaxHTTPAttempts = 180
const defaultHTTPRetryDelay = 1 * time.Second
const defaultHTTPTimeout = 30 * time.Second
func main() {
startedAt := time.Now()
var hostname string
var httpRetryDelay time.Duration
var httpTimeout time.Duration
var matchersPath string
var maxHTTPAttempts int
var retryStatusCodesStr string
var scheme string
var showSubstitutions bool
var skipTLSVerification bool
flag.StringVar(
&hostname,
"hostname",
"",
"hostname",
)
flag.DurationVar(
&httpRetryDelay,
"http-retry-delay",
defaultHTTPRetryDelay,
"delay between failed HTTP requests",
)
flag.DurationVar(
&httpTimeout,
"http-timeout",
defaultHTTPTimeout,
"timeout per HTTP request",
)
flag.StringVar(
&matchersPath,
"matchers",
"",
"path to custom matchers JSON file",
)
flag.IntVar(
&maxHTTPAttempts,
"max-http-attempts",
defaultMaxHTTPAttempts,
"maximum number of attempts per HTTP request",
)
flag.StringVar(
&retryStatusCodesStr,
"retry-status-codes",
"",
"comma-separated HTTP status codes to retry on (e.g. 502,503)",
)
flag.StringVar(
&scheme,
"scheme",
"http",
"scheme (http/https)",
)
flag.BoolVar(
&showSubstitutions,
"show-substitutions",
false,
"show substitutions table on success (always shown on failure)",
)
flag.BoolVar(
&skipTLSVerification,
"skip-tls-verification",
false,
"skip TLS certificate verification",
)
flag.Parse()
if len(flag.Args()) == 0 {
os.Exit(0)
}
var retryStatusCodes []int
if retryStatusCodesStr != "" {
for _, s := range strings.Split(retryStatusCodesStr, ",") {
code, err := strconv.Atoi(strings.TrimSpace(s))
if err != nil {
panic("invalid status code: " + s)
}
retryStatusCodes = append(retryStatusCodes, code)
}
}
context := &context{
Hostname: hostname,
HTTPRetryDelay: httpRetryDelay,
HTTPTimeout: httpTimeout,
LogContext: false,
LogFunctions: false,
Matchers: make(map[string]string),
MatchersPath: matchersPath,
MaxHTTPAttempts: maxHTTPAttempts,
Pathnames: flag.Args(),
ResultGathererChannel: make(chan context),
RetryStatusCodes: retryStatusCodes,
ShowSubstitutions: showSubstitutions,
SkipTLSVerification: skipTLSVerification,
StartedAt: startedAt,
Scheme: scheme,
WaitGroup: &sync.WaitGroup{},
}
err := loadMatchers(context)
if err != nil {
panic(err)
}
context.enterStage("00 main")
go resultGatherer(*context)
specFileScatterer(context)
context.WaitGroup.Wait()
close(context.ResultGathererChannel)
select {}
}