Skip to content

Commit 91b9dcc

Browse files
author
Olve S. Hansen
committed
Added kingpin vars for exponential backoff config. (Default off)
Defaults are 0 retries (i.e. off) 1 second jitter base 5s max time between retries 10s total http timeout. Same as Prometheus default scrape timeout.
1 parent 221eb3e commit 91b9dcc

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

stackdriver_exporter.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"golang.org/x/oauth2/google"
1616
"google.golang.org/api/monitoring/v3"
1717
"gopkg.in/alecthomas/kingpin.v2"
18-
"time"
1918
)
2019

2120
var (
@@ -46,6 +45,26 @@ var (
4645
collectorFillMissingLabels = kingpin.Flag(
4746
"collector.fill-missing-labels", "Fill missing metrics labels with empty string to avoid label dimensions inconsistent failure ($STACKDRIVER_EXPORTER_COLLECTOR_FILL_MISSING_LABELS).",
4847
).Envar("STACKDRIVER_EXPORTER_COLLECTOR_FILL_MISSING_LABELS").Default("true").Bool()
48+
49+
stackdriverMaxRetries = kingpin.Flag(
50+
"stackdriver.max-retries", "Max number of retries that should be attempted on 503 errors from stackdriver. ($STACKDRIVER_EXPORTER_MAX_RETRIES)",
51+
).Envar("STACKDRIVER_EXPORTER_MAX_RETRIES").Default("0").Int()
52+
53+
stackdriverHttpTimeout = kingpin.Flag(
54+
"stackdriver.http-timeout", "How long should stackdriver_exporter wait for a result from the Stackdriver API ($STACKDRIVER_EXPORTER_HTTP_TIMEOUT)",
55+
).Envar("STACKDRIVER_EXPORTER_HTTP_TIMEOUT").Default("10s").Duration()
56+
57+
stackdriverMaxBackoffDuration = kingpin.Flag(
58+
"stackdriver.http-timeout", "Max time between each request in an exp backoff scenario ($STACKDRIVER_EXPORTER_MAX_BACKOFF_DURATION)",
59+
).Envar("STACKDRIVER_EXPORTER_MAX_BACKOFF_DURATION").Default("5s").Duration()
60+
61+
stackdriverBackoffJitterBase = kingpin.Flag(
62+
"stackdriver.http-timeout", "The amount of jitter to introduce in a exp backoff scenario ($STACKDRIVER_EXPORTER_BACKODFF_JITTER_BASE)",
63+
).Envar("STACKDRIVER_EXPORTER_BACKODFF_JITTER_BASE").Default("1s").Duration()
64+
65+
stackdriverRetryStatuses = kingpin.Flag(
66+
"stackdriver.retry-statuses", "The HTTP statuses that should trigger a retry (comma separated) ($STACKDRIVER_EXPORTER_RETRY_STATUSES)",
67+
).Envar("STACKDRIVER_EXPORTER_RETRY_STATUSES").Default("503").Ints()
4968
)
5069

5170
func init() {
@@ -56,13 +75,14 @@ func createMonitoringService() (*monitoring.Service, error) {
5675
ctx := context.Background()
5776

5877
googleClient, err := google.DefaultClient(ctx, monitoring.MonitoringReadScope)
59-
googleClient.Timeout = time.Second * 10
78+
79+
googleClient.Timeout = *stackdriverHttpTimeout
6080
googleClient.Transport = rehttp.NewTransport(
6181
googleClient.Transport, // need to wrap DefaultClient transport
6282
rehttp.RetryAll(
63-
rehttp.RetryMaxRetries(3),
64-
rehttp.RetryStatuses(503)), // Cloud support suggests retrying on 503 errors
65-
rehttp.ExpJitterDelay(time.Second, 9*time.Second), // Set timeout to <10s as that is prom default timeout
83+
rehttp.RetryMaxRetries(*stackdriverMaxRetries),
84+
rehttp.RetryStatuses(*stackdriverRetryStatuses...)), // Cloud support suggests retrying on 503 errors
85+
rehttp.ExpJitterDelay(*stackdriverBackoffJitterBase, *stackdriverMaxBackoffDuration), // Set timeout to <10s as that is prom default timeout
6686
)
6787

6888
if err != nil {

0 commit comments

Comments
 (0)