Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandr Samylkin authored and anuptalwalkar committed Mar 7, 2017
1 parent e8a08b0 commit d303ea8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 43 deletions.
50 changes: 24 additions & 26 deletions metrics/nop_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func (c *capabilities) Tagging() bool {
return c.tagging
}

// NopCachedStatsReporter is an implementatin of tally.CachedStatsReporter than simply does nothing.
// NopCachedStatsReporter is an implementation of tally.CachedStatsReporter that simply does nothing
// and should be used for testing purposes only.
// TODO:(anup) This should exist in tally. https://github.com/uber-go/tally/issues/23
// Remove and replace metrics.NopCachedStatsReporter with tally.NopCachedStatsRepor once issue is resolved
// Remove and replace metrics.NopCachedStatsReporter with tally.NopCachedStatsReporter once issue is resolved
var NopCachedStatsReporter tally.CachedStatsReporter = nopCachedStatsReporter{}

type nopCachedStatsReporter struct {
}
type nopCachedStatsReporter struct{}

func (nopCachedStatsReporter) AllocateCounter(name string, tags map[string]string) tally.CachedCount {
return NopCachedCount
Expand All @@ -74,10 +74,10 @@ func (r nopCachedStatsReporter) Capabilities() tally.Capabilities {
return capabilitiesReportingNoTagging
}

func (r nopCachedStatsReporter) Flush() {
}
func (r nopCachedStatsReporter) Flush() {}

// NopCachedCount is an implementation of tally.CachedCount
// NopCachedCount is an implementation of tally.CachedCount and same as other Nop types don't do anything and
// should be used for testing purposes only.
var NopCachedCount tally.CachedCount = nopCachedCount{}

type nopCachedCount struct {
Expand All @@ -86,47 +86,45 @@ type nopCachedCount struct {
func (nopCachedCount) ReportCount(value int64) {
}

// NopCachedGauge is an implementation of tally.CachedGauge
// NopCachedGauge is an implementation of tally.CachedGauge and same as other Nop types don't do anything and
// should be used for testing purposes only.
var NopCachedGauge tally.CachedGauge = nopCachedGauge{}

type nopCachedGauge struct {
}
type nopCachedGauge struct{}

func (nopCachedGauge) ReportGauge(value float64) {
}
func (nopCachedGauge) ReportGauge(value float64) {}

// NopCachedTimer is an implementation of tally.CachedTimer
var NopCachedTimer tally.CachedTimer = nopCachedTimer{}

type nopCachedTimer struct {
}
type nopCachedTimer struct{}

func (nopCachedTimer) ReportTimer(interval time.Duration) {
}
func (nopCachedTimer) ReportTimer(interval time.Duration) {}

// NopCachedHistogram is an implementation of tally.CachedHistogram
// NopCachedHistogram is an implementation of tally.CachedHistogram and same as other Nop types don't do anything and
// should be used for testing purposes only.
var NopCachedHistogram tally.CachedHistogram = nopCachedHistogram{}

type nopCachedHistogram struct {
}
type nopCachedHistogram struct{}

func (nopCachedHistogram) ValueBucket(
bucketLowerBound, bucketUpperBound float64,
bucketLowerBound float64,
bucketUpperBound float64,
) tally.CachedHistogramBucket {
return nopCachedHistogramBucket{}
}

func (nopCachedHistogram) DurationBucket(
bucketLowerBound, bucketUpperBound time.Duration,
bucketLowerBound time.Duration,
bucketUpperBound time.Duration,
) tally.CachedHistogramBucket {
return nopCachedHistogramBucket{}
}

// NopCachedHistogramBucket is an implementation of tally.CachedHistogramBucket
// NopCachedHistogramBucket is an implementation of tally.CachedHistogramBucket and same as other Nop types
// don't do anything and should be used for testing purposes only.
var NopCachedHistogramBucket tally.CachedHistogramBucket = nopCachedHistogramBucket{}

type nopCachedHistogramBucket struct {
}
type nopCachedHistogramBucket struct{}

func (nopCachedHistogramBucket) ReportSamples(value int64) {
}
func (nopCachedHistogramBucket) ReportSamples(value int64) {}
11 changes: 2 additions & 9 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,17 @@ import (

"go.uber.org/fx/config"
"go.uber.org/fx/testutils/metrics"
"go.uber.org/zap"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/uber-go/tally"
"go.uber.org/zap"
)

func TestServiceCreation(t *testing.T) {
r := metrics.NewTestStatsReporter()
r.CountersWG.Add(1)
opts := tally.ScopeOptions{
Tags: nil,
Prefix: "",
Reporter: r,
CachedReporter: nil,
Separator: tally.DefaultSeparator,
DefaultBuckets: tally.DefaultBuckets,
}
opts := tally.ScopeOptions{Reporter: r}

scope, closer := tally.NewRootScope(opts, 50*time.Millisecond)
defer closer.Close()
Expand Down
9 changes: 1 addition & 8 deletions testutils/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,7 @@ func NewTestStatsReporter() *TestStatsReporter {
// NewTestScope returns a pair of scope and reporter that can be used for testing
func NewTestScope() (tally.Scope, *TestStatsReporter) {
r := NewTestStatsReporter()
opts := tally.ScopeOptions{
Tags: nil,
Prefix: "",
Reporter: r,
CachedReporter: nil,
Separator: tally.DefaultSeparator,
DefaultBuckets: tally.DefaultBuckets,
}
opts := tally.ScopeOptions{Reporter: r}

scope, _ := tally.NewRootScope(opts, 100*time.Millisecond)
return scope, r
Expand Down

0 comments on commit d303ea8

Please sign in to comment.