better handle error when sending usage metrics (#3333)

This commit is contained in:
blotus 2024-11-18 11:21:30 +01:00 committed by GitHub
parent 9067106ac0
commit c57dadce27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -368,10 +368,14 @@ func (a *apic) SendUsageMetrics(ctx context.Context) {
if err != nil {
log.Errorf("unable to send usage metrics: %s", err)
if resp == nil || resp.Response.StatusCode >= http.StatusBadRequest && resp.Response.StatusCode != http.StatusUnprocessableEntity {
if resp == nil || resp.Response == nil {
// Most likely a transient network error, it will be retried later
continue
}
if 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
}
}