Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --health-timeout and set a default 10 seconds #111

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type Backend struct {
up int32
healthCheckURL string
healthCheckDuration time.Duration
healthCheckTimeout time.Duration
Stats *BackendStats
}

Expand Down Expand Up @@ -323,7 +324,7 @@ func drainBody(resp *http.Response) {

func (b *Backend) doHealthCheck() error {
// Set up a maximum timeout time for the healtcheck operation
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), b.healthCheckTimeout)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, b.healthCheckURL, nil)
Expand Down Expand Up @@ -739,7 +740,7 @@ func IsLoopback(addr string) bool {
return net.ParseIP(host).IsLoopback()
}

func configureSite(ctx *cli.Context, siteNum int, siteStrs []string, healthCheckPath string, healthCheckPort int, healthCheckDuration time.Duration) *site {
func configureSite(ctx *cli.Context, siteNum int, siteStrs []string, healthCheckPath string, healthCheckPort int, healthCheckDuration, healthCheckTimeout time.Duration) *site {
var endpoints []string

if ellipses.HasEllipses(siteStrs...) {
Expand Down Expand Up @@ -815,7 +816,7 @@ func configureSite(ctx *cli.Context, siteNum int, siteStrs []string, healthCheck
}
backend := &Backend{siteNum, endpoint, proxy, &http.Client{
Transport: proxy.Transport,
}, 0, healthCheckURL, healthCheckDuration, &stats}
}, 0, healthCheckURL, healthCheckDuration, healthCheckTimeout, &stats}
go backend.healthCheck()
proxy.ErrorHandler = backend.ErrorHandler
backends = append(backends, backend)
Expand All @@ -840,6 +841,7 @@ func sidekickMain(ctx *cli.Context) {
healthReadCheckPath := ctx.GlobalString("read-health-path")
healthCheckPort := ctx.GlobalInt("health-port")
healthCheckDuration := ctx.GlobalDuration("health-duration")
healthCheckTimeout := ctx.GlobalDuration("health-timeout")
addr := ctx.GlobalString("address")

// Validate port range which should be in [0, 65535]
Expand Down Expand Up @@ -886,7 +888,7 @@ func sidekickMain(ctx *cli.Context) {
healthCheckPath = healthReadCheckPath
}

site := configureSite(ctx, i+1, strings.Split(siteStrs, ","), healthCheckPath, healthCheckPort, healthCheckDuration)
site := configureSite(ctx, i+1, strings.Split(siteStrs, ","), healthCheckPath, healthCheckPort, healthCheckDuration, healthCheckTimeout)
sites = append(sites, site)
}

Expand Down Expand Up @@ -978,6 +980,11 @@ func main() {
Usage: "health check duration in seconds",
Value: 5 * time.Second,
},
cli.DurationFlag{
Name: "health-timeout",
Usage: "health check timeout in seconds",
Value: 10 * time.Second,
},
cli.BoolFlag{
Name: "insecure, i",
Usage: "disable TLS certificate verification",
Expand Down
Loading