Skip to content

Commit

Permalink
Merge branch 'afex-contrib' of github.com:vermapratyush/hystrix-go in…
Browse files Browse the repository at this point in the history
…to afex-contrib
  • Loading branch information
vermapratyush committed Oct 17, 2017
2 parents 5c09bc7 + fa3c586 commit 94ffb27
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
25 changes: 0 additions & 25 deletions hystrix/hystrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sync/atomic"

. "github.com/smartystreets/goconvey/convey"
"testing/quick"
)

func TestSuccess(t *testing.T) {
Expand Down Expand Up @@ -342,30 +341,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()
Expand Down
1 change: 1 addition & 0 deletions hystrix/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
8 changes: 8 additions & 0 deletions plugins/graphite_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions plugins/statsd_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type StatsdCollector struct {
client statsd.Statter
circuitOpenPrefix string
attemptsPrefix string
queueSizePrefix string
errorsPrefix string
successesPrefix string
failuresPrefix string
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 94ffb27

Please sign in to comment.