From c3f00eb403436170d54e54dcf610c2ceb5d6a3f0 Mon Sep 17 00:00:00 2001 From: Yuri Tseretyan Date: Wed, 19 Mar 2025 10:14:05 -0400 Subject: [PATCH] Alerting: log body of unexpected response from Mimir (#102382) log body of unexpected response Signed-off-by: Yuri Tseretyan --- pkg/services/ngalert/remote/client/mimir.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/services/ngalert/remote/client/mimir.go b/pkg/services/ngalert/remote/client/mimir.go index 4482ee0495a..0ae532b01ad 100644 --- a/pkg/services/ngalert/remote/client/mimir.go +++ b/pkg/services/ngalert/remote/client/mimir.go @@ -13,6 +13,7 @@ import ( "strings" alertingNotify "github.com/grafana/alerting/notify" + "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/tracing" apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" @@ -139,7 +140,12 @@ func (mc *Mimir) do(ctx context.Context, p, method string, payload io.Reader, ou ct := resp.Header.Get("Content-Type") if !strings.HasPrefix(ct, "application/json") { msg := "Response content-type is not application/json" - mc.logger.Error(msg, "content-type", "url", r.URL.String(), "method", r.Method, ct, "status", resp.StatusCode) + body, err := io.ReadAll(resp.Body) + bodyStr := string(body) + if err != nil { + bodyStr = fmt.Sprintf("fail_to_read: %s", err) + } + mc.logger.Error(msg, "content-type", "url", r.URL.String(), "method", r.Method, ct, "status", resp.StatusCode, "body", bodyStr) return nil, fmt.Errorf("%s: %s", msg, ct) }