Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2023-08-16 12:14:46 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-08-16 13:15:25 +0300
commit467f5048fd3b278a08166145f7c2bb61840a8ff1 (patch)
tree91d80b023bf1e4987e30a2fb090da51b74aea94a /internal/bootstrap
parent0e6776d8c8df7c4de521e90d89e7f9bce04f1697 (diff)
bootstrap: Inject properly configured logger
The boostrapping logic uses the global logrus logger to log data, which is discouraged. Convert the code to instead inject a logger so that we can use a properly configured one.
Diffstat (limited to 'internal/bootstrap')
-rw-r--r--internal/bootstrap/bootstrap.go20
-rw-r--r--internal/bootstrap/bootstrap_test.go6
2 files changed, 14 insertions, 12 deletions
diff --git a/internal/bootstrap/bootstrap.go b/internal/bootstrap/bootstrap.go
index 30113e13d..7c05511c0 100644
--- a/internal/bootstrap/bootstrap.go
+++ b/internal/bootstrap/bootstrap.go
@@ -9,7 +9,7 @@ import (
"github.com/cloudflare/tableflip"
"github.com/prometheus/client_golang/prometheus"
- log "github.com/sirupsen/logrus"
+ "github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/gitaly/v16/internal/helper"
"gitlab.com/gitlab-org/gitaly/v16/internal/helper/env"
"golang.org/x/sys/unix"
@@ -35,6 +35,7 @@ type Listener interface {
// Bootstrap handles graceful upgrades
type Bootstrap struct {
+ logger logrus.FieldLogger
upgrader upgrader
listenFunc ListenFunc
errChan chan error
@@ -76,7 +77,7 @@ type upgrader interface {
// freezes during a graceful shutdown
//
// gitaly-wrapper is supposed to set EnvUpgradesEnabled in order to enable graceful upgrades
-func New(totalConn *prometheus.CounterVec) (*Bootstrap, error) {
+func New(logger logrus.FieldLogger, totalConn *prometheus.CounterVec) (*Bootstrap, error) {
pidFile := os.Getenv(EnvPidFile)
upgradesEnabled, _ := env.GetBool(EnvUpgradesEnabled, false)
@@ -90,10 +91,10 @@ func New(totalConn *prometheus.CounterVec) (*Bootstrap, error) {
opErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
})
if err != nil {
- log.WithError(err).Warn(socketReusePortWarning)
+ logger.WithError(err).Warn(socketReusePortWarning)
}
if opErr != nil {
- log.WithError(opErr).Warn(socketReusePortWarning)
+ logger.WithError(opErr).Warn(socketReusePortWarning)
}
return nil
},
@@ -103,10 +104,10 @@ func New(totalConn *prometheus.CounterVec) (*Bootstrap, error) {
return nil, err
}
- return _new(upg, upg.Fds.Listen, upgradesEnabled, totalConn)
+ return _new(logger, upg, upg.Fds.Listen, upgradesEnabled, totalConn)
}
-func _new(upg upgrader, listenFunc ListenFunc, upgradesEnabled bool, totalConn *prometheus.CounterVec) (*Bootstrap, error) {
+func _new(logger logrus.FieldLogger, upg upgrader, listenFunc ListenFunc, upgradesEnabled bool, totalConn *prometheus.CounterVec) (*Bootstrap, error) {
if upgradesEnabled {
go func() {
sig := make(chan os.Signal, 1)
@@ -115,16 +116,17 @@ func _new(upg upgrader, listenFunc ListenFunc, upgradesEnabled bool, totalConn *
for range sig {
err := upg.Upgrade()
if err != nil {
- log.WithError(err).Error("Upgrade failed")
+ logger.WithError(err).Error("Upgrade failed")
continue
}
- log.Info("Upgrade succeeded")
+ logger.Info("Upgrade succeeded")
}
}()
}
return &Bootstrap{
+ logger: logger,
upgrader: upg,
listenFunc: listenFunc,
connTotal: totalConn,
@@ -194,7 +196,7 @@ func (b *Bootstrap) Wait(gracePeriodTicker helper.Ticker, stopAction func()) err
}
func (b *Bootstrap) waitGracePeriod(gracePeriodTicker helper.Ticker, kill <-chan os.Signal, stopAction func()) error {
- log.Warn("starting grace period")
+ b.logger.Warn("starting grace period")
allServersDone := make(chan struct{})
go func() {
diff --git a/internal/bootstrap/bootstrap_test.go b/internal/bootstrap/bootstrap_test.go
index adbf8468d..314a09b4f 100644
--- a/internal/bootstrap/bootstrap_test.go
+++ b/internal/bootstrap/bootstrap_test.go
@@ -74,7 +74,7 @@ func TestBootstrap_unixListener(t *testing.T) {
hasParent: tc.hasParent,
}
- b, err := _new(upgrader, listen, false, &prometheus.CounterVec{})
+ b, err := _new(testhelper.NewDiscardingLogEntry(t), upgrader, listen, false, &prometheus.CounterVec{})
require.NoError(t, err)
if tc.preexistingSocket {
@@ -219,7 +219,7 @@ func TestBootstrap_gracefulTermination(t *testing.T) {
}
func TestBootstrap_portReuse(t *testing.T) {
- b, err := New(&prometheus.CounterVec{})
+ b, err := New(testhelper.NewDiscardingLogEntry(t), &prometheus.CounterVec{})
require.NoError(t, err)
l, err := b.listen("tcp", "localhost:")
@@ -267,7 +267,7 @@ func setup(t *testing.T, ctx context.Context) (*Bootstrap, *mockUpgrader, mockLi
readyCh: make(chan error),
}
- b, err := _new(u, net.Listen, false, &prometheus.CounterVec{})
+ b, err := _new(testhelper.NewDiscardingLogEntry(t), u, net.Listen, false, &prometheus.CounterVec{})
require.NoError(t, err)
listeners := mockListeners{}