Skip to content

Commit 04d7514

Browse files
committed
--http-probe-client-timeout and --http-probe-client-timeout-crawl slim/profile command flags
Signed-off-by: Kyle Quest <[email protected]>
1 parent 31238c7 commit 04d7514

File tree

10 files changed

+72
-17
lines changed

10 files changed

+72
-17
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ In the interactive CLI prompt mode you must specify the target image using the `
430430
- `--poststart-compose-svc` - placeholder for now
431431
- `--http-probe` - Enables/disables HTTP probing (ENABLED by default; you have to disable the probe if you don't need it by setting the flag to `false`: `--http-probe=false`)
432432
- `--http-probe-off` - Alternative way to disable HTTP probing
433+
- `--http-probe-client-timeout` - Probe network client timeout in seconds (defaults to 30 seconds)
434+
- `--http-probe-client-timeout-crawl` - Crawl probe network client timeout in seconds (defaults to probe network client timeout if set or internal default if not, 10 seconds)
433435
- `--http-probe-cmd` - User defined HTTP probe(s) as `[[[[\"crawl\":]PROTO:]METHOD:]PATH]` [can use this flag multiple times]
434436
- `--http-probe-cmd-file` - File with user defined HTTP probe commands
435437
- `--http-probe-cmd-upload` - User defined HTTP probe(s) to submit form data as `[[[[[PROTO:]FORM_FILE_NAME:]FORM_FIELD_NAME:]FILE_OR_GENERATE_TYPE:]PATH]` [can use this flag multiple times

pkg/app/master/command/build/prompt.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ var CommandFlagSuggestions = &command.FlagSuggestions{
5050
{Text: command.FullFlagName(command.FlagCROShmSize), Description: command.FlagCROShmSizeUsage},
5151
{Text: command.FullFlagName(command.FlagHTTPProbeOff), Description: command.FlagHTTPProbeOffUsage},
5252
{Text: command.FullFlagName(command.FlagHTTPProbe), Description: command.FlagHTTPProbeUsage},
53+
{Text: command.FullFlagName(command.FlagHTTPProbeClientTimeout), Description: command.FlagHTTPProbeClientTimeoutUsage},
54+
{Text: command.FullFlagName(command.FlagHTTPProbeClientTimeoutCrawl), Description: command.FlagHTTPProbeClientTimeoutCrawlUsage},
5355
{Text: command.FullFlagName(command.FlagHTTPProbeCmd), Description: command.FlagHTTPProbeCmdUsage},
5456
{Text: command.FullFlagName(command.FlagHTTPProbeCmdUpload), Description: command.FlagHTTPProbeCmdUploadUsage},
5557
{Text: command.FullFlagName(command.FlagHTTPProbeCmdFile), Description: command.FlagHTTPProbeCmdFileUsage},

pkg/app/master/command/cliflags.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ const (
112112

113113
FlagHTTPProbe = "http-probe"
114114
FlagHTTPProbeOff = "http-probe-off" //alternative way to disable http probing
115+
FlagHTTPProbeClientTimeout = "http-probe-client-timeout"
116+
FlagHTTPProbeClientTimeoutCrawl = "http-probe-client-timeout-crawl"
115117
FlagHTTPProbeCmd = "http-probe-cmd"
116118
FlagHTTPProbeCmdFile = "http-probe-cmd-file"
117119
FlagHTTPProbeCmdUpload = "http-probe-cmd-upload"
@@ -228,6 +230,8 @@ const (
228230

229231
FlagHTTPProbeUsage = "Enable or disable HTTP probing"
230232
FlagHTTPProbeOffUsage = "Alternative way to disable HTTP probing"
233+
FlagHTTPProbeClientTimeoutUsage = "Probe network client timeout in seconds (defaults to 30 seconds)"
234+
FlagHTTPProbeClientTimeoutCrawlUsage = "Crawl probe network client timeout in seconds (defaults to probe network client timeout if set or internal default if not, 10 seconds)"
231235
FlagHTTPProbeCmdUsage = "User defined HTTP probe(s) as [[[[\"crawl\":]PROTO:]METHOD:]PATH]"
232236
FlagHTTPProbeCmdUploadUsage = "User defined HTTP probe(s) to submit form data as [[[[[PROTO:]FORM_FILE_NAME:]FORM_FIELD_NAME:]FILE_OR_GENERATE_TYPE:]PATH]"
233237
FlagHTTPProbeCmdFileUsage = "File with user defined HTTP probes"
@@ -619,6 +623,18 @@ var CommonFlags = map[string]cli.Flag{
619623
Usage: FlagHTTPProbeOffUsage,
620624
EnvVars: []string{"DSLIM_HTTP_PROBE_OFF"},
621625
},
626+
FlagHTTPProbeClientTimeout: &cli.IntFlag{
627+
Name: FlagHTTPProbeClientTimeout,
628+
Value: 0, //0 means use defaults in the app code
629+
Usage: FlagHTTPProbeClientTimeoutUsage,
630+
EnvVars: []string{"DSLIM_HTTP_PROBE_CLIENT_TIMEOUT"},
631+
},
632+
FlagHTTPProbeClientTimeoutCrawl: &cli.IntFlag{
633+
Name: FlagHTTPProbeClientTimeoutCrawl,
634+
Value: 0, //0 means use defaults in the app code
635+
Usage: FlagHTTPProbeClientTimeoutCrawlUsage,
636+
EnvVars: []string{"DSLIM_HTTP_PROBE_CLIENT_TIMEOUT_CRAWL"},
637+
},
622638
FlagHTTPProbeCmd: &cli.StringSliceFlag{
623639
Name: FlagHTTPProbeCmd,
624640
Value: cli.NewStringSlice(),
@@ -985,6 +1001,8 @@ func HTTPProbeFlags() []cli.Flag {
9851001

9861002
func HTTPProbeFlagsBasic() []cli.Flag {
9871003
return []cli.Flag{
1004+
Cflag(FlagHTTPProbeClientTimeout),
1005+
Cflag(FlagHTTPProbeClientTimeoutCrawl),
9881006
Cflag(FlagHTTPProbeCmd),
9891007
Cflag(FlagHTTPProbeCmdUpload),
9901008
Cflag(FlagHTTPProbeCmdFile),

pkg/app/master/command/clifvgetter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func GetHTTPProbeOptions(xc *app.ExecutionContext, ctx *cli.Context, doProbe boo
5858
opts := config.HTTPProbeOptions{
5959
Full: ctx.Bool(FlagHTTPProbeFull),
6060

61+
ClientTimeout: ctx.Int(FlagHTTPProbeClientTimeout),
62+
CrawlClientTimeout: ctx.Int(FlagHTTPProbeClientTimeoutCrawl),
63+
6164
StartWait: ctx.Int(FlagHTTPProbeStartWait),
6265
RetryOff: ctx.Bool(FlagHTTPProbeRetryOff),
6366
RetryCount: ctx.Int(FlagHTTPProbeRetryCount),

pkg/app/master/command/profile/prompt.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var CommandFlagSuggestions = &command.FlagSuggestions{
2424
{Text: command.FullFlagName(command.FlagCROShmSize), Description: command.FlagCROShmSizeUsage},
2525
{Text: command.FullFlagName(command.FlagHTTPProbeOff), Description: command.FlagHTTPProbeOffUsage},
2626
{Text: command.FullFlagName(command.FlagHTTPProbe), Description: command.FlagHTTPProbeUsage},
27+
{Text: command.FullFlagName(command.FlagHTTPProbeClientTimeout), Description: command.FlagHTTPProbeClientTimeoutUsage},
28+
{Text: command.FullFlagName(command.FlagHTTPProbeClientTimeoutCrawl), Description: command.FlagHTTPProbeClientTimeoutCrawlUsage},
2729
{Text: command.FullFlagName(command.FlagHTTPProbeCmd), Description: command.FlagHTTPProbeCmdUsage},
2830
{Text: command.FullFlagName(command.FlagHTTPProbeCmdUpload), Description: command.FlagHTTPProbeCmdUploadUsage},
2931
{Text: command.FullFlagName(command.FlagHTTPProbeCmdFile), Description: command.FlagHTTPProbeCmdFileUsage},

pkg/app/master/config/http_probe.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ type HTTPProbeOptions struct {
8484
ExitOnFailure bool
8585
ExitOnFailureCount int
8686

87+
ClientTimeout int
88+
CrawlClientTimeout int
89+
WsClientTimeout int //todo
90+
8791
Cmds []HTTPProbeCmd
8892
Ports []uint16
8993

pkg/app/master/probe/http/crawler.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ func (p *CustomProbe) crawl(proto, domain, addr string) {
2424
var httpClient *http.Client
2525
if strings.HasPrefix(proto, config.ProtoHTTP2) {
2626
var err error
27-
if httpClient, err = getHTTPClient(proto); err != nil {
27+
if httpClient, err = getHTTPClient(proto, p.opts.ClientTimeout); err != nil {
2828
p.xc.Out.Error("HTTP probe - construct client error - %v", err.Error())
2929
return
3030
}
3131

32-
httpClient.Timeout = 10 * time.Second //matches the timeout used by Colly
32+
if p.opts.ClientTimeout == 0 {
33+
httpClient.Timeout = 10 * time.Second //matches the timeout used by Colly
34+
}
35+
3336
jar, _ := cookiejar.New(nil)
3437
httpClient.Jar = jar
3538
}
@@ -62,6 +65,14 @@ func (p *CustomProbe) crawl(proto, domain, addr string) {
6265
c.SetClient(httpClient)
6366
}
6467

68+
if p.opts.CrawlClientTimeout > 0 {
69+
c.SetRequestTimeout(time.Duration(p.opts.CrawlClientTimeout) * time.Second)
70+
log.Debugf("http.CustomProbe.crawl - set request timeout - p.opts.CrawlClientTimeout (%v)", p.opts.CrawlClientTimeout)
71+
} else if p.opts.ClientTimeout > 0 {
72+
c.SetRequestTimeout(time.Duration(p.opts.ClientTimeout) * time.Second)
73+
log.Debugf("http.CustomProbe.crawl - set request timeout - p.opts.ClientTimeout (%v)", p.opts.ClientTimeout)
74+
}
75+
6576
if p.opts.CrawlMaxDepth > 0 {
6677
c.MaxDepth = p.opts.CrawlMaxDepth
6778
}

pkg/app/master/probe/http/custom_probe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,10 +730,10 @@ func (p *CustomProbe) Start() {
730730
switch {
731731
case cmd.FastCGI != nil:
732732
log.Debug("HTTP probe - FastCGI embedded proxy configured")
733-
client = getFastCGIClient(cmd.FastCGI)
733+
client = getFastCGIClient(p.opts.ClientTimeout, cmd.FastCGI)
734734
default:
735735
var err error
736-
if client, err = getHTTPClient(proto); err != nil {
736+
if client, err = getHTTPClient(proto, p.opts.ClientTimeout); err != nil {
737737
p.xc.Out.Error("HTTP probe - construct client error - %v", err.Error())
738738
continue
739739
}

pkg/app/master/probe/http/httpclient.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ import (
1313
"github.com/mintoolkit/mint/pkg/app/master/probe/http/internal"
1414
)
1515

16-
func getHTTP1Client() *http.Client {
16+
const defaultClientTimeout = 30
17+
18+
func getHTTP1Client(clientTimeout int) *http.Client {
19+
if clientTimeout <= 0 {
20+
clientTimeout = defaultClientTimeout
21+
}
22+
1723
client := &http.Client{
18-
Timeout: time.Second * 30,
24+
Timeout: time.Second * time.Duration(clientTimeout),
1925
Transport: &http.Transport{
2026
MaxIdleConns: 10,
21-
IdleConnTimeout: 30 * time.Second,
27+
IdleConnTimeout: time.Duration(clientTimeout) * time.Second,
2228
TLSClientConfig: &tls.Config{
2329
InsecureSkipVerify: true,
2430
},
@@ -28,15 +34,19 @@ func getHTTP1Client() *http.Client {
2834
return client
2935
}
3036

31-
func getHTTP2Client(h2c bool) *http.Client {
37+
func getHTTP2Client(clientTimeout int, h2c bool) *http.Client {
38+
if clientTimeout <= 0 {
39+
clientTimeout = defaultClientTimeout
40+
}
41+
3242
transport := &http2.Transport{
3343
TLSClientConfig: &tls.Config{
3444
InsecureSkipVerify: true,
3545
},
3646
}
3747

3848
client := &http.Client{
39-
Timeout: time.Second * 30,
49+
Timeout: time.Second * time.Duration(clientTimeout),
4050
Transport: transport,
4151
}
4252

@@ -50,14 +60,14 @@ func getHTTP2Client(h2c bool) *http.Client {
5060
return client
5161
}
5262

53-
func getHTTPClient(proto string) (*http.Client, error) {
63+
func getHTTPClient(proto string, clientTimeout int) (*http.Client, error) {
5464
switch proto {
5565
case config.ProtoHTTP2:
56-
return getHTTP2Client(false), nil
66+
return getHTTP2Client(clientTimeout, false), nil
5767
case config.ProtoHTTP2C:
58-
return getHTTP2Client(true), nil
68+
return getHTTP2Client(clientTimeout, true), nil
5969
default:
60-
return getHTTP1Client(), nil
70+
return getHTTP1Client(clientTimeout), nil
6171
}
6272

6373
return nil, fmt.Errorf("unsupported HTTP-family protocol %s", proto)
@@ -84,9 +94,12 @@ func getHTTPScheme(proto string) string {
8494
return scheme
8595
}
8696

87-
func getFastCGIClient(cfg *config.FastCGIProbeWrapperConfig) *http.Client {
97+
func getFastCGIClient(clientTimeout int, cfg *config.FastCGIProbeWrapperConfig) *http.Client {
98+
if clientTimeout <= 0 {
99+
clientTimeout = defaultClientTimeout
100+
}
88101

89-
genericTimeout := time.Second * 30
102+
genericTimeout := time.Second * time.Duration(clientTimeout)
90103
var dialTimeout, readTimeout, writeTimeout time.Duration
91104
if dialTimeout = cfg.DialTimeout; dialTimeout == 0 {
92105
dialTimeout = genericTimeout

pkg/app/master/probe/http/swagger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func apiSpecPrefix(spec *openapi3.T) (string, error) {
205205
func (p *CustomProbe) loadAPISpecs(proto, targetHost, port string) {
206206

207207
baseAddr := getHTTPAddr(proto, targetHost, port)
208-
client, err := getHTTPClient(proto)
208+
client, err := getHTTPClient(proto, p.opts.ClientTimeout)
209209
if err != nil {
210210
p.xc.Out.Error("HTTP probe - construct client error - %v", err.Error())
211211
return
@@ -386,7 +386,7 @@ func (p *CustomProbe) probeAPISpecEndpoints(proto, targetHost, port, prefix stri
386386
})
387387
}
388388

389-
httpClient, err := getHTTPClient(proto)
389+
httpClient, err := getHTTPClient(proto, p.opts.ClientTimeout)
390390
if err != nil {
391391
p.xc.Out.Error("HTTP probe - construct client error - %v", err.Error())
392392
return

0 commit comments

Comments
 (0)