From ad02278a9524ad9cb2f09a7074557fe382fc1017 Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Wed, 22 May 2019 21:18:47 -0400 Subject: [PATCH 1/4] Set user agent in all Stackdriver requests --- plugins/outputs/stackdriver/stackdriver.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index 572cdb4c7cdc4..3045aa8c896d7 100644 --- a/plugins/outputs/stackdriver/stackdriver.go +++ b/plugins/outputs/stackdriver/stackdriver.go @@ -12,7 +12,9 @@ import ( monitoring "cloud.google.com/go/monitoring/apiv3" // Imports the Stackdriver Monitoring client package. googlepb "github.com/golang/protobuf/ptypes/timestamp" "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/internal" "github.com/influxdata/telegraf/plugins/outputs" + "google.golang.org/api/option" metricpb "google.golang.org/genproto/googleapis/api/metric" monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres" monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3" @@ -65,6 +67,7 @@ var sampleConfig = ` # namespace = "myapp" # location = "eu-north0" ` +var userAgent = fmt.Sprintf("telegraf %s", internal.Version()) // Connect initiates the primary connection to the GCP project. func (s *Stackdriver) Connect() error { @@ -88,7 +91,7 @@ func (s *Stackdriver) Connect() error { if s.client == nil { ctx := context.Background() - client, err := monitoring.NewMetricClient(ctx) + client, err := monitoring.NewMetricClient(ctx, option.WithUserAgent(userAgent)) if err != nil { return err } From c386f0f60461740ec41a8f7b52896707644b92bb Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Thu, 23 May 2019 13:40:58 -0400 Subject: [PATCH 2/4] Whitespace fix. --- plugins/outputs/stackdriver/stackdriver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index 3045aa8c896d7..9183c49806d1c 100644 --- a/plugins/outputs/stackdriver/stackdriver.go +++ b/plugins/outputs/stackdriver/stackdriver.go @@ -14,7 +14,7 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal" "github.com/influxdata/telegraf/plugins/outputs" - "google.golang.org/api/option" + "google.golang.org/api/option" metricpb "google.golang.org/genproto/googleapis/api/metric" monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres" monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3" From e33353a048cee5a07c98470e6d783d8dfe3df234 Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Fri, 24 May 2019 07:10:02 -0400 Subject: [PATCH 3/4] Use ProductToken for user-agent --- plugins/outputs/stackdriver/stackdriver.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index 9183c49806d1c..8bb016e76b44a 100644 --- a/plugins/outputs/stackdriver/stackdriver.go +++ b/plugins/outputs/stackdriver/stackdriver.go @@ -66,8 +66,6 @@ var sampleConfig = ` # node_id = "$HOSTNAME" # namespace = "myapp" # location = "eu-north0" -` -var userAgent = fmt.Sprintf("telegraf %s", internal.Version()) // Connect initiates the primary connection to the GCP project. func (s *Stackdriver) Connect() error { @@ -91,7 +89,7 @@ func (s *Stackdriver) Connect() error { if s.client == nil { ctx := context.Background() - client, err := monitoring.NewMetricClient(ctx, option.WithUserAgent(userAgent)) + client, err := monitoring.NewMetricClient(ctx, option.WithUserAgent(internal.ProductToken())) if err != nil { return err } From 6a555ebbc7fc035c65e2053a2166128dc4bbf5e3 Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Fri, 24 May 2019 07:11:45 -0400 Subject: [PATCH 4/4] Fixed typo. --- plugins/outputs/stackdriver/stackdriver.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index 8bb016e76b44a..fbb946fbd3641 100644 --- a/plugins/outputs/stackdriver/stackdriver.go +++ b/plugins/outputs/stackdriver/stackdriver.go @@ -66,6 +66,7 @@ var sampleConfig = ` # node_id = "$HOSTNAME" # namespace = "myapp" # location = "eu-north0" +` // Connect initiates the primary connection to the GCP project. func (s *Stackdriver) Connect() error {