Skip to content

Commit

Permalink
Merge pull request #96 from keep94/30425
Browse files Browse the repository at this point in the history
In new Go API, name internal metrics based on sender mode.
  • Loading branch information
keep94 authored Aug 18, 2022
2 parents 05ff4a0 + a9f7b5a commit 10ec95b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
23 changes: 18 additions & 5 deletions senders/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package senders

import (
"fmt"
"github.com/wavefronthq/wavefront-sdk-go/internal"
"net/url"
"os"
"strconv"
"strings"

"github.com/wavefronthq/wavefront-sdk-go/internal"
)

const (
Expand Down Expand Up @@ -44,6 +45,18 @@ type configuration struct {
SDKMetricsTags map[string]string
}

func (c *configuration) Direct() bool {
return c.Token != ""
}

func (c *configuration) MetricPrefix() string {
result := "~sdk.go.core.sender.proxy"
if c.Direct() {
result = "~sdk.go.core.sender.direct"
}
return result
}

func (c *configuration) setDefaultPort(port int) {
c.MetricsPort = port
c.TracesPort = port
Expand Down Expand Up @@ -80,11 +93,11 @@ func CreateConfig(wfURL string, setters ...Option) (*configuration, error) {

switch strings.ToLower(u.Scheme) {
case "http":
if cfg.Token != "" {
if cfg.Direct() {
cfg.setDefaultPort(80)
}
case "https":
if cfg.Token != "" {
if cfg.Direct() {
cfg.setDefaultPort(443)
}
default:
Expand Down Expand Up @@ -114,7 +127,7 @@ func newWavefrontClient(cfg *configuration) (Sender, error) {

sender := &wavefrontSender{
defaultSource: internal.GetHostname("wavefront_direct_sender"),
proxy: len(cfg.Token) == 0,
proxy: !cfg.Direct(),
}
sender.initializeInternalMetrics(cfg)
sender.pointHandler = newLineHandler(metricsReporter, cfg, internal.MetricFormat, "points", sender.internalRegistry)
Expand All @@ -130,7 +143,7 @@ func newWavefrontClient(cfg *configuration) (Sender, error) {
func (sender *wavefrontSender) initializeInternalMetrics(cfg *configuration) {

var setters []internal.RegistryOption
setters = append(setters, internal.SetPrefix("~sdk.go.core.sender.direct"))
setters = append(setters, internal.SetPrefix(cfg.MetricPrefix()))
setters = append(setters, internal.SetTag("pid", strconv.Itoa(os.Getpid())))

for key, value := range cfg.SDKMetricsTags {
Expand Down
13 changes: 13 additions & 0 deletions senders/client_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ func TestDefaultPortsProxy(t *testing.T) {
assert.Equal(t, 30001, cfg.TracesPort)
}

func TestMetricPrefixProxy(t *testing.T) {
cfg, err := senders.CreateConfig("http://localhost")
require.NoError(t, err)
assert.False(t, cfg.Direct())
assert.Equal(t, "~sdk.go.core.sender.proxy", cfg.MetricPrefix())
}

func TestMetricPrefixDirect(t *testing.T) {
cfg, err := senders.CreateConfig("http://11111111-2222-3333-4444-555555555555@localhost")
require.NoError(t, err)
assert.True(t, cfg.Direct())
assert.Equal(t, "~sdk.go.core.sender.direct", cfg.MetricPrefix())
}
func TestDefaultPortsDIHttp(t *testing.T) {
cfg, err := senders.CreateConfig("http://11111111-2222-3333-4444-555555555555@localhost")
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package version

const Version = "0.9.10"
const Version = "0.10.2"

0 comments on commit 10ec95b

Please sign in to comment.