From 1665b0116817b84eb52d9d85e2dcf4d2af7bd7af Mon Sep 17 00:00:00 2001 From: Tobias Guggenmos Date: Thu, 12 Dec 2024 16:25:21 +0100 Subject: [PATCH] Log remaining errors --- prober/grpc.go | 4 ++-- prober/http.go | 13 ++++++++----- prober/prober.go | 2 +- prober/tcp.go | 6 ++++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/prober/grpc.go b/prober/grpc.go index 5a262682..da81bf89 100644 --- a/prober/grpc.go +++ b/prober/grpc.go @@ -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() diff --git a/prober/http.go b/prober/http.go index 911d3ed7..2bd5ff4d 100644 --- a/prober/http.go +++ b/prober/http.go @@ -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. } @@ -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() @@ -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 @@ -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 diff --git a/prober/prober.go b/prober/prober.go index 083e1e0d..5e8abf97 100644 --- a/prober/prober.go +++ b/prober/prober.go @@ -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"}` diff --git a/prober/tcp.go b/prober/tcp.go index e812bcc2..72bb1784 100644 --- a/prober/tcp.go +++ b/prober/tcp.go @@ -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))