Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert boolean metric values to float. More verbose message when failing to build a metric #3804

Merged
merged 1 commit into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions plugins/outputs/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (d *Datadog) Write(metrics []telegraf.Metric) error {
metricCounter++
}
} else {
log.Printf("I! unable to build Metric for %s, skipping\n", m.Name())
log.Printf("I! unable to build Metric for %s due to error '%v', skipping\n", m.Name(), err)
}
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func buildMetrics(m telegraf.Metric) (map[string]Point, error) {
}
var p Point
if err := p.setValue(v); err != nil {
return ms, fmt.Errorf("unable to extract value from Fields, %s", err.Error())
return ms, fmt.Errorf("unable to extract value from Fields %v error %v", k, err.Error())
}
p[0] = float64(m.Time().Unix())
ms[k] = p
Expand Down Expand Up @@ -189,6 +189,11 @@ func (p *Point) setValue(v interface{}) error {
p[1] = float64(d)
case float64:
p[1] = float64(d)
case bool:
p[1] = float64(0)
if d {
p[1] = float64(1)
}
default:
return fmt.Errorf("undeterminable type")
}
Expand Down
16 changes: 16 additions & 0 deletions plugins/outputs/datadog/datadog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ func TestBuildPoint(t *testing.T) {
},
nil,
},
{
testutil.TestMetric(bool(true), "test7"),
Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
1.0,
},
nil,
},
{
testutil.TestMetric(bool(false), "test8"),
Point{
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
0.0,
},
nil,
},
}
for _, tt := range tagtests {
pt, err := buildMetrics(tt.ptIn)
Expand Down