From 3e94f014fe6051798b220174f8f56fae71d5ade4 Mon Sep 17 00:00:00 2001 From: Alexey Medvedchikov Date: Mon, 19 Nov 2018 17:57:14 +0100 Subject: [PATCH] Fix segmentation fault on missing credentials --- stackdriver_exporter.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/stackdriver_exporter.go b/stackdriver_exporter.go index 98286860..04ba0ded 100644 --- a/stackdriver_exporter.go +++ b/stackdriver_exporter.go @@ -76,6 +76,9 @@ func createMonitoringService() (*monitoring.Service, error) { ctx := context.Background() googleClient, err := google.DefaultClient(ctx, monitoring.MonitoringReadScope) + if err != nil { + return nil, fmt.Errorf("Error creating Google client: %v", err) + } googleClient.Timeout = *stackdriverHttpTimeout googleClient.Transport = rehttp.NewTransport( @@ -86,10 +89,6 @@ func createMonitoringService() (*monitoring.Service, error) { rehttp.ExpJitterDelay(*stackdriverBackoffJitterBase, *stackdriverMaxBackoffDuration), // Set timeout to <10s as that is prom default timeout ) - if err != nil { - return nil, fmt.Errorf("Error creating Google client: %v", err) - } - monitoringService, err := monitoring.New(googleClient) if err != nil { return nil, fmt.Errorf("Error creating Google Stackdriver Monitoring service: %v", err)