Skip to content

Commit

Permalink
better handle error when sending usage metrics (#3333)
Browse files Browse the repository at this point in the history
  • Loading branch information
blotus authored Nov 18, 2024
1 parent 9067106 commit c57dadc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/apiserver/apic_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit c57dadc

Please sign in to comment.