add ability to fail probes and fatal on broker errors
All checks were successful
test / test (push) Successful in 3m12s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2025-02-26 11:06:11 +03:00
parent cfecb4afd0
commit aaf8c43e04
8 changed files with 186 additions and 90 deletions

View File

@@ -1,15 +1,19 @@
package kgo
import (
"context"
"net"
"sync/atomic"
"time"
"github.com/twmb/franz-go/pkg/kgo"
"go.unistack.org/micro/v3/logger"
)
type hookEvent struct {
connected *atomic.Uint32
log logger.Logger
fatalOnError bool
connected *atomic.Uint32
}
var (
@@ -24,12 +28,18 @@ var (
func (m *hookEvent) OnGroupManageError(err error) {
if err != nil {
m.connected.Store(0)
if m.fatalOnError {
m.log.Fatal(context.TODO(), "kgo.OnGroupManageError", err)
}
}
}
func (m *hookEvent) OnBrokerConnect(_ kgo.BrokerMetadata, _ time.Duration, _ net.Conn, err error) {
if err != nil {
m.connected.Store(0)
if m.fatalOnError {
m.log.Fatal(context.TODO(), "kgo.OnBrokerConnect", err)
}
}
}
@@ -40,6 +50,9 @@ func (m *hookEvent) OnBrokerDisconnect(_ kgo.BrokerMetadata, _ net.Conn) {
func (m *hookEvent) OnBrokerWrite(_ kgo.BrokerMetadata, _ int16, _ int, _ time.Duration, _ time.Duration, err error) {
if err != nil {
m.connected.Store(0)
if m.fatalOnError {
m.log.Fatal(context.TODO(), "kgo.OnBrokerWrite", err)
}
}
}