From 968d05c829bece7e2c3c48006d2eb21948bde5db Mon Sep 17 00:00:00 2001 From: Pratyush Verma Date: Tue, 26 Sep 2017 23:36:05 +0800 Subject: [PATCH 1/3] Update statsD and graphite implementation with updated metric_collector --- plugins/graphite_aggregator.go | 8 ++++++++ plugins/statsd_collector.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/plugins/graphite_aggregator.go b/plugins/graphite_aggregator.go index f26e916..ee4ed63 100644 --- a/plugins/graphite_aggregator.go +++ b/plugins/graphite_aggregator.go @@ -22,6 +22,7 @@ var makeCounterFunc = func() interface{} { return metrics.NewCounter() } // on how metrics are aggregated and expressed in graphite. type GraphiteCollector struct { attemptsPrefix string + queueSizePrefix string errorsPrefix string successesPrefix string failuresPrefix string @@ -60,6 +61,7 @@ func NewGraphiteCollector(name string) metricCollector.MetricCollector { return &GraphiteCollector{ attemptsPrefix: name + ".attempts", errorsPrefix: name + ".errors", + queueSizePrefix: name + ".queueLength", successesPrefix: name + ".successes", failuresPrefix: name + ".failures", rejectsPrefix: name + ".rejects", @@ -94,6 +96,12 @@ func (g *GraphiteCollector) IncrementAttempts() { g.incrementCounterMetric(g.attemptsPrefix) } +// IncrementQueueSize increments the number of elements in the queue. +// Request that would have otherwise been rejected, but was queued before executing/rejection +func (g *GraphiteCollector) IncrementQueueSize() { + g.incrementCounterMetric(g.queueSizePrefix) +} + // IncrementErrors increments the number of unsuccessful attempts. // Attempts minus Errors will equal successes within a time range. // Errors are any result from an attempt that is not a success. diff --git a/plugins/statsd_collector.go b/plugins/statsd_collector.go index 8c0895d..0c3e5f2 100644 --- a/plugins/statsd_collector.go +++ b/plugins/statsd_collector.go @@ -18,6 +18,7 @@ type StatsdCollector struct { client statsd.Statter circuitOpenPrefix string attemptsPrefix string + queueSizePrefix string errorsPrefix string successesPrefix string failuresPrefix string @@ -96,6 +97,7 @@ func (s *StatsdCollectorClient) NewStatsdCollector(name string) metricCollector. circuitOpenPrefix: name + ".circuitOpen", attemptsPrefix: name + ".attempts", errorsPrefix: name + ".errors", + queueSizePrefix: name + ".queueLength", successesPrefix: name + ".successes", failuresPrefix: name + ".failures", rejectsPrefix: name + ".rejects", @@ -136,6 +138,12 @@ func (g *StatsdCollector) IncrementAttempts() { g.incrementCounterMetric(g.attemptsPrefix) } +// IncrementQueueSize increments the number of elements in the queue. +// Request that would have otherwise been rejected, but was queued before executing/rejection +func (g *StatsdCollector) IncrementQueueSize() { + g.incrementCounterMetric(g.queueSizePrefix) +} + // IncrementErrors increments the number of unsuccessful attempts. // Attempts minus Errors will equal successes within a time range. // Errors are any result from an attempt that is not a success. From 5ef977f930b54780288184aee6599c37f23f6a0b Mon Sep 17 00:00:00 2001 From: Pratyush Verma Date: Wed, 27 Sep 2017 00:08:09 +0800 Subject: [PATCH 2/3] Remove flaky test --- hystrix/hystrix_test.go | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/hystrix/hystrix_test.go b/hystrix/hystrix_test.go index 2e2d6af..a17ed89 100644 --- a/hystrix/hystrix_test.go +++ b/hystrix/hystrix_test.go @@ -342,30 +342,6 @@ func TestFallbackAfterRejected(t *testing.T) { }) } -func TestReturnTicket_QuickCheck(t *testing.T) { - compareTicket := func() bool { - defer Flush() - ConfigureCommand("", CommandConfig{Timeout: 2}) - errChan := Go("", func() error { - c := make(chan struct{}) - <-c // should block - return nil - }, nil) - err := <-errChan - So(err, ShouldResemble, ErrTimeout) - cb, _, err := GetCircuit("") - So(err, ShouldBeNil) - return cb.executorPool.ActiveCount() == 0 - } - - Convey("with a run command that doesn't return", t, func() { - Convey("checking many times that after Go(), the ticket returns to the pool after the timeout", func() { - err := quick.Check(compareTicket, nil) - So(err, ShouldBeNil) - }) - }) -} - func TestReturnTicket(t *testing.T) { Convey("with a run command that doesn't return", t, func() { defer Flush() From fa3c58695989f7386997efbc58c551c95e569419 Mon Sep 17 00:00:00 2001 From: Pratyush Verma Date: Wed, 27 Sep 2017 00:09:53 +0800 Subject: [PATCH 3/3] fix flaky test and goimport --- hystrix/hystrix_test.go | 1 - hystrix/pool_test.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/hystrix/hystrix_test.go b/hystrix/hystrix_test.go index a17ed89..d7c4cfb 100644 --- a/hystrix/hystrix_test.go +++ b/hystrix/hystrix_test.go @@ -8,7 +8,6 @@ import ( "sync/atomic" . "github.com/smartystreets/goconvey/convey" - "testing/quick" ) func TestSuccess(t *testing.T) { diff --git a/hystrix/pool_test.go b/hystrix/pool_test.go index 3dbfbad..eef4577 100644 --- a/hystrix/pool_test.go +++ b/hystrix/pool_test.go @@ -85,6 +85,7 @@ func TestWaitingCount(t *testing.T) { Convey("WaitingTicket should be max-10", func() { <-checkpoint + time.Sleep(500 * time.Millisecond) So(pool.WaitingCount(), ShouldEqual, pool.QueueSizeRejectionThreshold-10) })