diff --git a/command.go b/command.go index f8c347c..a188b87 100644 --- a/command.go +++ b/command.go @@ -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 @@ -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: diff --git a/command_test.go b/command_test.go index 49ffc79..92e6166 100644 --- a/command_test.go +++ b/command_test.go @@ -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)) }