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 retry checker for DNS failure from Ingress #2351

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions test/spoof/error_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package spoof
import (
"errors"
"net"
"net/http"
"strings"
)

Expand Down Expand Up @@ -62,3 +63,8 @@ func isConnectionReset(err error) bool {
func isNoRouteToHostError(err error) bool {
return err != nil && strings.Contains(err.Error(), "connect: no route to host")
}

func isResponseDNSError(resp *Response) bool {
// no such host with 502 is sent back from istio-ingressgateway when it fails to resolve domain.
return resp.StatusCode == http.StatusBadGateway && strings.Contains(string(resp.Body), "no such host")
}
10 changes: 9 additions & 1 deletion test/spoof/spoof.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (sc *SpoofingClient) Do(req *http.Request, errorRetryCheckers ...interface{
// If no retry checkers are specified `DefaultErrorRetryChecker` will be used.
func (sc *SpoofingClient) Poll(req *http.Request, inState ResponseChecker, checkers ...interface{}) (*Response, error) {
if len(checkers) == 0 {
checkers = []interface{}{ErrorRetryChecker(DefaultErrorRetryChecker)}
checkers = []interface{}{ErrorRetryChecker(DefaultErrorRetryChecker), ResponseRetryChecker(DefaultResponseRetryChecker)}
}

var resp *Response
Expand Down Expand Up @@ -255,6 +255,14 @@ func DefaultErrorRetryChecker(err error) (bool, error) {
return false, err
}

// DefaultResponseRetryChecker implements the defaults for retrying on response.
func DefaultResponseRetryChecker(resp *Response) (bool, error) {
if isResponseDNSError(resp) {
return true, fmt.Errorf("retrying for DNS related failure response: %v", resp)
}
return false, nil
}

// logZipkinTrace provides support to log Zipkin Trace for param: spoofResponse
// We only log Zipkin trace for HTTP server errors i.e for HTTP status codes between 500 to 600
func (sc *SpoofingClient) logZipkinTrace(spoofResp *Response) {
Expand Down