Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions internal/errorcounter/errorcounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@ func (c *Counter) Add(err error, labels ...string) int {
c.mu.Lock()
defer c.mu.Unlock()

errMsg := err.Error()
errMsg += strings.Join(labels, "-")
c.store[errMsg] += 1
return c.store[errMsg]
key := makeKey(labels)
c.store[key] += 1
return c.store[key]
}

func (c *Counter) Count(err error, labels ...string) int {
c.mu.Lock()
defer c.mu.Unlock()

errMsg := err.Error()
errMsg += strings.Join(labels, "-")
return c.store[errMsg]
key := makeKey(labels)
return c.store[key]
}

func (c *Counter) Clear(err error, labels ...string) {
c.mu.Lock()
defer c.mu.Unlock()

errMsg := err.Error()
errMsg += strings.Join(labels, "-")
c.store[errMsg] = 0
return
key := makeKey(labels)
delete(c.store, key)
}

// makeKey builds a stable key from labels only. The error message is excluded
// because it often contains dynamic data (timestamps, IDs) which would create
// unique keys and prevent the PauseAfterErrCount threshold from ever being reached.
func makeKey(labels []string) string {
return strings.Join(labels, "-")
}
Loading