fix(outputs.stackdriver): Add tag as resource label option (#13575)
This commit is contained in:
parent
14f52eae01
commit
8cde34bfeb
|
|
@ -60,6 +60,12 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
## * double: preferred datatype to allow queries by PromQL.
|
## * double: preferred datatype to allow queries by PromQL.
|
||||||
# metric_data_type = "source"
|
# metric_data_type = "source"
|
||||||
|
|
||||||
|
## Tags as resource labels
|
||||||
|
## Tags defined in this option, when they exist, are added as a resource
|
||||||
|
## label and not included as a metric label. The values from tags override
|
||||||
|
## the values defined under the resource_labels config options.
|
||||||
|
# tags_as_resource_label = []
|
||||||
|
|
||||||
## Custom resource type
|
## Custom resource type
|
||||||
# resource_type = "generic_node"
|
# resource_type = "generic_node"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,12 @@
|
||||||
## * double: preferred datatype to allow queries by PromQL.
|
## * double: preferred datatype to allow queries by PromQL.
|
||||||
# metric_data_type = "source"
|
# metric_data_type = "source"
|
||||||
|
|
||||||
|
## Tags as resource labels
|
||||||
|
## Tags defined in this option, when they exist, are added as a resource
|
||||||
|
## label and not included as a metric label. The values from tags override
|
||||||
|
## the values defined under the resource_labels config options.
|
||||||
|
# tags_as_resource_label = []
|
||||||
|
|
||||||
## Custom resource type
|
## Custom resource type
|
||||||
# resource_type = "generic_node"
|
# resource_type = "generic_node"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,15 @@ var sampleConfig string
|
||||||
|
|
||||||
// Stackdriver is the Google Stackdriver config info.
|
// Stackdriver is the Google Stackdriver config info.
|
||||||
type Stackdriver struct {
|
type Stackdriver struct {
|
||||||
Project string `toml:"project"`
|
Project string `toml:"project"`
|
||||||
Namespace string `toml:"namespace"`
|
Namespace string `toml:"namespace"`
|
||||||
ResourceType string `toml:"resource_type"`
|
ResourceType string `toml:"resource_type"`
|
||||||
ResourceLabels map[string]string `toml:"resource_labels"`
|
ResourceLabels map[string]string `toml:"resource_labels"`
|
||||||
MetricTypePrefix string `toml:"metric_type_prefix"`
|
MetricTypePrefix string `toml:"metric_type_prefix"`
|
||||||
MetricNameFormat string `toml:"metric_name_format"`
|
MetricNameFormat string `toml:"metric_name_format"`
|
||||||
MetricDataType string `toml:"metric_data_type"`
|
MetricDataType string `toml:"metric_data_type"`
|
||||||
Log telegraf.Logger `toml:"-"`
|
TagsAsResourceLabels []string `toml:"tags_as_resource_label"`
|
||||||
|
Log telegraf.Logger `toml:"-"`
|
||||||
|
|
||||||
client *monitoring.MetricClient
|
client *monitoring.MetricClient
|
||||||
counterCache *counterCache
|
counterCache *counterCache
|
||||||
|
|
@ -223,6 +224,16 @@ func (s *Stackdriver) sendBatch(batch []telegraf.Metric) error {
|
||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert any declared tag to a resource label and remove it from
|
||||||
|
// the metric
|
||||||
|
resourceLabels := s.ResourceLabels
|
||||||
|
for _, tag := range s.TagsAsResourceLabels {
|
||||||
|
if val, ok := m.GetTag(tag); ok {
|
||||||
|
resourceLabels[tag] = val
|
||||||
|
m.RemoveTag(tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare time series.
|
// Prepare time series.
|
||||||
timeSeries := &monitoringpb.TimeSeries{
|
timeSeries := &monitoringpb.TimeSeries{
|
||||||
Metric: &metricpb.Metric{
|
Metric: &metricpb.Metric{
|
||||||
|
|
@ -232,7 +243,7 @@ func (s *Stackdriver) sendBatch(batch []telegraf.Metric) error {
|
||||||
MetricKind: metricKind,
|
MetricKind: metricKind,
|
||||||
Resource: &monitoredrespb.MonitoredResource{
|
Resource: &monitoredrespb.MonitoredResource{
|
||||||
Type: s.ResourceType,
|
Type: s.ResourceType,
|
||||||
Labels: s.ResourceLabels,
|
Labels: resourceLabels,
|
||||||
},
|
},
|
||||||
Points: []*monitoringpb.Point{
|
Points: []*monitoringpb.Point{
|
||||||
dataPoint,
|
dataPoint,
|
||||||
|
|
@ -254,7 +265,7 @@ func (s *Stackdriver) sendBatch(batch []telegraf.Metric) error {
|
||||||
MetricKind: metricpb.MetricDescriptor_CUMULATIVE,
|
MetricKind: metricpb.MetricDescriptor_CUMULATIVE,
|
||||||
Resource: &monitoredrespb.MonitoredResource{
|
Resource: &monitoredrespb.MonitoredResource{
|
||||||
Type: s.ResourceType,
|
Type: s.ResourceType,
|
||||||
Labels: s.ResourceLabels,
|
Labels: resourceLabels,
|
||||||
},
|
},
|
||||||
Points: []*monitoringpb.Point{
|
Points: []*monitoringpb.Point{
|
||||||
dataPoint,
|
dataPoint,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue