feat(outputs.wavefront): Use common/http to configure http client (#14136)

This commit is contained in:
Luke Winikates 2023-10-23 07:10:35 -07:00 committed by GitHub
parent 56edee0b4f
commit 3eed69f866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 18 deletions

2
go.mod
View File

@ -181,7 +181,7 @@ require (
github.com/vapourismo/knx-go v0.0.0-20220829185957-fb5458a5389d github.com/vapourismo/knx-go v0.0.0-20220829185957-fb5458a5389d
github.com/vjeantet/grok v1.0.1 github.com/vjeantet/grok v1.0.1
github.com/vmware/govmomi v0.32.0 github.com/vmware/govmomi v0.32.0
github.com/wavefronthq/wavefront-sdk-go v0.14.0 github.com/wavefronthq/wavefront-sdk-go v0.15.0
github.com/wvanbergen/kafka v0.0.0-20171203153745-e2edea948ddf github.com/wvanbergen/kafka v0.0.0-20171203153745-e2edea948ddf
github.com/x448/float16 v0.8.4 github.com/x448/float16 v0.8.4
github.com/xdg/scram v1.0.5 github.com/xdg/scram v1.0.5

4
go.sum
View File

@ -1511,8 +1511,8 @@ github.com/vjeantet/grok v1.0.1 h1:2rhIR7J4gThTgcZ1m2JY4TrJZNgjn985U28kT2wQrJ4=
github.com/vjeantet/grok v1.0.1/go.mod h1:ax1aAchzC6/QMXMcyzHQGZWaW1l195+uMYIkCWPCNIo= github.com/vjeantet/grok v1.0.1/go.mod h1:ax1aAchzC6/QMXMcyzHQGZWaW1l195+uMYIkCWPCNIo=
github.com/vmware/govmomi v0.32.0 h1:Rsdi/HAX5Ebf9Byp/FvBir4sfM7yP5DBUeRlbC6vLBo= github.com/vmware/govmomi v0.32.0 h1:Rsdi/HAX5Ebf9Byp/FvBir4sfM7yP5DBUeRlbC6vLBo=
github.com/vmware/govmomi v0.32.0/go.mod h1:JA63Pg0SgQcSjk+LuPzjh3rJdcWBo/ZNCIwbb1qf2/0= github.com/vmware/govmomi v0.32.0/go.mod h1:JA63Pg0SgQcSjk+LuPzjh3rJdcWBo/ZNCIwbb1qf2/0=
github.com/wavefronthq/wavefront-sdk-go v0.14.0 h1:Nq+yobFZrVw3bfXh+EsWmWDtwMHYRKLRVXgnB1S0j34= github.com/wavefronthq/wavefront-sdk-go v0.15.0 h1:po9E3vh/0y7kOx8D9EtFp7kbSLLLKbmu/w/s1xGJAQU=
github.com/wavefronthq/wavefront-sdk-go v0.14.0/go.mod h1:V72c8e+bXuLK8HpA6ioW0ll5mK9IPD+4IHNNDY75ksA= github.com/wavefronthq/wavefront-sdk-go v0.15.0/go.mod h1:V72c8e+bXuLK8HpA6ioW0ll5mK9IPD+4IHNNDY75ksA=
github.com/wvanbergen/kafka v0.0.0-20171203153745-e2edea948ddf h1:TOV5PC6fIWwFOFra9xJfRXZcL2pLhMI8oNuDugNxg9Q= github.com/wvanbergen/kafka v0.0.0-20171203153745-e2edea948ddf h1:TOV5PC6fIWwFOFra9xJfRXZcL2pLhMI8oNuDugNxg9Q=
github.com/wvanbergen/kafka v0.0.0-20171203153745-e2edea948ddf/go.mod h1:nxx7XRXbR9ykhnC8lXqQyJS0rfvJGxKyKw/sT1YOttg= github.com/wvanbergen/kafka v0.0.0-20171203153745-e2edea948ddf/go.mod h1:nxx7XRXbR9ykhnC8lXqQyJS0rfvJGxKyKw/sT1YOttg=
github.com/wvanbergen/kazoo-go v0.0.0-20180202103751-f72d8611297a h1:ILoU84rj4AQ3q6cjQvtb9jBjx4xzR/Riq/zYhmDQiOk= github.com/wvanbergen/kazoo-go v0.0.0-20180202103751-f72d8611297a h1:ILoU84rj4AQ3q6cjQvtb9jBjx4xzR/Riq/zYhmDQiOk=

View File

@ -89,6 +89,20 @@ to use them.
## HTTP Timeout ## HTTP Timeout
# timeout="10s" # timeout="10s"
## MaxIdleConns controls the maximum number of idle (keep-alive)
## connections across all hosts. Zero means no limit.
# max_idle_conn = 0
## MaxIdleConnsPerHost, if non-zero, controls the maximum idle
## (keep-alive) connections to keep per-host. If zero,
## DefaultMaxIdleConnsPerHost is used(2).
# max_idle_conn_per_host = 2
## Idle (keep-alive) connection timeout.
## Maximum amount of time before idle connection is closed.
## Zero means no limit.
# idle_conn_timeout = 0
## Authentication for Direct Ingestion. ## Authentication for Direct Ingestion.
## Direct Ingestion requires one of: `token`,`auth_csp_api_token`, or `auth_csp_client_credentials` ## Direct Ingestion requires one of: `token`,`auth_csp_api_token`, or `auth_csp_client_credentials`
## See https://docs.wavefront.com/csp_getting_started.html to learn more about using CSP credentials with Wavefront. ## See https://docs.wavefront.com/csp_getting_started.html to learn more about using CSP credentials with Wavefront.

View File

@ -64,6 +64,20 @@
## HTTP Timeout ## HTTP Timeout
# timeout="10s" # timeout="10s"
## MaxIdleConns controls the maximum number of idle (keep-alive)
## connections across all hosts. Zero means no limit.
# max_idle_conn = 0
## MaxIdleConnsPerHost, if non-zero, controls the maximum idle
## (keep-alive) connections to keep per-host. If zero,
## DefaultMaxIdleConnsPerHost is used(2).
# max_idle_conn_per_host = 2
## Idle (keep-alive) connection timeout.
## Maximum amount of time before idle connection is closed.
## Zero means no limit.
# idle_conn_timeout = 0
## Authentication for Direct Ingestion. ## Authentication for Direct Ingestion.
## Direct Ingestion requires one of: `token`,`auth_csp_api_token`, or `auth_csp_client_credentials` ## Direct Ingestion requires one of: `token`,`auth_csp_api_token`, or `auth_csp_client_credentials`
## See https://docs.wavefront.com/csp_getting_started.html to learn more about using CSP credentials with Wavefront. ## See https://docs.wavefront.com/csp_getting_started.html to learn more about using CSP credentials with Wavefront.

View File

@ -2,7 +2,7 @@
package wavefront package wavefront
import ( import (
cryptoTls "crypto/tls" "context"
_ "embed" _ "embed"
"errors" "errors"
"fmt" "fmt"
@ -15,7 +15,7 @@ import (
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/common/tls" httpconfig "github.com/influxdata/telegraf/plugins/common/http"
"github.com/influxdata/telegraf/plugins/outputs" "github.com/influxdata/telegraf/plugins/outputs"
serializer "github.com/influxdata/telegraf/plugins/serializers/wavefront" serializer "github.com/influxdata/telegraf/plugins/serializers/wavefront"
) )
@ -45,7 +45,6 @@ type Wavefront struct {
ConvertPaths bool `toml:"convert_paths"` ConvertPaths bool `toml:"convert_paths"`
ConvertBool bool `toml:"convert_bool"` ConvertBool bool `toml:"convert_bool"`
HTTPMaximumBatchSize int `toml:"http_maximum_batch_size"` HTTPMaximumBatchSize int `toml:"http_maximum_batch_size"`
Timeout config.Duration `toml:"timeout"`
UseRegex bool `toml:"use_regex"` UseRegex bool `toml:"use_regex"`
UseStrict bool `toml:"use_strict"` UseStrict bool `toml:"use_strict"`
TruncateTags bool `toml:"truncate_tags"` TruncateTags bool `toml:"truncate_tags"`
@ -53,7 +52,9 @@ type Wavefront struct {
SendInternalMetrics bool `toml:"send_internal_metrics"` SendInternalMetrics bool `toml:"send_internal_metrics"`
SourceOverride []string `toml:"source_override"` SourceOverride []string `toml:"source_override"`
StringToNumber map[string][]map[string]float64 `toml:"string_to_number" deprecated:"1.9.0;use the enum processor instead"` StringToNumber map[string][]map[string]float64 `toml:"string_to_number" deprecated:"1.9.0;use the enum processor instead"`
tls.ClientConfig
httpconfig.HTTPClientConfig
sender wavefront.Sender sender wavefront.Sender
Log telegraf.Logger `toml:"-"` Log telegraf.Logger `toml:"-"`
} }
@ -87,13 +88,15 @@ func (w *Wavefront) parseConnectionURL() (string, error) {
return u.String(), nil return u.String(), nil
} }
func (w *Wavefront) createSender(connectionURL string, flushSeconds int, tlsConfig *cryptoTls.Config) (wavefront.Sender, error) { func (w *Wavefront) createSender(connectionURL string, flushSeconds int) (wavefront.Sender, error) {
timeout := time.Duration(w.Timeout) client, err := w.CreateClient(context.Background(), w.Log)
if err != nil {
return nil, err
}
options := []wavefront.Option{ options := []wavefront.Option{
wavefront.BatchSize(w.HTTPMaximumBatchSize), wavefront.BatchSize(w.HTTPMaximumBatchSize),
wavefront.FlushIntervalSeconds(flushSeconds), wavefront.FlushIntervalSeconds(flushSeconds),
wavefront.TLSConfigOptions(tlsConfig), wavefront.HTTPClient(client),
wavefront.Timeout(timeout),
wavefront.SendInternalMetrics(w.SendInternalMetrics), wavefront.SendInternalMetrics(w.SendInternalMetrics),
} }
@ -116,12 +119,7 @@ func (w *Wavefront) Connect() error {
return err return err
} }
tlsConfig, err := w.TLSConfig() sender, err := w.createSender(connectionURL, flushSeconds)
if err != nil {
return err
}
sender, err := w.createSender(connectionURL, flushSeconds, tlsConfig)
if err != nil { if err != nil {
return fmt.Errorf("could not create Wavefront Sender for the provided url") return fmt.Errorf("could not create Wavefront Sender for the provided url")
@ -384,7 +382,7 @@ func init() {
ImmediateFlush: true, ImmediateFlush: true,
SendInternalMetrics: true, SendInternalMetrics: true,
HTTPMaximumBatchSize: 10000, HTTPMaximumBatchSize: 10000,
Timeout: config.Duration(10 * time.Second), HTTPClientConfig: httpconfig.HTTPClientConfig{Timeout: config.Duration(10 * time.Second)},
CSPBaseURL: "https://console.cloud.vmware.com", CSPBaseURL: "https://console.cloud.vmware.com",
} }
}) })