Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Pillitteri <[email protected]>
  • Loading branch information
56quarters committed Apr 22, 2024
1 parent 68b7fce commit 233bc0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 7 additions & 8 deletions internal/component/mimir/rules/kubernetes/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rules

import (
"context"
"errors"
"fmt"
"regexp"
"sync"
Expand Down Expand Up @@ -68,20 +67,20 @@ func (e *eventProcessor) run(ctx context.Context) {
err := e.processEvent(ctx, evt)

if err != nil {
retries := c.queue.NumRequeues(evt)
if retries < 5 && !errors.Is(err, client.ErrUnrecoverable) {
c.metrics.eventsRetried.WithLabelValues(string(evt.Typ)).Inc()
c.queue.AddRateLimited(evt)
level.Error(c.log).Log(
retries := e.queue.NumRequeues(evt)
if retries < 5 && !client.IsUnrecoverable(err) {
e.metrics.eventsRetried.WithLabelValues(string(evt.Typ)).Inc()
e.queue.AddRateLimited(evt)
level.Error(e.logger).Log(

"msg", "failed to process event, will retry",
"retries", fmt.Sprintf("%d/5", retries),
"err", err,
)
continue
} else {
c.metrics.eventsFailed.WithLabelValues(string(evt.Typ)).Inc()
level.Error(c.log).Log(
e.metrics.eventsFailed.WithLabelValues(string(evt.Typ)).Inc()
level.Error(e.logger).Log(
"msg", "failed to process event, unrecoverable error or max retries exceeded",
"retries", fmt.Sprintf("%d/5", retries),
"err", err,
Expand Down
5 changes: 5 additions & 0 deletions internal/mimir/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var (
ErrUnrecoverable = errors.New("unrecoverable error response")
)

// IsUnrecoverable returns true for errors from API requests that should not be retried, false otherwise.
func IsUnrecoverable(err error) bool {
return errors.Is(err, ErrUnrecoverable)
}

// Config is used to configure a MimirClient.
type Config struct {
ID string
Expand Down
3 changes: 1 addition & 2 deletions internal/mimir/client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"errors"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -178,7 +177,7 @@ func TestCheckResponseErrors(t *testing.T) {

err := checkResponse(response)
require.Error(t, err)
require.Equal(t, tt.fatal, errors.Is(err, ErrUnrecoverable), "%+v is not expected recoverable/unrecoverable", err)
require.Equal(t, tt.fatal, IsUnrecoverable(err), "%+v is not expected recoverable/unrecoverable", err)
})
}
}

0 comments on commit 233bc0f

Please sign in to comment.