Skip to content

Commit

Permalink
Replace remaining logrus uses
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Feb 12, 2024
1 parent 9ad0e3d commit 19a55e1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 42 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/prometheus/client_golang v1.11.1
github.com/redis/go-redis/v9 v9.4.0
github.com/rs/zerolog v1.32.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.3
github.com/urfave/cli/v2 v2.27.1
go4.org v0.0.0-20190919214946-0cfe6e5be80f
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,11 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
Expand Down Expand Up @@ -171,7 +168,6 @@ golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -209,6 +205,5 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 0 additions & 2 deletions pkg/chromaprint/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/acoustid/go-acoustid/util"
"github.com/acoustid/go-acoustid/util/signal"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -286,7 +285,6 @@ func matchAlignedFingerprints(master *common_pb.Fingerprint, query *common_pb.Fi
matches = append(matches, m)
}
}
log.Println(matches)

return matches, nil
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/index/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"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
)

type IndexClientFactory struct {
Expand Down Expand Up @@ -78,14 +78,14 @@ func (p *IndexClientPool) Close(ctx context.Context) {
func (p *IndexClientPool) Search(ctx context.Context, in *pb.SearchRequest) (*pb.SearchResponse, error) {
obj, err := p.Pool.BorrowObject(ctx)
if err != nil {
log.Errorf("failed to borrow index client from the pool: %v", err)
log.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.Errorf("failed to return index client to the pool: %v", err)
log.Error().Err(err).Msg("failed to return index client from the pool")
}
}()

Expand All @@ -96,14 +96,14 @@ func (p *IndexClientPool) Search(ctx context.Context, in *pb.SearchRequest) (*pb
func (p *IndexClientPool) Insert(ctx context.Context, in *pb.InsertRequest) (*pb.InsertResponse, error) {
obj, err := p.Pool.BorrowObject(ctx)
if err != nil {
log.Errorf("failed to borrow index client from the pool: %v", err)
log.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.Errorf("failed to return index client to the pool: %v", err)
log.Error().Err(err).Msg("failed to return index client from the pool")
}
}()

Expand Down
11 changes: 3 additions & 8 deletions pkg/index/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

pb "github.com/acoustid/go-acoustid/proto/index"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
grpc "google.golang.org/grpc"
)
Expand Down Expand Up @@ -51,12 +51,6 @@ func (p *Proxy) Insert(ctx context.Context, in *pb.InsertRequest) (*pb.InsertRes
}

func RunProxy(cfg *ProxyConfig) {
if cfg.Debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}

pool := NewIndexClientPool(cfg.Index, 32)
defer pool.Close(context.Background())

Expand All @@ -65,7 +59,8 @@ func RunProxy(cfg *ProxyConfig) {
addr := net.JoinHostPort(cfg.ListenHost, strconv.Itoa(cfg.ListenPort))
lis, err := net.Listen("tcp", addr)
if err != nil {
log.Fatalf("failed to listen: %v", err)
log.Fatal().Err(err).Msg("failed to listen")
return
}

grpcServer := grpc.NewServer()
Expand Down
32 changes: 11 additions & 21 deletions pkg/index/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
pb "github.com/acoustid/go-acoustid/proto/index"

_ "github.com/lib/pq"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
)

const UpdateBatchSize = 10000
Expand All @@ -29,22 +29,16 @@ func NewUpdaterConfig() *UpdaterConfig {
}

func RunUpdater(cfg *UpdaterConfig) {
if cfg.Debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}

db, err := sql.Open("postgres", cfg.Database.URL().String())
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
log.Fatal().Err(err).Msg("Failed to connect to database")
return
}
defer db.Close()

err = db.Ping()
if err != nil {
log.Fatalf("Can't ping the database: %v", err)
log.Fatal().Err(err).Msg("Can't ping the database")
return
}

Expand All @@ -63,21 +57,21 @@ func RunUpdater(cfg *UpdaterConfig) {
if delay > MaxDelay {
delay = MaxDelay
}
log.Debugf("Sleeping for %v", delay)
log.Debug().Msgf("Sleeping for %v", delay)
time.Sleep(delay)
}

if idx == nil {
idx, err = ConnectWithConfig(context.Background(), cfg.Index)
if err != nil {
log.Fatalf("Failed to connect to index: %s", err)
log.Fatal().Err(err).Msg("Failed to connect to index")
delay = MaxDelay
continue
}
}

if !idx.IsOK() {
log.Infof("Index connection failed, reconnecting...")
log.Info().Msg("Index connection failed, reconnecting...")
idx.Close(context.Background())
idx = nil
delay = MaxDelay
Expand All @@ -89,31 +83,31 @@ func RunUpdater(cfg *UpdaterConfig) {

lastID, err := GetLastFingerprintID(ctx, idx)
if err != nil {
log.Errorf("Failed to get the last fingerprint ID in index: %s", err)
log.Error().Err(err).Msg("Failed to get the last fingerprint ID in index")
delay = MaxDelay
continue
}

fingerprints, err := fpDB.GetNextFingerprints(ctx, lastID, true, UpdateBatchSize)
if err != nil {
log.Errorf("Failed to get the next fingerprints to import: %s", err)
log.Error().Err(err).Msg("Failed to get the next fingerprints to import")
delay = MaxDelay
continue
}

_, err = idx.Insert(ctx, &pb.InsertRequest{Fingerprints: fingerprints})
if err != nil {
log.Errorf("Failed to import the fingerprints: %s", err)
log.Error().Err(err).Msg("Failed to import the fingerprints")
delay = MaxDelay
continue
}

fingerprintCount := len(fingerprints)
if fingerprintCount > 0 {
lastID = fingerprints[fingerprintCount-1].Id
log.Infof("Added %d fingerprints up to ID %d", fingerprintCount, lastID)
log.Info().Msgf("Added %d fingerprints up to ID %d", fingerprintCount, lastID)
} else {
log.Debugf("Added %d fingerprints up to ID %d", fingerprintCount, lastID)
log.Debug().Msgf("Added %d fingerprints up to ID %d", fingerprintCount, lastID)
}

if fingerprintCount == 0 {
Expand All @@ -126,8 +120,4 @@ func RunUpdater(cfg *UpdaterConfig) {
delay = NoDelay
}
}

if idx != nil {
idx.Close(context.Background())
}
}

0 comments on commit 19a55e1

Please sign in to comment.