Skip to content

Commit

Permalink
export func
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Jul 20, 2018
1 parent 72ec64c commit 24c644e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *command) errorWithFallback(ctx context.Context, err error) {

// collect prometheus metrics
elapsed := c.start.Sub(time.Now()).Seconds()
requests.WithLabelValues(c.name, errorToEvent(err)).Inc()
requests.WithLabelValues(c.name, ErrorToEvent(err)).Inc()
requestLatencyHistogram.WithLabelValues(c.name).Observe(elapsed)

// run returns nil means everything is ok
Expand All @@ -53,7 +53,8 @@ func (c *command) errorWithFallback(ctx context.Context, err error) {
requests.WithLabelValues(c.name, "fallback-success").Inc()
}

func errorToEvent(err error) string {
// ErrorToEvent converts error to event
func ErrorToEvent(err error) string {
event := "failure"
switch err {
case nil:
Expand Down
6 changes: 3 additions & 3 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestErrorToEvent(t *testing.T) {
assert.Equal(t, "too-many-requests", errorToEvent(gobreaker.ErrTooManyRequests))
assert.Equal(t, "circuit-open", errorToEvent(gobreaker.ErrOpenState))
assert.Equal(t, "success", errorToEvent(nil))
assert.Equal(t, "too-many-requests", ErrorToEvent(gobreaker.ErrTooManyRequests))
assert.Equal(t, "circuit-open", ErrorToEvent(gobreaker.ErrOpenState))
assert.Equal(t, "success", ErrorToEvent(nil))
}

0 comments on commit 24c644e

Please # to comment.