Skip string fields in stackdriver output (#5384)
This commit is contained in:
parent
f54da4d748
commit
d4ab5da34f
|
@ -17,3 +17,8 @@ Metrics are grouped by the `namespace` variable and metric key - eg: `custom.goo
|
|||
# The namespace for the metric descriptor
|
||||
namespace = "telegraf"
|
||||
```
|
||||
|
||||
### Restrictions
|
||||
|
||||
Stackdriver does not support string values in custom metrics, any string
|
||||
fields will not be written.
|
||||
|
|
|
@ -6,12 +6,10 @@ import (
|
|||
"log"
|
||||
"path"
|
||||
|
||||
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/plugins/outputs"
|
||||
|
||||
// Imports the Stackdriver Monitoring client package.
|
||||
monitoring "cloud.google.com/go/monitoring/apiv3"
|
||||
googlepb "github.com/golang/protobuf/ptypes/timestamp"
|
||||
metricpb "google.golang.org/genproto/googleapis/api/metric"
|
||||
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
|
||||
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
|
||||
|
@ -86,6 +84,10 @@ func (s *Stackdriver) Write(metrics []telegraf.Metric) error {
|
|||
continue
|
||||
}
|
||||
|
||||
if value == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
metricKind, err := getStackdriverMetricKind(m.Type())
|
||||
if err != nil {
|
||||
log.Printf("E! [output.stackdriver] get metric failed: %s", err)
|
||||
|
@ -222,11 +224,8 @@ func getStackdriverTypedValue(value interface{}) (*monitoringpb.TypedValue, erro
|
|||
},
|
||||
}, nil
|
||||
case string:
|
||||
return &monitoringpb.TypedValue{
|
||||
Value: &monitoringpb.TypedValue_StringValue{
|
||||
StringValue: string(v),
|
||||
},
|
||||
}, nil
|
||||
// String value types are not available for custom metrics
|
||||
return nil, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("value type \"%T\" not supported for stackdriver custom metrics", v)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue