Skip to content

Commit

Permalink
Log remaining errors
Browse files Browse the repository at this point in the history
  • Loading branch information
slrtbtfs committed Dec 12, 2024
1 parent 2705d34 commit 1665b01
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions prober/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ func ProbeGRPC(ctx context.Context, target string, module config.Module, registr

if err != nil {
logger.Error(err.Error())
return ProbeFailure("can't connect grpc server")
return ProbeFailure("Can't connect to the grpc server")
} else if !ok {
return ProbeFailure("can't connect grpc server")
return ProbeFailure("Can't connect to the grpc server")
} else {
logger.Debug("connect the grpc server successfully")
result = ProbeSuccess()
Expand Down
13 changes: 8 additions & 5 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
if resp == nil {
resp = &http.Response{}
if err != nil {
result = ProbeFailure("Error for HTTP request", "err", err.Error())
logger.Error("Error for HTTP request", "err", err.Error())
result = ProbeFailure("HTTP request failed")
// no return here, since there are cases where an error here
// might be acceptable after all.
}
Expand All @@ -481,8 +482,8 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
}
}
if !result.success {
result = ProbeFailure("Invalid HTTP response status code", "status_code", strconv.Itoa(resp.StatusCode),
"valid_status_codes", fmt.Sprintf("%v", httpConfig.ValidStatusCodes))
logger.Info("Valid status codes", "codes", httpConfig.ValidStatusCodes)
result = ProbeFailure("Invalid HTTP response status code", "status_code", strconv.Itoa(resp.StatusCode))
}
} else if 200 <= resp.StatusCode && resp.StatusCode < 300 {
result = ProbeSuccess()
Expand All @@ -505,7 +506,8 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
if httpConfig.Compression != "" {
dec, err := getDecompressionReader(httpConfig.Compression, resp.Body)
if err != nil {
result = ProbeFailure("Failed to get decompressor for HTTP response body", "err", err.Error())
logger.Error(err.Error())
result = ProbeFailure("Failed to get decompressor for HTTP response body")
} else if dec != nil {
// Since we are replacing the original resp.Body with the decoder, we need to make sure
// we close the original body. We cannot close it right away because the decompressor
Expand Down Expand Up @@ -545,7 +547,8 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
if !requestErrored {
_, err = io.Copy(io.Discard, byteCounter)
if err != nil {
result = ProbeFailure("Failed to read HTTP response body", "err", err.Error())
logger.Error(err.Error())
result = ProbeFailure("Failed to read HTTP response body")
}

respBodyBytes = byteCounter.n
Expand Down
2 changes: 1 addition & 1 deletion prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ProbeResult struct {
// Expects an odd number of string arguments.
//
// Example:
// Calling probeFailure("problem", "label1", "value1", "label2", "value2")
// Calling ProbeFailure("problem", "label1", "value1", "label2", "value2")
// will result in the metric:
//
// `probe_failure_info{reason="problem", label1="value1", label2="value2"}`
Expand Down
6 changes: 4 additions & 2 deletions prober/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
}
}
if scanner.Err() != nil {
return ProbeFailure("Error reading from connection", "err", scanner.Err().Error())
logger.Error("Scanner Error", "error", scanner.Err())
return ProbeFailure("Error reading from connection")
}
if match == nil {
probeFailedDueToRegex.Set(1)
return ProbeFailure("Regexp did not match", "regexp", qr.Expect.Regexp.String(), "line", scanner.Text())
logger.Error("Regexp did not match", "regexp", qr.Expect.Regexp.String(), "line", scanner.Text())
return ProbeFailure("Regexp did not match")
}
probeFailedDueToRegex.Set(0)
send = string(qr.Expect.Regexp.Expand(nil, []byte(send), scanner.Bytes(), match))
Expand Down

0 comments on commit 1665b01

Please sign in to comment.