Skip string fields in stackdriver output (#5384)

This commit is contained in:
Daniel Nelson 2019-02-05 18:22:42 -08:00 committed by GitHub
parent f54da4d748
commit d4ab5da34f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

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

View File

@ -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)
} }