diff --git a/go.mod b/go.mod index 192fd39af..ec3b15ad2 100644 --- a/go.mod +++ b/go.mod @@ -146,7 +146,7 @@ require ( github.com/vapourismo/knx-go v0.0.0-20211128234507-8198fa17db36 github.com/vjeantet/grok v1.0.1 github.com/vmware/govmomi v0.29.0 - github.com/wavefronthq/wavefront-sdk-go v0.9.11 + github.com/wavefronthq/wavefront-sdk-go v0.10.1 github.com/wvanbergen/kafka v0.0.0-20171203153745-e2edea948ddf github.com/xdg/scram v1.0.5 github.com/yuin/goldmark v1.4.1 diff --git a/go.sum b/go.sum index 86aea5996..448ff493e 100644 --- a/go.sum +++ b/go.sum @@ -2267,8 +2267,8 @@ github.com/vjeantet/grok v1.0.1/go.mod h1:ax1aAchzC6/QMXMcyzHQGZWaW1l195+uMYIkCW github.com/vmware/govmomi v0.29.0 h1:SHJQ7DUc4fltFZv16znJNGHR1/XhiDK5iKxm2OqwkuU= github.com/vmware/govmomi v0.29.0/go.mod h1:F7adsVewLNHsW/IIm7ziFURaXDaHEwcc+ym4r3INMdY= github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad/go.mod h1:Hy8o65+MXnS6EwGElrSRjUzQDLXreJlzYLlWiHtt8hM= -github.com/wavefronthq/wavefront-sdk-go v0.9.11 h1:3qv/yyNNyLKPQftQWFrfHGUv50e/gMxKlUQnILlvHKw= -github.com/wavefronthq/wavefront-sdk-go v0.9.11/go.mod h1:AcW8zJJcYodB7B9KYzoxVH6K0fmYd6MgpmXE1LMo+OU= +github.com/wavefronthq/wavefront-sdk-go v0.10.1 h1:my6q/yDaSi4bADHr9006YrHBhTdjEtpU0UpT0NDaSw8= +github.com/wavefronthq/wavefront-sdk-go v0.10.1/go.mod h1:JHflWDtew1icwZB6OEvHedBFD9T1h7Se/m+dBSjywu8= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI= diff --git a/plugins/outputs/wavefront/README.md b/plugins/outputs/wavefront/README.md index 0335d3caf..59256ede8 100644 --- a/plugins/outputs/wavefront/README.md +++ b/plugins/outputs/wavefront/README.md @@ -1,27 +1,25 @@ # Wavefront Output Plugin -This plugin writes to a [Wavefront](https://www.wavefront.com) proxy, in -Wavefront data format over TCP. +This plugin writes to a [Wavefront](https://www.wavefront.com) instance or a +Wavefront Proxy instance over HTTP or HTTPS. ## Configuration ```toml @sample.conf -# Configuration for Wavefront server to send metrics to [[outputs.wavefront]] - ## Url for Wavefront Direct Ingestion. For Wavefront Proxy Ingestion, see - ## the 'host' and 'port' options below. + ## Url for Wavefront API or Wavefront Proxy instance. url = "https://metrics.wavefront.com" - ## Authentication Token for Wavefront. Only required if using Direct Ingestion + ## Authentication Token for Wavefront. Required if using Direct Ingestion. Not required if using a Wavefront Proxy. #token = "DUMMY_TOKEN" - ## Maximum number of metrics to send per batch for Direct Ingestion. Ignored unless 'url' is set. This value should be higher than the `metric_batch_size`. Default is 10,000. Values higher than 40,000 are not recommended. + ## Maximum number of metrics to send per HTTP request. This value should be higher than the `metric_batch_size`. Default is 10,000. Values higher than 40,000 are not recommended. # http_maximum_batch_size = 10000 - ## DNS name of the wavefront proxy server. Do not use if url is specified + ## Deprecated. DNS name of the Wavefront server or Wavefront Proxy. Use the `url` field instead. #host = "wavefront.example.com" - ## Port that the Wavefront proxy server listens on. Do not use if url is specified + ## Deprecated. Wavefront proxy port. Use the `url` field instead. #port = 2878 ## prefix for metrics keys diff --git a/plugins/outputs/wavefront/sample.conf b/plugins/outputs/wavefront/sample.conf index 23c21f5d1..14088ea0a 100644 --- a/plugins/outputs/wavefront/sample.conf +++ b/plugins/outputs/wavefront/sample.conf @@ -1,19 +1,17 @@ -# Configuration for Wavefront server to send metrics to [[outputs.wavefront]] - ## Url for Wavefront Direct Ingestion. For Wavefront Proxy Ingestion, see - ## the 'host' and 'port' options below. + ## Url for Wavefront API or Wavefront Proxy instance. url = "https://metrics.wavefront.com" - ## Authentication Token for Wavefront. Only required if using Direct Ingestion + ## Authentication Token for Wavefront. Required if using Direct Ingestion. Not required if using a Wavefront Proxy. #token = "DUMMY_TOKEN" - ## Maximum number of metrics to send per batch for Direct Ingestion. Ignored unless 'url' is set. This value should be higher than the `metric_batch_size`. Default is 10,000. Values higher than 40,000 are not recommended. + ## Maximum number of metrics to send per HTTP request. This value should be higher than the `metric_batch_size`. Default is 10,000. Values higher than 40,000 are not recommended. # http_maximum_batch_size = 10000 - ## DNS name of the wavefront proxy server. Do not use if url is specified + ## Deprecated. DNS name of the Wavefront server or Wavefront Proxy. Use the `url` field instead. #host = "wavefront.example.com" - ## Port that the Wavefront proxy server listens on. Do not use if url is specified + ## Deprecated. Wavefront proxy port. Use the `url` field instead. #port = 2878 ## prefix for metrics keys diff --git a/plugins/outputs/wavefront/wavefront.go b/plugins/outputs/wavefront/wavefront.go index 50070172b..dc9c0b6b8 100644 --- a/plugins/outputs/wavefront/wavefront.go +++ b/plugins/outputs/wavefront/wavefront.go @@ -4,6 +4,7 @@ package wavefront import ( _ "embed" "fmt" + "net/url" "regexp" "strings" @@ -22,8 +23,8 @@ const maxTagLength = 254 type Wavefront struct { URL string `toml:"url"` Token string `toml:"token"` - Host string `toml:"host"` - Port int `toml:"port"` + Host string `toml:"host" deprecated:"2.4.0;use url instead"` + Port int `toml:"port" deprecated:"2.4.0;use url instead"` Prefix string `toml:"prefix"` SimpleFields bool `toml:"simple_fields"` MetricSeparator string `toml:"metric_separator"` @@ -77,36 +78,50 @@ func (*Wavefront) SampleConfig() string { return sampleConfig } +func senderURLFromURLAndToken(rawURL, token string) (string, error) { + newURL, err := url.Parse(rawURL) + if err != nil { + return "", fmt.Errorf("could not parse the provided Url: %s", rawURL) + } + newURL.User = url.User(token) + + return newURL.String(), nil +} + +func senderURLFromHostAndPort(host string, port int) string { + return fmt.Sprintf("http://%s:%d", host, port) +} + func (w *Wavefront) Connect() error { flushSeconds := 5 if w.ImmediateFlush { flushSeconds = 86400 // Set a very long flush interval if we're flushing directly } + var connectionURL string if w.URL != "" { w.Log.Debug("connecting over http/https using Url: %s", w.URL) - sender, err := wavefront.NewDirectSender(&wavefront.DirectConfiguration{ - Server: w.URL, - Token: w.Token, - FlushIntervalSeconds: flushSeconds, - BatchSize: w.HTTPMaximumBatchSize, - }) + connectionURLWithToken, err := senderURLFromURLAndToken(w.URL, w.Token) if err != nil { - return fmt.Errorf("could not create Wavefront Sender for Url: %s", w.URL) + return err } - w.sender = sender + connectionURL = connectionURLWithToken } else { - w.Log.Debugf("connecting over tcp using Host: %q and Port: %d", w.Host, w.Port) - sender, err := wavefront.NewProxySender(&wavefront.ProxyConfiguration{ - Host: w.Host, - MetricsPort: w.Port, - FlushIntervalSeconds: flushSeconds, - }) - if err != nil { - return fmt.Errorf("could not create Wavefront Sender for Host: %q and Port: %d", w.Host, w.Port) - } - w.sender = sender + w.Log.Warnf("configuration with host/port is deprecated. Please use url.") + w.Log.Debugf("connecting over http using Host: %q and Port: %d", w.Host, w.Port) + connectionURL = senderURLFromHostAndPort(w.Host, w.Port) } + sender, err := wavefront.NewSender(connectionURL, + wavefront.BatchSize(w.HTTPMaximumBatchSize), + wavefront.FlushIntervalSeconds(flushSeconds), + ) + + if err != nil { + return fmt.Errorf("could not create Wavefront Sender for the provided url") + } + + w.sender = sender + if w.ConvertPaths && w.MetricSeparator == "_" { w.ConvertPaths = false } @@ -140,7 +155,7 @@ func (w *Wavefront) Write(metrics []telegraf.Metric) error { } func (w *Wavefront) buildMetrics(m telegraf.Metric) []*MetricPoint { - ret := []*MetricPoint{} + ret := make([]*MetricPoint, 0) for fieldName, value := range m.Fields() { var name string diff --git a/plugins/outputs/wavefront/wavefront_test.go b/plugins/outputs/wavefront/wavefront_test.go index ec88678b6..090793f10 100644 --- a/plugins/outputs/wavefront/wavefront_test.go +++ b/plugins/outputs/wavefront/wavefront_test.go @@ -355,6 +355,17 @@ func TestTagLimits(t *testing.T) { require.Equal(t, longKey, tags[longKey]) } +func TestSenderURLFromHostAndPort(t *testing.T) { + require.Equal(t, "http://localhost:2878", senderURLFromHostAndPort("localhost", 2878)) +} + +func TestSenderURLFromURLAndToken(t *testing.T) { + url, err := senderURLFromURLAndToken("https://surf.wavefront.com", "11111111-2222-3333-4444-555555555555") + require.Nil(t, err) + require.Equal(t, "https://11111111-2222-3333-4444-555555555555@surf.wavefront.com", + url) +} + func TestDefaults(t *testing.T) { defaultWavefront := outputs.Outputs["wavefront"]().(*Wavefront) require.Equal(t, 10000, defaultWavefront.HTTPMaximumBatchSize)