mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 12:25:53 +02:00
better handle error when sending usage metrics (#3333)
This commit is contained in:
parent
9067106ac0
commit
c57dadce27
1 changed files with 6 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue