Fix conversion of unsigned ints in prometheus output (#3978)

This commit is contained in:
Daniel Nelson 2018-04-05 16:38:41 -07:00 committed by GitHub
parent 252101b7c6
commit 7177e0473f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

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

View File

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