Skip to content

Commit

Permalink
fix(wavefront output): update wavefront sdk and use non-deprecated APIs
Browse files Browse the repository at this point in the history
- always create http(s) connection
  • Loading branch information
LukeWinikates committed Jul 28, 2022
1 parent b2f3822 commit 1781585
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,5 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace google.golang.org/grpc/naming => google.golang.org/grpc v1.29.1
44 changes: 19 additions & 25 deletions plugins/outputs/wavefront/wavefront.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (*Wavefront) SampleConfig() string {
return sampleConfig
}

func SenderURLFromURLAndToken(rawURL, token string) (string, error) {
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)
Expand All @@ -88,46 +88,40 @@ func SenderURLFromURLAndToken(rawURL, token string) (string, error) {
return newURL.String(), nil
}

func SenderURLFromHostAndPort(host string, port int) string {
newURL := url.URL{
Scheme: "tcp",
Host: fmt.Sprintf("%s:%d", host, port),
}
return newURL.String()
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)
newURL, err := SenderURLFromURLAndToken(w.URL, w.Token)
connectionURLWithToken, err := senderURLFromURLAndToken(w.URL, w.Token)
if err != nil {
return err
}

sender, err := wavefront.NewSender(newURL,
wavefront.BatchSize(w.HTTPMaximumBatchSize),
wavefront.FlushIntervalSeconds(flushSeconds),
)
if err != nil {
return fmt.Errorf("could not create Wavefront Sender for Url: %s", w.URL)
}
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.NewSender(SenderURLFromHostAndPort(w.Host, w.Port),
wavefront.FlushIntervalSeconds(flushSeconds))
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)
}

if err != nil {
return fmt.Errorf("could not create Wavefront Sender for Host: %q and Port: %d", w.Host, w.Port)
}
w.sender = sender
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
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/outputs/wavefront/wavefront_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ func TestTagLimits(t *testing.T) {
}

func TestSenderURLFromHostAndPort(t *testing.T) {
require.Equal(t, "tcp://localhost:2878", SenderURLFromHostAndPort("localhost", 2878))
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")
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)
Expand Down

0 comments on commit 1781585

Please sign in to comment.