Skip to content

Commit

Permalink
feat(outputs.wavefront): Use common/http to configure http client (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWinikates authored Oct 23, 2023
1 parent 56edee0 commit 3eed69f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ require (
github.com/vapourismo/knx-go v0.0.0-20220829185957-fb5458a5389d
github.com/vjeantet/grok v1.0.1
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/x448/float16 v0.8.4
github.com/xdg/scram v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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/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/wavefronthq/wavefront-sdk-go v0.14.0 h1:Nq+yobFZrVw3bfXh+EsWmWDtwMHYRKLRVXgnB1S0j34=
github.com/wavefronthq/wavefront-sdk-go v0.14.0/go.mod h1:V72c8e+bXuLK8HpA6ioW0ll5mK9IPD+4IHNNDY75ksA=
github.com/wavefronthq/wavefront-sdk-go v0.15.0 h1:po9E3vh/0y7kOx8D9EtFp7kbSLLLKbmu/w/s1xGJAQU=
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/go.mod h1:nxx7XRXbR9ykhnC8lXqQyJS0rfvJGxKyKw/sT1YOttg=
github.com/wvanbergen/kazoo-go v0.0.0-20180202103751-f72d8611297a h1:ILoU84rj4AQ3q6cjQvtb9jBjx4xzR/Riq/zYhmDQiOk=
Expand Down
14 changes: 14 additions & 0 deletions plugins/outputs/wavefront/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ to use them.
## HTTP Timeout
# 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.
## 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.
Expand Down
14 changes: 14 additions & 0 deletions plugins/outputs/wavefront/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@
## HTTP Timeout
# 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.
## 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.
Expand Down
28 changes: 13 additions & 15 deletions plugins/outputs/wavefront/wavefront.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package wavefront

import (
cryptoTls "crypto/tls"
"context"
_ "embed"
"errors"
"fmt"
Expand All @@ -15,7 +15,7 @@ import (

"github.com/influxdata/telegraf"
"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"
serializer "github.com/influxdata/telegraf/plugins/serializers/wavefront"
)
Expand Down Expand Up @@ -45,15 +45,16 @@ type Wavefront struct {
ConvertPaths bool `toml:"convert_paths"`
ConvertBool bool `toml:"convert_bool"`
HTTPMaximumBatchSize int `toml:"http_maximum_batch_size"`
Timeout config.Duration `toml:"timeout"`
UseRegex bool `toml:"use_regex"`
UseStrict bool `toml:"use_strict"`
TruncateTags bool `toml:"truncate_tags"`
ImmediateFlush bool `toml:"immediate_flush"`
SendInternalMetrics bool `toml:"send_internal_metrics"`
SourceOverride []string `toml:"source_override"`
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
Log telegraf.Logger `toml:"-"`
}
Expand Down Expand Up @@ -87,13 +88,15 @@ func (w *Wavefront) parseConnectionURL() (string, error) {
return u.String(), nil
}

func (w *Wavefront) createSender(connectionURL string, flushSeconds int, tlsConfig *cryptoTls.Config) (wavefront.Sender, error) {
timeout := time.Duration(w.Timeout)
func (w *Wavefront) createSender(connectionURL string, flushSeconds int) (wavefront.Sender, error) {
client, err := w.CreateClient(context.Background(), w.Log)
if err != nil {
return nil, err
}
options := []wavefront.Option{
wavefront.BatchSize(w.HTTPMaximumBatchSize),
wavefront.FlushIntervalSeconds(flushSeconds),
wavefront.TLSConfigOptions(tlsConfig),
wavefront.Timeout(timeout),
wavefront.HTTPClient(client),
wavefront.SendInternalMetrics(w.SendInternalMetrics),
}

Expand All @@ -116,12 +119,7 @@ func (w *Wavefront) Connect() error {
return err
}

tlsConfig, err := w.TLSConfig()
if err != nil {
return err
}

sender, err := w.createSender(connectionURL, flushSeconds, tlsConfig)
sender, err := w.createSender(connectionURL, flushSeconds)

if err != nil {
return fmt.Errorf("could not create Wavefront Sender for the provided url")
Expand Down Expand Up @@ -384,7 +382,7 @@ func init() {
ImmediateFlush: true,
SendInternalMetrics: true,
HTTPMaximumBatchSize: 10000,
Timeout: config.Duration(10 * time.Second),
HTTPClientConfig: httpconfig.HTTPClientConfig{Timeout: config.Duration(10 * time.Second)},
CSPBaseURL: "https://console.cloud.vmware.com",
}
})
Expand Down

0 comments on commit 3eed69f

Please sign in to comment.