Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions datadog/dogstatsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ func NewDogStatsdSink(addr string, hostName string) (*DogStatsdSink, error) {
return sink, nil
}

// NewDogStatsdSinkFromClient returns a DogStatsdSink that uses a pre-existing datadog client
func NewDogStatsdSinkFromClient(client *statsd.Client, hostName string) *DogStatsdSink {
return &DogStatsdSink{
client: client,
hostName: hostName,
propagateHostname: false,
}
}

// SetTags sets common tags on the Dogstatsd Client that will be sent
// along with all dogstatsd packets.
// Ref: http://docs.datadoghq.com/guides/dogstatsd/#tags
Expand Down
15 changes: 15 additions & 0 deletions datadog/dogstatsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"reflect"
"testing"

"github.com/DataDog/datadog-go/statsd"
"github.com/armon/go-metrics"
)

Expand Down Expand Up @@ -83,6 +84,20 @@ func setupTestServerAndBuffer(t *testing.T) (*net.UDPConn, []byte) {
return server, make([]byte, 1024)
}

func TestFromClient(t *testing.T) {
client := &statsd.Client{}
hostname := "fake-hostname"
sink := NewDogStatsdSinkFromClient(client, hostname)

if !reflect.DeepEqual(sink.client, client) {
t.Fatalf("Client assigned to sink did not match what was passed in")
}

if sink.hostName != hostname {
t.Fatalf("Sink hostname did not match what was passed in, %v != %v", sink.hostName, hostname)
}
}

func TestParseKey(t *testing.T) {
for _, tt := range ParseKeyTests {
dog := mockNewDogStatsdSink(DogStatsdAddr, tt.Tags, tt.PropagateHostname)
Expand Down