Skip to content

Commit

Permalink
Fix contextual logging in index client pool
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Feb 24, 2024
1 parent 1134e37 commit 4f3af4c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/fpindex/client_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
pb "github.com/acoustid/go-acoustid/proto/index"

pool "github.com/jolestar/go-commons-pool"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog"
)

type IndexClientFactory struct {
Expand Down Expand Up @@ -83,16 +83,18 @@ func (p *IndexClientPool) Close(ctx context.Context) {
}

func (p *IndexClientPool) Search(ctx context.Context, in *pb.SearchRequest) (*pb.SearchResponse, error) {
logger := zerolog.Ctx(ctx)

obj, err := p.Pool.BorrowObject(ctx)
if err != nil {
log.Error().Err(err).Msg("failed to borrow index client from the pool")
logger.Error().Err(err).Msg("failed to borrow index client from the pool")
return nil, err
}

defer func() {
err := p.Pool.ReturnObject(ctx, obj)
if err != nil {
log.Error().Err(err).Msg("failed to return index client from the pool")
logger.Error().Err(err).Msg("failed to return index client from the pool")
}
}()

Expand All @@ -101,16 +103,18 @@ func (p *IndexClientPool) Search(ctx context.Context, in *pb.SearchRequest) (*pb
}

func (p *IndexClientPool) Insert(ctx context.Context, in *pb.InsertRequest) (*pb.InsertResponse, error) {
logger := zerolog.Ctx(ctx)

obj, err := p.Pool.BorrowObject(ctx)
if err != nil {
log.Error().Err(err).Msg("failed to borrow index client from the pool")
logger.Error().Err(err).Msg("failed to borrow index client from the pool")
return nil, err
}

defer func() {
err := p.Pool.ReturnObject(ctx, obj)
if err != nil {
log.Error().Err(err).Msg("failed to return index client from the pool")
logger.Error().Err(err).Msg("failed to return index client from the pool")
}
}()

Expand Down

0 comments on commit 4f3af4c

Please sign in to comment.