fix(outputs.stackdriver): Allow for custom metric type prefix (#13168)

This commit is contained in:
Joshua Powers 2023-05-04 11:56:29 -06:00 committed by GitHub
parent cf7ec5072d
commit d12bcec8c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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,