From d12bcec8c4ed72961babda09a98b7bb18b43d758 Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Thu, 4 May 2023 11:56:29 -0600 Subject: [PATCH] fix(outputs.stackdriver): Allow for custom metric type prefix (#13168) --- plugins/outputs/stackdriver/README.md | 4 ++++ plugins/outputs/stackdriver/sample.conf | 4 ++++ plugins/outputs/stackdriver/stackdriver.go | 21 +++++++++++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/plugins/outputs/stackdriver/README.md b/plugins/outputs/stackdriver/README.md index 0ce549b21..6699423df 100644 --- a/plugins/outputs/stackdriver/README.md +++ b/plugins/outputs/stackdriver/README.md @@ -38,6 +38,10 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. ## The namespace for the metric descriptor namespace = "telegraf" + ## Metric Type Prefix + ## The DNS name used with the metric type as a prefix. + # metric_type_prefix = "custom.googleapis.com" + ## Custom resource type # resource_type = "generic_node" diff --git a/plugins/outputs/stackdriver/sample.conf b/plugins/outputs/stackdriver/sample.conf index e29b3632a..e0eac793b 100644 --- a/plugins/outputs/stackdriver/sample.conf +++ b/plugins/outputs/stackdriver/sample.conf @@ -6,6 +6,10 @@ ## The namespace for the metric descriptor namespace = "telegraf" + ## Metric Type Prefix + ## The DNS name used with the metric type as a prefix. + # metric_type_prefix = "custom.googleapis.com" + ## Custom resource type # resource_type = "generic_node" diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index 80d821c87..c42e115fd 100644 --- a/plugins/outputs/stackdriver/stackdriver.go +++ b/plugins/outputs/stackdriver/stackdriver.go @@ -27,11 +27,12 @@ var sampleConfig string // Stackdriver is the Google Stackdriver config info. type Stackdriver struct { - Project string `toml:"project"` - Namespace string `toml:"namespace"` - ResourceType string `toml:"resource_type"` - ResourceLabels map[string]string `toml:"resource_labels"` - Log telegraf.Logger `toml:"-"` + Project string `toml:"project"` + Namespace string `toml:"namespace"` + ResourceType string `toml:"resource_type"` + ResourceLabels map[string]string `toml:"resource_labels"` + MetricTypePrefix string `toml:"metric_type_prefix"` + Log telegraf.Logger `toml:"-"` client *monitoring.MetricClient counterCache *counterCache @@ -56,6 +57,14 @@ const ( errStringPointsTooFrequent = "one or more points were written more frequently than the maximum sampling period configured for the metric" ) +func (s *Stackdriver) Init() error { + if s.MetricTypePrefix == "" { + s.MetricTypePrefix = "custom.googleapis.com" + } + + return nil +} + func (*Stackdriver) SampleConfig() string { return sampleConfig } @@ -199,7 +208,7 @@ func (s *Stackdriver) sendBatch(batch []telegraf.Metric) error { // Prepare time series. timeSeries := &monitoringpb.TimeSeries{ Metric: &metricpb.Metric{ - Type: path.Join("custom.googleapis.com", s.Namespace, m.Name(), f.Key), + Type: path.Join(s.MetricTypePrefix, s.Namespace, m.Name(), f.Key), Labels: s.getStackdriverLabels(m.TagList()), }, MetricKind: metricKind,