Skip to content

Commit

Permalink
chore: add debug logs to healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshay Kalbhor committed May 6, 2024
1 parent 7bf29b9 commit e6514f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/relay/source_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (sp *SourcePool) Close() {

// newConn initializes a new consumer group config.
func (sp *SourcePool) newConn(ctx context.Context, s Server) (*kgo.Client, error) {
sp.log.Debug("running TCP health check", "id", s.ID, "server", s.Config.BootstrapBrokers)
sp.log.Debug("running TCP health check", "id", s.ID, "server", s.Config.BootstrapBrokers, "session_timeout", s.Config.SessionTimeout)
if ok := checkTCP(ctx, s.Config.BootstrapBrokers, s.Config.SessionTimeout); !ok {
return nil, ErrorNoHealthy
}
Expand Down Expand Up @@ -297,12 +297,14 @@ func (sp *SourcePool) healthcheck(ctx context.Context, signal chan struct{}) err

// For the first ever check, clients will be nil.
if clients[i] == nil {
sp.log.Debug("initializing admin client for background check", "id", s.ID, "server", s.Config.BootstrapBrokers)
cl, err := sp.initConsumerClient(s.Config)
if err != nil {
sp.log.Error("error initializing admin client in background healthcheck", "id", s.ID, "server", s.Config.BootstrapBrokers, "error", err)
continue
}

sp.log.Debug("initialized admin client for background check", "id", s.ID, "server", s.Config.BootstrapBrokers)
clients[i] = cl
}

Expand All @@ -314,6 +316,7 @@ func (sp *SourcePool) healthcheck(ctx context.Context, signal chan struct{}) err

// Get the highest offset of all the topics on the source server and sum them up
// to derive the weight of the server.
sp.log.Debug("getting high watermark via admin client for background check", "id", idx)
offsets, err := sp.GetHighWatermark(ctx, clients[idx])
if err != nil && offsets == nil {
sp.log.Error("error fetching offset in background healthcheck", "id", s.ID, "server", s.Config.BootstrapBrokers, "error", err)
Expand Down Expand Up @@ -506,6 +509,7 @@ func (sp *SourcePool) setWeight(id int, weight int64) {
sp.curCandidate = s
}

sp.log.Debug("setting candidate weight", "id", id, "weight", weight, "curr", sp.curCandidate)
sp.servers[id] = s
break
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func main() {
// Initialize CLI flags.
initFlags(ko)

fmt.Println(buildString)
if ko.Bool("version") {
fmt.Println(buildString)
os.Exit(0)
}

Expand Down

0 comments on commit e6514f4

Please sign in to comment.