Skip to content

Commit

Permalink
Merge branch 'main' into add/icmp-prober
Browse files Browse the repository at this point in the history
  • Loading branch information
m-yosefpor committed Jan 15, 2024
2 parents e4c62bf + 4dbb2a8 commit ec90be1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
13 changes: 8 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ updates:
directory: "/"
schedule:
interval: monthly
assignees:
- m-yosefpor
labels:
- dependencies

groups:
dev-dependencies:
patterns:
- "*"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "monthly"
assignees:
- m-yosefpor
labels:
- dependencies
groups:
dev-dependencies:
patterns:
- "*"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#build stage
FROM golang:1.17 AS builder
FROM golang:1.21 AS builder
RUN mkdir -p /go/src/app
WORKDIR /go/src/app

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type HTTP struct {
Timeout time.Duration `mapstructure:"timeout"`
TLSSkipVerify bool `mapstructure:"tls_skip_verify"`
DisableKeepAlives bool `mapstructure:"disable_keepalives"`
H2cEnabled bool `mapstructure:"h2c_enabled"`
Host string `mapstructure:"host"`
}

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func main() {
ctx, cancel := context.WithCancel(context.Background())

for _, ht := range config.Get().Targets.HTTP {
httpProber := prober.NewHttp(ht.Name, ht.URL, ht.RPS, ht.Timeout, ht.TLSSkipVerify, ht.DisableKeepAlives, ht.Host)
httpProber := prober.NewHttp(ht.Name, ht.URL, ht.RPS, ht.Timeout, ht.TLSSkipVerify, ht.DisableKeepAlives, ht.H2cEnabled, ht.Host)

klog.Infof("Probing HTTP target '%s' with url '%s', RPS: %.2f, timeout: %s, TLS_skip_verify: %v, disableKeepAlives: %v ...\n",
ht.Name, ht.URL, ht.RPS, ht.Timeout, ht.TLSSkipVerify, ht.DisableKeepAlives)
klog.Infof("Probing HTTP target '%s' with url '%s', RPS: %.2f, timeout: %s, TLS_skip_verify: %v, disableKeepAlives: %v, h2cEnabled: %v ...\n",
ht.Name, ht.URL, ht.RPS, ht.Timeout, ht.TLSSkipVerify, ht.DisableKeepAlives, ht.H2cEnabled)
go httpProber.Start(ctx)
}

Expand Down
29 changes: 23 additions & 6 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"
"golang.org/x/net/http2"
klog "k8s.io/klog/v2"
)

Expand Down Expand Up @@ -48,16 +49,32 @@ func init() {

}

func NewHttp(name string, url string, rps float64, timeout time.Duration, tlsSkipVerify, disableKeepAlives bool, host string) HTTP {
func NewHttp(name string, url string, rps float64, timeout time.Duration, tlsSkipVerify, disableKeepAlives, h2cEnabled bool, host string) HTTP {
client := &http.Client{
Timeout: timeout,
}
customTransport := http.DefaultTransport.(*http.Transport).Clone()
customTransport.DisableKeepAlives = disableKeepAlives
if tlsSkipVerify {
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}

if h2cEnabled {
customTransport := &http2.Transport{
AllowHTTP: true,
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
return net.Dial(network, addr)
},
}
if tlsSkipVerify {
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
client.Transport = customTransport
} else {
customTransport := http.DefaultTransport.(*http.Transport).Clone()

// disableKeepalive is only for http1.1
customTransport.DisableKeepAlives = disableKeepAlives
if tlsSkipVerify {
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
client.Transport = customTransport
}
client.Transport = customTransport

return HTTP{
Name: name,
Expand Down

0 comments on commit ec90be1

Please sign in to comment.