Skip to content

Commit

Permalink
[Ajat|Baskara] add MetricCollector interface and StatsdCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha committed Jul 1, 2019
1 parent a3776c7 commit eb59f38
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/plugins/metrics/collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package metrics

import "time"

type MetricResult struct {
ProcessingDuration time.Duration
DownloadDuration time.Duration
TotalDuration time.Duration
ReadDuration time.Duration
WriteDuration time.Duration
CropDuration time.Duration
ResizeDuration time.Duration
MonoDuration time.Duration
}

// MetricCollector represents the contract that all collectors must fulfill to gather statistics.
// Implementations of this interface do not have to maintain locking around their data stores so long as
// they are not modified outside of the storage/processor context.
type MetricCollector interface {
// Update accepts a set of metrics from a command execution for remote instrumentation
Update(MetricResult)
// Reset resets the internal counters and timers.
Reset()
}
39 changes: 39 additions & 0 deletions 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"
"***REMOVED***/darkroom/core/pkg/plugins/metrics"
"time"
)

Expand All @@ -12,6 +13,19 @@ const (
GigabitStatsdFlushBytes = 8932
)

type StatsdCollector struct {
client statsd.Statter
processingDuration string
downloadDuration string
totalDuration string
readDuration string
writeDuration string
cropDuration string
resizeDuration string
monoDuration string
sampleRate float32
}

type StatsdCollectorClient struct {
client statsd.Statter
sampleRate float32
Expand Down Expand Up @@ -44,3 +58,28 @@ func InitializeStatsdCollector(config *StatsdCollectorConfig) *StatsdCollectorCl
// TODO Add logger for error
return &StatsdCollectorClient{client: c, sampleRate: sampleRate}
}

// NewStatsdMetricCollector creates a collector with specific name. The
// prefix given to these stats will be {config.Prefix}.{name}.{metric}.
func (s *StatsdCollectorClient) NewStatsdMetricCollector(name string) metrics.MetricCollector {
return &StatsdCollector{
client: s.client,
processingDuration: name + ".processingDuration",
downloadDuration: name + ".downloadDuration",
totalDuration: name + ".totalDuration",
readDuration: name + ".readDuration",
writeDuration: name + ".writeDuration",
cropDuration: name + ".cropDuration",
resizeDuration: name + ".resizeDuration",
monoDuration: name + ".monoDuration",
sampleRate: s.sampleRate,
}
}

func (sc *StatsdCollector) Update(metrics.MetricResult) {
// TODO ("implement me")
}

func (sc *StatsdCollector) Reset() {
// TODO ("implement me")
}
6 changes: 6 additions & 0 deletions pkg/plugins/statsd_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func TestInitializeStatsdCollector(t *testing.T) {
assert.NotNil(t, scc.client)
}

func TestNewStatsdMetricCollector(t *testing.T) {
scc := InitializeStatsdCollector(&StatsdCollectorConfig{Prefix: "darkroom"})
mc := scc.NewStatsdMetricCollector("app-name")
assert.NotNil(t, mc)
}

type mockStatsdClient struct {
}

Expand Down

0 comments on commit eb59f38

Please sign in to comment.