Skip to content

Commit

Permalink
[Ajat|Baskara] add Register to metricCollectorRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha committed Jul 1, 2019
1 parent eb59f38 commit ec8eba0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/gojektech/heimdall v5.0.2+incompatible
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect
github.com/gorilla/mux v1.7.2
github.com/magiconair/properties v1.8.0
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2
github.com/smartystreets/assertions v1.0.0 // indirect
Expand Down
18 changes: 17 additions & 1 deletion pkg/plugins/metrics/collector.go → pkg/metrics/collector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
package metrics

import "time"
import (
"sync"
"time"
)

type metricCollectorRegistry struct {
lock *sync.RWMutex
registry []func(name string) MetricCollector
}

// Register places a MetricCollector Initializer in the registry maintained by this metricCollectorRegistry.
func (m *metricCollectorRegistry) Register(initMetricCollector func(string) MetricCollector) {
m.lock.Lock()
defer m.lock.Unlock()

m.registry = append(m.registry, initMetricCollector)
}

type MetricResult struct {
ProcessingDuration time.Duration
Expand Down
15 changes: 15 additions & 0 deletions pkg/metrics/collector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package metrics

import (
"github.com/stretchr/testify/assert"
"sync"
"testing"
)

func TestMetricCollectorRegistry_Register(t *testing.T) {
sc := InitializeStatsdCollector(&StatsdCollectorConfig{})
mcr := metricCollectorRegistry{lock: &sync.RWMutex{}}

mcr.Register(sc.NewStatsdMetricCollector)
assert.Equal(t, 1, len(mcr.registry))
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package plugins
package metrics

import (
"github.com/cactus/go-statsd-client/statsd"
"***REMOVED***/darkroom/core/pkg/plugins/metrics"
"time"
)

Expand Down Expand Up @@ -61,7 +60,7 @@ func InitializeStatsdCollector(config *StatsdCollectorConfig) *StatsdCollectorCl

// 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 {
func (s *StatsdCollectorClient) NewStatsdMetricCollector(name string) MetricCollector {
return &StatsdCollector{
client: s.client,
processingDuration: name + ".processingDuration",
Expand All @@ -76,7 +75,7 @@ func (s *StatsdCollectorClient) NewStatsdMetricCollector(name string) metrics.Me
}
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package plugins
package metrics

import (
"github.com/cactus/go-statsd-client/statsd"
Expand Down

0 comments on commit ec8eba0

Please sign in to comment.