Add ability to specify bytes options as strings with units (KB, MiB, ...) (#4852)

This commit is contained in:
Samuel-BF
2018-10-19 20:17:18 +02:00
committed by Daniel Nelson
parent 17360f079c
commit 589d0587f6
16 changed files with 117 additions and 61 deletions

View File

@@ -42,7 +42,7 @@ The InfluxDB output plugin writes metrics to the [InfluxDB v1.x] HTTP or UDP ser
# user_agent = "telegraf"
## UDP payload size is the maximum packet size to send.
# udp_payload = 512
# udp_payload = "512B"
## Optional TLS Config for use on HTTP connections.
# tls_ca = "/etc/telegraf/ca.pem"

View File

@@ -41,7 +41,7 @@ type InfluxDB struct {
RetentionPolicy string
WriteConsistency string
Timeout internal.Duration
UDPPayload int `toml:"udp_payload"`
UDPPayload internal.Size `toml:"udp_payload"`
HTTPProxy string `toml:"http_proxy"`
HTTPHeaders map[string]string `toml:"http_headers"`
ContentEncoding string `toml:"content_encoding"`
@@ -95,7 +95,7 @@ var sampleConfig = `
# user_agent = "telegraf"
## UDP payload size is the maximum packet size to send.
# udp_payload = 512
# udp_payload = "512B"
## Optional TLS Config for use on HTTP connections.
# tls_ca = "/etc/telegraf/ca.pem"
@@ -225,7 +225,7 @@ func (i *InfluxDB) Write(metrics []telegraf.Metric) error {
func (i *InfluxDB) udpClient(url *url.URL) (Client, error) {
config := &UDPConfig{
URL: url,
MaxPayloadSize: i.UDPPayload,
MaxPayloadSize: int(i.UDPPayload.Size),
Serializer: i.serializer,
}

View File

@@ -74,7 +74,7 @@ func TestConnectUDPConfig(t *testing.T) {
output := influxdb.InfluxDB{
URLs: []string{"udp://localhost:8089"},
UDPPayload: 42,
UDPPayload: internal.Size{Size: 42},
CreateUDPClientF: func(config *influxdb.UDPConfig) (influxdb.Client, error) {
actual = config