Skip to content
Snippets Groups Projects
Unverified Commit 7177e047 authored by Daniel Nelson's avatar Daniel Nelson Committed by GitHub
Browse files

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

parent 252101b7
No related branches found
No related tags found
No related merge requests found
...@@ -352,6 +352,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error { ...@@ -352,6 +352,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
switch fv := fv.(type) { switch fv := fv.(type) {
case int64: case int64:
value = float64(fv) value = float64(fv)
case uint64:
value = float64(fv)
case float64: case float64:
value = fv value = fv
default: default:
...@@ -391,6 +393,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error { ...@@ -391,6 +393,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
switch fv := fv.(type) { switch fv := fv.(type) {
case int64: case int64:
value = float64(fv) value = float64(fv)
case uint64:
value = float64(fv)
case float64: case float64:
value = fv value = fv
default: default:
...@@ -427,6 +431,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error { ...@@ -427,6 +431,8 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
switch fv := fv.(type) { switch fv := fv.(type) {
case int64: case int64:
value = float64(fv) value = float64(fv)
case uint64:
value = float64(fv)
case float64: case float64:
value = fv value = fv
default: default:
......
...@@ -151,6 +151,16 @@ func TestWrite_Counters(t *testing.T) { ...@@ -151,6 +151,16 @@ func TestWrite_Counters(t *testing.T) {
metricName: "foo_other", metricName: "foo_other",
valueType: telegraf.Counter, 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 { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
...@@ -239,6 +249,16 @@ func TestWrite_Gauge(t *testing.T) { ...@@ -239,6 +249,16 @@ func TestWrite_Gauge(t *testing.T) {
metricName: "foo_other", metricName: "foo_other",
valueType: telegraf.Gauge, 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 { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment