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

fix: using extra valid status codes when response status code greater than 400 #3986

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions staging/src/github.com/labring/lvscare/care/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (p *httpProber) RegisterFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.Method, "health-req-method", "GET", "http request method")
fs.StringVar(&p.Body, "health-req-body", "", "body to send for health checker")
fs.StringToStringVar(&p.Headers, "health-req-headers", map[string]string{}, "http request headers")
fs.IntSliceVar(&p.ValidStatusCodes, "health-status", []int{}, "valid status codes")
fs.IntSliceVar(&p.ValidStatusCodes, "health-status", []int{}, "extra valid status codes greater than 400")
fs.BoolVar(&p.InsecureSkipVerify, "health-insecure-skip-verify", true, "skip verify insecure request")
fs.DurationVar(&p.timeout, "health-timeout", 10*time.Second, "http probe timeout")
}
Expand Down Expand Up @@ -114,13 +114,10 @@ func (p *httpProber) Probe(host, port string) error {
defer func() {
_, _ = io.Copy(io.Discard, resp.Body)
}()
if p.validStatus.Len() > 0 {
if p.validStatus.Has(resp.StatusCode) {
if resp.StatusCode/100 >= 4 {
if p.validStatus.Len() > 0 && p.validStatus.Has(resp.StatusCode) {
return nil
}
return fmt.Errorf("invalid status code %d", resp.StatusCode)
}
if resp.StatusCode/100 >= 4 {
return fmt.Errorf("unexpected status code %d", resp.StatusCode)
}
return nil
Expand Down