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
|
# The namespace for the metric descriptor
|
||||||
namespace = "telegraf"
|
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"
|
"log"
|
||||||
"path"
|
"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"
|
||||||
"github.com/influxdata/telegraf/plugins/outputs"
|
"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"
|
metricpb "google.golang.org/genproto/googleapis/api/metric"
|
||||||
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
|
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
|
||||||
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
|
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
|
||||||
|
@ -86,6 +84,10 @@ func (s *Stackdriver) Write(metrics []telegraf.Metric) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if value == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
metricKind, err := getStackdriverMetricKind(m.Type())
|
metricKind, err := getStackdriverMetricKind(m.Type())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("E! [output.stackdriver] get metric failed: %s", err)
|
log.Printf("E! [output.stackdriver] get metric failed: %s", err)
|
||||||
|
@ -222,11 +224,8 @@ func getStackdriverTypedValue(value interface{}) (*monitoringpb.TypedValue, erro
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
case string:
|
case string:
|
||||||
return &monitoringpb.TypedValue{
|
// String value types are not available for custom metrics
|
||||||
Value: &monitoringpb.TypedValue_StringValue{
|
return nil, nil
|
||||||
StringValue: string(v),
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("value type \"%T\" not supported for stackdriver custom metrics", v)
|
return nil, fmt.Errorf("value type \"%T\" not supported for stackdriver custom metrics", v)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue