Skip to content

Commit

Permalink
Convert lib/srv/transport to use slog
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy committed Dec 9, 2024
1 parent 607d998 commit 0bcef1a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4932,7 +4932,7 @@ func (process *TeleportProcess) initProxyEndpoint(conn *Connector) error {

transportService, err := transportv1.NewService(transportv1.ServerConfig{
FIPS: cfg.FIPS,
Logger: process.log.WithField(teleport.ComponentKey, "transport"),
Logger: process.logger.With(teleport.ComponentKey, "transport"),
Dialer: proxyRouter,
SignerFn: func(authzCtx *authz.Context, clusterName string) agentless.SignerCreator {
return agentless.SignerFromAuthzContext(authzCtx, accessPoint, clusterName)
Expand Down
11 changes: 6 additions & 5 deletions lib/srv/transport/transportv1/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import (
"context"
"errors"
"io"
"log/slog"
"net"
"net/netip"
"reflect"
"sync"

"github.com/gravitational/trace"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/agent"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -63,7 +64,7 @@ type ServerConfig struct {
// to run in FIPS mode.
FIPS bool
// Logger provides a mechanism to log output.
Logger logrus.FieldLogger
Logger *slog.Logger
// Dialer is used to establish remote connections.
Dialer Dialer
// SignerFn is used to create an [ssh.Signer] for an authenticated connection.
Expand Down Expand Up @@ -93,7 +94,7 @@ func (c *ServerConfig) CheckAndSetDefaults() error {
}

if c.Logger == nil {
c.Logger = utils.NewLogger().WithField(teleport.ComponentKey, "transport")
c.Logger = slog.With(teleport.ComponentKey, "transport")
}

if c.agentGetterFn == nil {
Expand Down Expand Up @@ -247,7 +248,7 @@ func (s *Service) ProxySSH(stream transportv1pb.TransportService_ProxySSHServer)
req, err := stream.Recv()
if err != nil {
if !utils.IsOKNetworkError(err) && !errors.Is(err, context.Canceled) && status.Code(err) != codes.Canceled {
s.cfg.Logger.Errorf("ssh stream terminated unexpectedly: %v", err)
s.cfg.Logger.ErrorContext(ctx, "ssh stream terminated unexpectedly", "error", err)
}

return
Expand All @@ -262,7 +263,7 @@ func (s *Service) ProxySSH(stream transportv1pb.TransportService_ProxySSHServer)
case *transportv1pb.ProxySSHRequest_Agent:
agentStream.incomingC <- frame.Agent.Payload
default:
s.cfg.Logger.Errorf("received unexpected ssh frame: %T", frame)
s.cfg.Logger.ErrorContext(ctx, "received unexpected ssh frame", "frame", reflect.TypeOf(frame))
continue
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/srv/transport/transportv1/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestService_GetClusterDetails(t *testing.T) {
t.Parallel()
srv := newServer(t, ServerConfig{
Dialer: fakeDialer{},
Logger: utils.NewLoggerForTests(),
Logger: utils.NewSlogLoggerForTests(),
FIPS: test.FIPS,
SignerFn: fakeSigner,
ConnectionMonitor: fakeMonitor{},
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestService_ProxyCluster(t *testing.T) {
cluster: conn,
},
},
Logger: utils.NewLoggerForTests(),
Logger: utils.NewSlogLoggerForTests(),
SignerFn: fakeSigner,
ConnectionMonitor: fakeMonitor{},
LocalAddr: utils.MustParseAddr("127.0.0.1:4242"),
Expand Down Expand Up @@ -491,7 +491,7 @@ func TestService_ProxySSH_Errors(t *testing.T) {
},
SignerFn: fakeSigner,
ConnectionMonitor: fakeMonitor{},
Logger: utils.NewLoggerForTests(),
Logger: utils.NewSlogLoggerForTests(),
LocalAddr: utils.MustParseAddr("127.0.0.1:4242"),
authzContextFn: func(info credentials.AuthInfo) (*authz.Context, error) {
checker, err := test.checkerFn(info)
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestService_ProxySSH(t *testing.T) {
srv := newServer(t, ServerConfig{
Dialer: sshSrv,
SignerFn: fakeSigner,
Logger: utils.NewLoggerForTests(),
Logger: utils.NewSlogLoggerForTests(),
LocalAddr: utils.MustParseAddr("127.0.0.1:4242"),
ConnectionMonitor: fakeMonitor{},
agentGetterFn: func(rw io.ReadWriter) teleagent.Getter {
Expand Down
2 changes: 1 addition & 1 deletion lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8308,7 +8308,7 @@ func createProxy(ctx context.Context, t *testing.T, proxyID string, node *regula

transportService, err := transportv1.NewService(transportv1.ServerConfig{
FIPS: false,
Logger: utils.NewLoggerForTests(),
Logger: utils.NewSlogLoggerForTests(),
Dialer: router,
SignerFn: func(authzCtx *authz.Context, clusterName string) agentless.SignerCreator {
return agentless.SignerFromAuthzContext(authzCtx, client, clusterName)
Expand Down

0 comments on commit 0bcef1a

Please sign in to comment.