Skip to content

Commit 2f02a45

Browse files
author
Olve S. Hansen
committed
Added exponential backoff and retries on stackdriver api
As per discussion with Google Cloud Support this is their preferred workaround on 503 errors from their APIs. Also using a timeout of 10 seconds for the client to make sure we do not have hanging requests.
1 parent 49c2fbd commit 2f02a45

File tree

2 files changed

+93
-14
lines changed

2 files changed

+93
-14
lines changed

Gopkg.lock

Lines changed: 81 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stackdriver_exporter.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import (
66
"os"
77
"strings"
88

9+
"github.com/PuerkitoBio/rehttp"
10+
"github.com/frodenas/stackdriver_exporter/collectors"
911
"github.com/prometheus/client_golang/prometheus"
1012
"github.com/prometheus/common/log"
1113
"github.com/prometheus/common/version"
1214
"golang.org/x/net/context"
1315
"golang.org/x/oauth2/google"
1416
"google.golang.org/api/monitoring/v3"
1517
"gopkg.in/alecthomas/kingpin.v2"
16-
17-
"github.com/frodenas/stackdriver_exporter/collectors"
18+
"time"
1819
)
1920

2021
var (
@@ -55,6 +56,15 @@ func createMonitoringService() (*monitoring.Service, error) {
5556
ctx := context.Background()
5657

5758
googleClient, err := google.DefaultClient(ctx, monitoring.MonitoringReadScope)
59+
googleClient.Timeout = time.Second * 10
60+
googleClient.Transport = rehttp.NewTransport(
61+
googleClient.Transport, // need to wrap DefaultClient transport
62+
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
66+
)
67+
5868
if err != nil {
5969
return nil, fmt.Errorf("Error creating Google client: %v", err)
6070
}

0 commit comments

Comments
 (0)