Skip to content

Commit

Permalink
Skip string fields in stackdriver output (influxdata#5384)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and Max Eshleman committed Feb 13, 2019
1 parent 667d7b0 commit 2832343
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions plugins/outputs/stackdriver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 8 additions & 9 deletions plugins/outputs/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 2832343

Please sign in to comment.