summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorIgor Drozdov <idrozdov@gitlab.com>2021-09-15 20:46:00 +0300
committerIgor Drozdov <idrozdov@gitlab.com>2021-09-15 20:46:08 +0300
commitaf3aac6b459791fabd8ebc306cdff47c609fbf53 (patch)
tree159c78d0b98126365dd3f3f08502e4c4a5110033 /internal
parent3f640bdafe429501897541cadf2c268b13c4cf9f (diff)
downloadgitlab-shell-af3aac6b459791fabd8ebc306cdff47c609fbf53.tar.gz
Add context fields to loggingid-context-fields
It adds correlation ids wherever possible
Diffstat (limited to 'internal')
-rw-r--r--internal/command/shared/customaction/customaction.go2
-rw-r--r--internal/handler/exec.go2
-rw-r--r--internal/sshd/connection.go2
-rw-r--r--internal/sshd/server_config.go4
-rw-r--r--internal/sshd/sshd.go14
5 files changed, 12 insertions, 12 deletions
diff --git a/internal/command/shared/customaction/customaction.go b/internal/command/shared/customaction/customaction.go
index 34086fb..73d2ce4 100644
--- a/internal/command/shared/customaction/customaction.go
+++ b/internal/command/shared/customaction/customaction.go
@@ -64,7 +64,7 @@ func (c *Command) processApiEndpoints(ctx context.Context, response *accessverif
"endpoint": endpoint,
}
- log.WithFields(fields).Info("Performing custom action")
+ log.WithContextFields(ctx, fields).Info("Performing custom action")
response, err := c.performRequest(ctx, client, endpoint, request)
if err != nil {
diff --git a/internal/handler/exec.go b/internal/handler/exec.go
index 27031b1..eb5211e 100644
--- a/internal/handler/exec.go
+++ b/internal/handler/exec.go
@@ -110,7 +110,7 @@ func getConn(ctx context.Context, gc *GitalyCommand) (*grpc.ClientConn, error) {
if serviceName == "" {
serviceName = "gitlab-shell-unknown"
- log.WithFields(log.Fields{"service_name": serviceName}).Warn("No gRPC service name specified, defaulting to gitlab-shell-unknown")
+ log.WithContextFields(ctx, log.Fields{"service_name": serviceName}).Warn("No gRPC service name specified, defaulting to gitlab-shell-unknown")
}
serviceName = fmt.Sprintf("%s-%s", serviceName, gc.ServiceName)
diff --git a/internal/sshd/connection.go b/internal/sshd/connection.go
index 0e0da93..1d91a6c 100644
--- a/internal/sshd/connection.go
+++ b/internal/sshd/connection.go
@@ -54,7 +54,7 @@ func (c *connection) handle(ctx context.Context, chans <-chan ssh.NewChannel, ha
// Prevent a panic in a single session from taking out the whole server
defer func() {
if err := recover(); err != nil {
- log.WithFields(log.Fields{"recovered_error": err}).Warnf("panic handling session from %s", c.remoteAddr)
+ log.WithContextFields(ctx, log.Fields{"recovered_error": err, "address": c.remoteAddr}).Warn("panic handling session")
}
}()
diff --git a/internal/sshd/server_config.go b/internal/sshd/server_config.go
index 7306944..68210f8 100644
--- a/internal/sshd/server_config.go
+++ b/internal/sshd/server_config.go
@@ -32,12 +32,12 @@ func newServerConfig(cfg *config.Config) (*serverConfig, error) {
for _, filename := range cfg.Server.HostKeyFiles {
keyRaw, err := os.ReadFile(filename)
if err != nil {
- log.WithError(err).Warnf("Failed to read host key %v", filename)
+ log.WithError(err).WithFields(log.Fields{"filename": filename}).Warn("Failed to read host key")
continue
}
key, err := ssh.ParsePrivateKey(keyRaw)
if err != nil {
- log.WithError(err).Warnf("Failed to parse host key %v", filename)
+ log.WithError(err).WithFields(log.Fields{"filename": filename}).Warn("Failed to parse host key")
continue
}
diff --git a/internal/sshd/sshd.go b/internal/sshd/sshd.go
index ff9e765..92a9c2b 100644
--- a/internal/sshd/sshd.go
+++ b/internal/sshd/sshd.go
@@ -47,7 +47,7 @@ func NewServer(cfg *config.Config) (*Server, error) {
}
func (s *Server) ListenAndServe(ctx context.Context) error {
- if err := s.listen(); err != nil {
+ if err := s.listen(ctx); err != nil {
return err
}
defer s.listener.Close()
@@ -85,7 +85,7 @@ func (s *Server) MonitoringServeMux() *http.ServeMux {
return mux
}
-func (s *Server) listen() error {
+func (s *Server) listen(ctx context.Context) error {
sshListener, err := net.Listen("tcp", s.Config.Server.Listen)
if err != nil {
return fmt.Errorf("failed to listen for connection: %w", err)
@@ -97,10 +97,10 @@ func (s *Server) listen() error {
ReadHeaderTimeout: ProxyHeaderTimeout,
}
- log.Info("Proxy protocol is enabled")
+ log.ContextLogger(ctx).Info("Proxy protocol is enabled")
}
- log.WithFields(log.Fields{"tcp_address": sshListener.Addr().String()}).Info("Listening for SSH connections")
+ log.WithContextFields(ctx, log.Fields{"tcp_address": sshListener.Addr().String()}).Info("Listening for SSH connections")
s.listener = sshListener
@@ -117,7 +117,7 @@ func (s *Server) serve(ctx context.Context) {
break
}
- log.WithError(err).Warn("Failed to accept connection")
+ log.ContextLogger(ctx).WithError(err).Warn("Failed to accept connection")
continue
}
@@ -152,7 +152,7 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
// Prevent a panic in a single connection from taking out the whole server
defer func() {
if err := recover(); err != nil {
- log.WithFields(log.Fields{"recovered_error": err}).Warnf("panic handling session from %s", remoteAddr)
+ log.WithContextFields(ctx, log.Fields{"recovered_error": err, "address": remoteAddr}).Warn("panic handling session")
}
}()
@@ -161,7 +161,7 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
sconn, chans, reqs, err := ssh.NewServerConn(nconn, s.serverConfig.get(ctx))
if err != nil {
- log.WithError(err).Info("Failed to initialize SSH connection")
+ log.ContextLogger(ctx).WithError(err).Info("Failed to initialize SSH connection")
return
}