Skip to content

Commit

Permalink
Fix conversion of unsigned ints in prometheus output (#3978)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7177e04)
  • Loading branch information
danielnelson committed Apr 5, 2018
1 parent 3c03992 commit 38075d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/outputs/prometheus_client/prometheus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
switch fv := fv.(type) {
case int64:
value = float64(fv)
case uint64:
value = float64(fv)
case float64:
value = fv
default:
Expand Down Expand Up @@ -391,6 +393,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
switch fv := fv.(type) {
case int64:
value = float64(fv)
case uint64:
value = float64(fv)
case float64:
value = fv
default:
Expand Down Expand Up @@ -427,6 +431,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
switch fv := fv.(type) {
case int64:
value = float64(fv)
case uint64:
value = float64(fv)
case float64:
value = fv
default:
Expand Down
20 changes: 20 additions & 0 deletions plugins/outputs/prometheus_client/prometheus_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ func TestWrite_Counters(t *testing.T) {
metricName: "foo_other",
valueType: telegraf.Counter,
},
{
name: "uint64 fields are output",
args: args{
measurement: "foo",
fields: map[string]interface{}{"value": uint64(42)},
valueType: telegraf.Counter,
},
metricName: "foo",
valueType: telegraf.Counter,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -239,6 +249,16 @@ func TestWrite_Gauge(t *testing.T) {
metricName: "foo_other",
valueType: telegraf.Gauge,
},
{
name: "uint64 fields are output",
args: args{
measurement: "foo",
fields: map[string]interface{}{"value": uint64(42)},
valueType: telegraf.Counter,
},
metricName: "foo",
valueType: telegraf.Counter,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 38075d8

Please sign in to comment.