Skip to content

Commit

Permalink
Merge pull request #11 from movio/export-noop-metrics-provider
Browse files Browse the repository at this point in the history
Export NoopMetricsProvider
  • Loading branch information
nmaquet authored Jul 12, 2017
2 parents 0a192be + 992b4e2 commit 7cc9efe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (config *Config) setDefaults() {
config.Logger = NewBasicLogger(false)
}
if config.MetricsProvider == nil {
config.MetricsProvider = &noopMetricsProvider{}
config.MetricsProvider = &NoopMetricsProvider{}
}
if config.MetricsUpdateInterval == 0 {
config.MetricsUpdateInterval = 15 * time.Second
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func init() {
config := &Config{
TopicProcessorName: "test",
Logger: &noopLogger{},
MetricsProvider: &noopMetricsProvider{},
MetricsProvider: &NoopMetricsProvider{},
}
url := fmt.Sprintf("http://%s:9200", getCIHost())
client, err := elastic.NewClient(
Expand Down
4 changes: 2 additions & 2 deletions multi_elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestMultiElasticsearch(t *testing.T) {
config := &Config{
TopicProcessorName: "test",
Logger: &noopLogger{},
MetricsProvider: &noopMetricsProvider{},
MetricsProvider: &NoopMetricsProvider{},
}
url := fmt.Sprintf("http://%s:9200", getCIHost())
client, err := elastic.NewClient(
Expand All @@ -38,7 +38,7 @@ func TestMultiElasticsearch_PutAll_GetAll(t *testing.T) {
config := &Config{
TopicProcessorName: "test",
Logger: &noopLogger{},
MetricsProvider: &noopMetricsProvider{},
MetricsProvider: &NoopMetricsProvider{},
}
url := fmt.Sprintf("http://%s:9200", getCIHost())
client, err := elastic.NewClient(
Expand Down
4 changes: 2 additions & 2 deletions multi_redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestMultiRedis(t *testing.T) {
config := &Config{
TopicProcessorName: "test",
Logger: &noopLogger{},
MetricsProvider: &noopMetricsProvider{},
MetricsProvider: &NoopMetricsProvider{},
}
url := fmt.Sprintf("redis://%s:6379", getCIHost())
conn, err := redis.DialURL(url)
Expand All @@ -27,7 +27,7 @@ func TestMultiRedis_PutAll_GetAll(t *testing.T) {
config := &Config{
TopicProcessorName: "test",
Logger: &noopLogger{},
MetricsProvider: &noopMetricsProvider{},
MetricsProvider: &NoopMetricsProvider{},
}
url := fmt.Sprintf("redis://%s:6379", getCIHost())
conn, err := redis.DialURL(url)
Expand Down
13 changes: 9 additions & 4 deletions noop_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ func (m *noopMetric) Add(value float64, labelValues ...string) {}

func (m *noopMetric) Observe(value float64, labelValues ...string) {}

type noopMetricsProvider struct{}
// NoopMetricsProvider is a dummy implementation of MetricsProvider that does nothing.
// Useful for testing, not recommended in production.
type NoopMetricsProvider struct{}

func (m *noopMetricsProvider) NewCounter(name string, help string, labelNames ...string) Counter {
// NewCounter creates a new no-op Counter
func (m *NoopMetricsProvider) NewCounter(name string, help string, labelNames ...string) Counter {
return &noopMetric{len(labelNames)}
}

func (m *noopMetricsProvider) NewGauge(name string, help string, labelNames ...string) Gauge {
// NewGauge creates a new no-op Gauge
func (m *NoopMetricsProvider) NewGauge(name string, help string, labelNames ...string) Gauge {
return &noopMetric{len(labelNames)}
}

func (m *noopMetricsProvider) NewSummary(name string, help string, labelNames ...string) Summary {
// NewSummary creates a new no-op Summary
func (m *NoopMetricsProvider) NewSummary(name string, help string, labelNames ...string) Summary {
return &noopMetric{len(labelNames)}
}
2 changes: 1 addition & 1 deletion redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func init() {
config := &Config{
TopicProcessorName: "test",
Logger: &noopLogger{},
MetricsProvider: &noopMetricsProvider{},
MetricsProvider: &NoopMetricsProvider{},
}
url := fmt.Sprintf("redis://%s:6379", getCIHost())
conn, err := redis.DialURL(url)
Expand Down

0 comments on commit 7cc9efe

Please sign in to comment.