Skip to content

Commit

Permalink
disruption backend: extend error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
vrutkovs committed Nov 13, 2024
1 parent 5b2dc8d commit a43e11d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/disruption/backend/sampler/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Requestor interface {
// request sent to the server.
type ResponseChecker interface {
// CheckError checks the the given error for any known types
CheckError(error) error
CheckError(error, backend.RequestResponse) error

// CheckResponse checks the given HTTP Response object and
// optionally the response body that has been successfully read.
Expand Down
2 changes: 1 addition & 1 deletion pkg/disruption/backend/sampler/producer_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (pc *producerConsumer) Produce(stop context.Context, sampleID uint64) (inte

resp, err := pc.client.Do(req)
if err != nil {
return rr, pc.checker.CheckError(err)
return rr, pc.checker.CheckError(err, rr)
}
rr.Response = resp
err = pc.checker.CheckResponse(rr)
Expand Down
23 changes: 16 additions & 7 deletions pkg/disruption/backend/sampler/response_checker.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package sampler

import (
"errors"
"fmt"
"syscall"

"github.com/openshift/origin/pkg/disruption/backend"
)
Expand Down Expand Up @@ -51,12 +53,19 @@ func (c checker) CheckResponse(rr backend.RequestResponse) error {
return nil
}

func (c checker) CheckError(err error) error {
// TODO: check for obvious error type and determine the category, to
// begin with, we could resolve the following errors:
// a) "no route to host" or "io timeout": these can be
// safely considered network error
// b) "connection refused": needs triage to begin with
// c) "connection reset": needs triage to begin with
func (c checker) CheckError(err error, rr backend.RequestResponse) error {
if errors.Is(err, syscall.EHOSTUNREACH) || errors.Is(err, syscall.ETIMEDOUT) {
return &KnownError{
category: "NetworkError",
err: fmt.Errorf("error while reading response body, error: %w, request: %#v", err, rr.Request),
}
}
if errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.ECONNABORTED) || errors.Is(err, syscall.ECONNREFUSED) {
return &KnownError{
category: "NeedsTriage",
err: fmt.Errorf("error while reading response body, error: %w: request: %#v", err, rr.Request),
}
}

return err
}

0 comments on commit a43e11d

Please sign in to comment.