Alerting: log body of unexpected response from Mimir (#102382)

log body of unexpected response

Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
pull/102463/head
Yuri Tseretyan 3 months ago committed by GitHub
parent 42472dbe7e
commit c3f00eb403
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      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)
}

Loading…
Cancel
Save