From d00a6a687345f78add9c05e06bf7b75cbfb28007 Mon Sep 17 00:00:00 2001 From: Laurence Jones Date: Fri, 25 Oct 2024 10:31:08 +0100 Subject: [PATCH] enhance: Check if resp is nil in capi metrics and continue (#3299) --- pkg/apiserver/apic_metrics.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/apiserver/apic_metrics.go b/pkg/apiserver/apic_metrics.go index 3d9e7b28a79..aa8db3f1c85 100644 --- a/pkg/apiserver/apic_metrics.go +++ b/pkg/apiserver/apic_metrics.go @@ -368,9 +368,10 @@ func (a *apic) SendUsageMetrics(ctx context.Context) { if err != nil { log.Errorf("unable to send usage metrics: %s", err) - if resp.Response.StatusCode >= http.StatusBadRequest && resp.Response.StatusCode != http.StatusUnprocessableEntity { + if resp == nil || resp.Response.StatusCode >= http.StatusBadRequest && resp.Response.StatusCode != http.StatusUnprocessableEntity { // In case of 422, mark the metrics as sent anyway, the API did not like what we sent, // and it's unlikely we'll be able to fix it + // also if resp is nil, we should'nt mark the metrics as sent could be network issue continue } }