Skip to content

Commit 38c38ce

Browse files
Vasilii Iakliushine_forbes
authored andcommitted
Merge branch 'ef-migrate-gitlab-sshd-to-labkit-v2-test-logs' into 'main'
Safer option - Litmus testing v2 log package in production See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/1348 Merged-by: Vasilii Iakliushin <viakliushin@gitlab.com> Approved-by: Alejandro Rodríguez <alejandro@gitlab.com> Approved-by: Vasilii Iakliushin <viakliushin@gitlab.com> Reviewed-by: Vasilii Iakliushin <viakliushin@gitlab.com> Reviewed-by: GitLab Duo <gitlab-duo@gitlab.com> Co-authored-by: e_forbes <eforbes@gitlab.com>
2 parents 494c2b3 + c2cadab commit 38c38ce

5 files changed

Lines changed: 45 additions & 12 deletions

File tree

cmd/gitlab-sshd/acceptance_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ var (
5252

5353
const (
5454
testRepo = "test-gitlab-shell/gitlab-test.git"
55-
testRepoNamespace = "test-gitlab-shell"
5655
testRepoImportURL = "https://gitlab.com/gitlab-org/gitlab-test.git"
5756
)
5857

cmd/gitlab-sshd/main.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package main
44
import (
55
"context"
66
"flag"
7+
"fmt"
8+
"log/slog"
79
"os"
810
"os/signal"
911
"syscall"
@@ -14,8 +16,10 @@ import (
1416
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/logger"
1517
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/sshd"
1618

19+
"gitlab.com/gitlab-org/labkit/fields"
1720
"gitlab.com/gitlab-org/labkit/log"
1821
"gitlab.com/gitlab-org/labkit/monitoring"
22+
v2log "gitlab.com/gitlab-org/labkit/v2/log"
1923
)
2024

2125
var (
@@ -43,6 +47,9 @@ func overrideConfigFromEnvironment(cfg *config.Config) {
4347
}
4448

4549
func main() {
50+
ctx := context.Background()
51+
v2Logger := v2log.New()
52+
v2Logger.InfoContext(ctx, "v2log: gitlab-sshd starting up...")
4653
command.CheckForVersionFlag(os.Args, Version, BuildTime)
4754

4855
flag.Parse()
@@ -52,15 +59,23 @@ func main() {
5259
var err error
5360
cfg, err = config.NewFromDir(*configDir)
5461
if err != nil {
62+
v2Logger.ErrorContext(ctx, "v2log: failed to load configuration from specified directory", slog.String(
63+
fields.ErrorMessage, err.Error(),
64+
))
5565
log.WithError(err).Fatal("failed to load configuration from specified directory")
5666
}
5767
}
5868

5969
overrideConfigFromEnvironment(cfg)
6070
if err := cfg.IsSane(); err != nil {
71+
ctx = v2log.WithFields(ctx,
72+
slog.String(fields.ErrorMessage, err.Error()),
73+
)
6174
if *configDir == "" {
75+
v2Logger.ErrorContext(ctx, "v2log: no config-dir provided, using only environment variables")
6276
log.WithError(err).Fatal("no config-dir provided, using only environment variables")
6377
} else {
78+
v2Logger.ErrorContext(ctx, "v2log: configuration error")
6479
log.WithError(err).Fatal("configuration error")
6580
}
6681
}
@@ -70,6 +85,9 @@ func main() {
7085
logCloser := logger.ConfigureStandalone(cfg)
7186
defer func() {
7287
if err := logCloser.Close(); err != nil {
88+
v2Logger.ErrorContext(ctx, "v2log: Error closing logCloser", slog.String(
89+
fields.ErrorMessage, err.Error(),
90+
))
7391
log.WithError(err).Fatal("Error closing logCloser")
7492
}
7593
}()
@@ -80,6 +98,9 @@ func main() {
8098

8199
server, err := sshd.NewServer(cfg)
82100
if err != nil {
101+
v2Logger.ErrorContext(ctx, "v2log: Failed to start Gitlab built-in sshd", slog.String(
102+
fields.ErrorMessage, err.Error(),
103+
))
83104
log.WithError(err).Fatal("Failed to start GitLab built-in sshd")
84105
}
85106

@@ -94,25 +115,37 @@ func main() {
94115
done := make(chan os.Signal, 1)
95116
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
96117

97-
gracefulShutdown(ctx, done, cfg, server, cancel)
118+
gracefulShutdown(ctx, done, cfg, server, cancel, v2Logger)
98119

99120
if err := server.ListenAndServe(ctx); err != nil {
121+
v2Logger.ErrorContext(ctx, "v2log: GitLab built-in sshd failed to listen for new connections",
122+
slog.String(fields.ErrorMessage, err.Error()))
100123
log.WithError(err).Fatal("GitLab built-in sshd failed to listen for new connections")
101124
}
102125
}
103126

104-
func gracefulShutdown(ctx context.Context, done chan os.Signal, cfg *config.Config, server *sshd.Server, cancel context.CancelFunc) {
127+
func gracefulShutdown(
128+
ctx context.Context,
129+
done chan os.Signal,
130+
cfg *config.Config,
131+
server *sshd.Server,
132+
cancel context.CancelFunc,
133+
v2Logger *slog.Logger,
134+
) {
105135
go func() {
106136
sig := <-done
107137
signal.Reset(syscall.SIGINT, syscall.SIGTERM)
108138

109139
gracePeriod := time.Duration(cfg.Server.GracePeriod)
110140
log.WithContextFields(ctx, log.Fields{"shutdown_timeout_s": gracePeriod.Seconds(), "signal": sig.String()}).Info("Shutdown initiated")
141+
v2Logger.InfoContext(ctx, fmt.Sprintf("v2log: Shutdown initiated with grace period: %f", gracePeriod.Seconds()),
142+
slog.String("signal", sig.String()))
111143

112144
if err := server.Shutdown(); err != nil {
145+
v2Logger.ErrorContext(ctx, "v2log: Error shutting down the server", slog.String(
146+
fields.ErrorMessage, err.Error()))
113147
log.WithError(err).Fatal("Error shutting down the server")
114148
}
115-
116149
<-time.After(gracePeriod)
117150

118151
cancel()

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
// Please do not override. Once v16.11.1 is released, this comment
2424
// can be removed.
2525
gitlab.com/gitlab-org/gitaly/v16 v16.11.0-rc1.0.20250408053233-c6d43513e93c
26-
gitlab.com/gitlab-org/labkit v1.27.1
26+
gitlab.com/gitlab-org/labkit v1.35.0
2727
golang.org/x/crypto v0.41.0
2828
golang.org/x/sync v0.16.0
2929
google.golang.org/grpc v1.72.0
@@ -65,7 +65,7 @@ require (
6565
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
6666
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
6767
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
68-
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.1 // indirect
68+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 // indirect
6969
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
7070
github.com/hashicorp/yamux v0.1.2-0.20220728231024-8f49b6f63f18 // indirect
7171
github.com/jmespath/go-jmespath v0.4.0 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
cel.dev/expr v0.20.0 h1:OunBvVCfvpWlt4dN7zg3FM6TDkzOePe1+foGJ9AXeeI=
2-
cel.dev/expr v0.20.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
1+
cel.dev/expr v0.23.1 h1:K4KOtPCJQjVggkARsjG9RWXP6O4R73aHeJMa/dmCQQg=
2+
cel.dev/expr v0.23.1/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
33
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
44
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
55
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
@@ -348,8 +348,8 @@ github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDP
348348
github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A=
349349
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
350350
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
351-
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.1 h1:KcFzXwzM/kGhIRHvc8jdixfIJjVzuUJdnv+5xsPutog=
352-
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.1/go.mod h1:qOchhhIlmRcqk/O9uCo/puJlyo07YINaIqdZfZG3Jkc=
351+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 h1:sGm2vDRFUrQJO/Veii4h4zG2vvqG6uWNkBHSTqXOZk0=
352+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2/go.mod h1:wd1YpapPLivG6nQgbf7ZkG1hhSOXDhhn4MLTknx2aAc=
353353
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
354354
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
355355
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
@@ -554,8 +554,8 @@ gitlab.com/gitlab-org/gitaly/v16 v16.11.0-rc1.0.20250408053233-c6d43513e93c h1:x
554554
gitlab.com/gitlab-org/gitaly/v16 v16.11.0-rc1.0.20250408053233-c6d43513e93c/go.mod h1:/rkj6992VsNymUeG6N3VnLZ8Pvb1Y9ZUo00Yy35t8WQ=
555555
gitlab.com/gitlab-org/go/reopen v1.0.0 h1:6BujZ0lkkjGIejTUJdNO1w56mN1SI10qcVQyQlOPM+8=
556556
gitlab.com/gitlab-org/go/reopen v1.0.0/go.mod h1:D6OID8YJDzEVZNYW02R/Pkj0v8gYFSIhXFTArAsBQw8=
557-
gitlab.com/gitlab-org/labkit v1.27.1 h1:c4gL4qfHPMZwetbFZO5HDam98MOS1Ul/CC8QTPon5/c=
558-
gitlab.com/gitlab-org/labkit v1.27.1/go.mod h1:ZHOQIOVQKeOEKvQ/GhGBjUNbV3zWsx8nty6D/SRCyd4=
557+
gitlab.com/gitlab-org/labkit v1.35.0 h1:6PSRUvmuEKFrAZpQPLlMNIdbtZHyKHaqyRlM4PDYDbs=
558+
gitlab.com/gitlab-org/labkit v1.35.0/go.mod h1:JqQLdgjV/KKAZJ6gvNodaLStmWeTT9mxgJPIEi66VHI=
559559
go.etcd.io/raft/v3 v3.6.0 h1:5NtvbDVYpnfZWcIHgGRk9DyzkBIXOi8j+DDp1IcnUWQ=
560560
go.etcd.io/raft/v3 v3.6.0/go.mod h1:nLvLevg6+xrVtHUmVaTcTz603gQPHfh7kUAwV6YpfGo=
561561
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cmd/gitlab-sshd/main.go:49:6: Function 'main' has too many statements (41 > 40) (funlen)

0 commit comments

Comments
 (0)