Add influx uint support as a runtime option (#3948)
This commit is contained in:
@@ -9,18 +9,6 @@ import (
|
||||
"github.com/influxdata/telegraf"
|
||||
)
|
||||
|
||||
const MaxInt = int(^uint(0) >> 1)
|
||||
|
||||
// enableUint64Support will enable uint64 support if set to true.
|
||||
var enableUint64Support = false
|
||||
|
||||
// EnableUintSupport manually enables uint support for convertValue.
|
||||
// This function will be removed in the future and only exists for unit tests during the
|
||||
// transition.
|
||||
func EnableUintSupport() {
|
||||
enableUint64Support = true
|
||||
}
|
||||
|
||||
type metric struct {
|
||||
name string
|
||||
tags []*telegraf.Tag
|
||||
@@ -269,19 +257,8 @@ func convertField(v interface{}) interface{} {
|
||||
case int:
|
||||
return int64(v)
|
||||
case uint:
|
||||
if v <= uint(MaxInt) {
|
||||
return int64(v)
|
||||
} else {
|
||||
return int64(MaxInt)
|
||||
}
|
||||
return uint64(v)
|
||||
case uint64:
|
||||
if enableUint64Support == false {
|
||||
if v <= uint64(MaxInt) {
|
||||
return int64(v)
|
||||
} else {
|
||||
return int64(MaxInt)
|
||||
}
|
||||
}
|
||||
return uint64(v)
|
||||
case []byte:
|
||||
return string(v)
|
||||
@@ -292,11 +269,11 @@ func convertField(v interface{}) interface{} {
|
||||
case int8:
|
||||
return int64(v)
|
||||
case uint32:
|
||||
return int64(v)
|
||||
return uint64(v)
|
||||
case uint16:
|
||||
return int64(v)
|
||||
return uint64(v)
|
||||
case uint8:
|
||||
return int64(v)
|
||||
return uint64(v)
|
||||
case float32:
|
||||
return float64(v)
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user