From f2b97f537d3c98784107681601a636e58a4d0030 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Tue, 5 Dec 2023 10:01:56 -0700 Subject: [PATCH] chore: improve error logs for prober (#886) * improve error logs for prober Signed-off-by: Hector Fernandez * address reviewer comments Signed-off-by: Hector Fernandez --------- Signed-off-by: Hector Fernandez --- cmd/prober/write.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/prober/write.go b/cmd/prober/write.go index c17004340..77884147a 100644 --- a/cmd/prober/write.go +++ b/cmd/prober/write.go @@ -163,11 +163,16 @@ func rekorWriteEndpoint(ctx context.Context, cert *x509.Certificate, priv *ecdsa defer resp.Body.Close() exportDataToPrometheus(resp, rekorURL, endpoint, POST, latency) + if resp.StatusCode != http.StatusCreated { + body, _ := io.ReadAll(resp.Body) + return fmt.Errorf("invalid status code '%s' when checking an entry in rekor with body '%s'", resp.Status, string(body)) + } // If entry was added successfully, we should verify it var logEntry models.LogEntry err = json.NewDecoder(resp.Body).Decode(&logEntry) if err != nil { - return fmt.Errorf("unmarshal: %w", err) + body, _ := io.ReadAll(resp.Body) + return fmt.Errorf("error decoding the log entry with body '%s' and error: %w", string(body), err) } var logEntryAnon models.LogEntryAnon for _, e := range logEntry {