From 7177e0473f93732efde9b50542b19f6ccf057f51 Mon Sep 17 00:00:00 2001
From: Daniel Nelson <daniel@wavesofdawn.com>
Date: Thu, 5 Apr 2018 16:38:41 -0700
Subject: [PATCH] Fix conversion of unsigned ints in prometheus output (#3978)

---
 .../prometheus_client/prometheus_client.go    |  6 ++++++
 .../prometheus_client_test.go                 | 20 +++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/plugins/outputs/prometheus_client/prometheus_client.go b/plugins/outputs/prometheus_client/prometheus_client.go
index 5b416b72..b82c72cf 100644
--- a/plugins/outputs/prometheus_client/prometheus_client.go
+++ b/plugins/outputs/prometheus_client/prometheus_client.go
@@ -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:
diff --git a/plugins/outputs/prometheus_client/prometheus_client_test.go b/plugins/outputs/prometheus_client/prometheus_client_test.go
index 05bd5264..bd2398a2 100644
--- a/plugins/outputs/prometheus_client/prometheus_client_test.go
+++ b/plugins/outputs/prometheus_client/prometheus_client_test.go
@@ -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) {
-- 
GitLab