Skip to content

Commit

Permalink
fix(postgres-leader): add proper error logging in postgres leader ele…
Browse files Browse the repository at this point in the history
…ctor (#12484)

## Motivation

We saw this error without any information: 
<img width="421" alt="image"
src="https://github.com/user-attachments/assets/c9bf06f4-e94f-4322-9baa-fba0b5f56933"
/>
I've added proper error logging in postgres leader elector to see more
details, and to skip the context cancelled error

<!--
> Changelog: skip
-->
<!--
Uncomment the above section to explicitly set a [`> Changelog:` entry
here](https://github.com/kumahq/kuma/blob/master/CONTRIBUTING.md#submitting-a-patch)?
-->

---------

Signed-off-by: Marcin Skalski <[email protected]>
  • Loading branch information
Automaat authored Jan 9, 2025
1 parent 3227b8c commit 763690a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/plugins/leader/postgres/leader_elector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"cirello.io/pglock"
"github.com/pkg/errors"

"github.com/kumahq/kuma/pkg/core"
"github.com/kumahq/kuma/pkg/core/runtime/component"
Expand Down Expand Up @@ -111,7 +112,16 @@ func (p *postgresLeaderElector) IsLeader() bool {
type KumaPqLockLogger struct{}

func (k *KumaPqLockLogger) Error(msg string, args ...interface{}) {
log.Error(nil, fmt.Sprintf(msg, args...))
if len(args) > 0 {
err, ok := args[0].(error)
if ok {
if !errors.Is(err, context.Canceled) {
log.Error(err, fmt.Sprintf(msg, args...))
}
}
} else {
log.Error(nil, fmt.Sprintf(msg, args...))
}
}

func (k *KumaPqLockLogger) Debug(msg string, args ...interface{}) {
Expand Down

0 comments on commit 763690a

Please sign in to comment.