Skip to content

Commit b1bdf53

Browse files
Retry by default on 401s (#1130)
Seems like these come up a lot during testing It seems like Grafana may fail to authenticate users when lots of requests are being processed
1 parent b19e8db commit b1bdf53

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

internal/provider/provider.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,13 @@ func createGrafanaClient(d *schema.ResourceData) (string, *gapi.Config, *gapi.Cl
397397
}
398398

399399
cfg := gapi.Config{
400-
Client: cli,
401-
NumRetries: d.Get("retries").(int),
402-
RetryTimeout: time.Second * time.Duration(d.Get("retry_wait").(int)),
403-
BasicAuth: userInfo,
404-
OrgID: orgID,
405-
APIKey: apiKey,
400+
Client: cli,
401+
NumRetries: d.Get("retries").(int),
402+
RetryTimeout: time.Second * time.Duration(d.Get("retry_wait").(int)),
403+
RetryStatusCodes: []string{"429", "5xx", "401"}, // In high load scenarios, Grafana sometimes returns 401s (unable to authenticate the user?)
404+
BasicAuth: userInfo,
405+
OrgID: orgID,
406+
APIKey: apiKey,
406407
}
407408

408409
if v, ok := d.GetOk("retry_status_codes"); ok {
@@ -441,15 +442,16 @@ func createGrafanaOAPIClient(apiURL string, d *schema.ResourceData) (*goapi.Graf
441442
}
442443

443444
cfg := goapi.TransportConfig{
444-
Host: u.Host,
445-
BasePath: apiPath,
446-
Schemes: []string{u.Scheme},
447-
NumRetries: d.Get("retries").(int),
448-
RetryTimeout: time.Second * time.Duration(d.Get("retry_wait").(int)),
449-
TLSConfig: tlsClientConfig,
450-
BasicAuth: userInfo,
451-
OrgID: orgID,
452-
APIKey: APIKey,
445+
Host: u.Host,
446+
BasePath: apiPath,
447+
Schemes: []string{u.Scheme},
448+
NumRetries: d.Get("retries").(int),
449+
RetryTimeout: time.Second * time.Duration(d.Get("retry_wait").(int)),
450+
RetryStatusCodes: []string{"429", "5xx", "401"}, // In high load scenarios, Grafana sometimes returns 401s (unable to authenticate the user?)
451+
TLSConfig: tlsClientConfig,
452+
BasicAuth: userInfo,
453+
OrgID: orgID,
454+
APIKey: APIKey,
453455
}
454456

455457
if v, ok := d.GetOk("retry_status_codes"); ok {

0 commit comments

Comments
 (0)