Skip to content

Commit

Permalink
[Ajat|Baskara] add statsd.Statter client
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha committed Jul 1, 2019
1 parent 1e3358f commit 71294ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/plugins/statsd_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugins

import (
"github.com/cactus/go-statsd-client/statsd"
"time"
)

type StatsdCollectorClient struct {
Expand All @@ -17,12 +18,19 @@ type StatsdCollectorConfig struct {
Prefix string
// StatsdSampleRate sets statsd sampling. If 0, defaults to 1.0. (no sampling)
SampleRate float32
// FlushBytes sets message size for statsd packets.
FlushBytes int
}

func InitializeStatsdCollector(config *StatsdCollectorConfig) (*StatsdCollectorClient, error) {
flushBytes := config.FlushBytes

sampleRate := config.SampleRate
if sampleRate == 0 {
sampleRate = 1
}
return &StatsdCollectorClient{sampleRate: sampleRate}, nil

c, _ := statsd.NewBufferedClient(config.StatsdAddr, config.Prefix, 1*time.Second, flushBytes)

return &StatsdCollectorClient{client: c, sampleRate: sampleRate}, nil
}
6 changes: 6 additions & 0 deletions pkg/plugins/statsd_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func TestInitializeStatsdCollector(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, scc)
assert.Equal(t, float32(1), scc.sampleRate)

// Test Statter client
scc, err = InitializeStatsdCollector(&StatsdCollectorConfig{})
assert.Nil(t, err)
assert.NotNil(t, scc)
assert.NotNil(t, scc.client)
}

type mockStatsdClient struct {
Expand Down

0 comments on commit 71294ee

Please sign in to comment.