TUN-1418: Rename ProtocolLogger to TransportLogger, and use TransportLogger to log RPC events.

This commit is contained in:
Chung-Ting Huang 2019-01-28 14:11:56 -06:00
parent 9db4b7fdfb
commit 61cd4a918d
4 changed files with 23 additions and 22 deletions

View File

@ -191,9 +191,9 @@ func StartServer(c *cli.Context, version string, shutdownC, graceShutdownC chan
return errors.Wrap(err, "Error configuring logger") return errors.Wrap(err, "Error configuring logger")
} }
protoLogger, err := configProtoLogger(c) transportLogger, err := configTransportLogger(c)
if err != nil { if err != nil {
return errors.Wrap(err, "Error configuring protocol logger") return errors.Wrap(err, "Error configuring transport logger")
} }
if c.IsSet("trace-output") { if c.IsSet("trace-output") {
@ -224,7 +224,7 @@ func StartServer(c *cli.Context, version string, shutdownC, graceShutdownC chan
} }
if c.String("logfile") != "" { if c.String("logfile") != "" {
if err := initLogFile(c, logger, protoLogger); err != nil { if err := initLogFile(c, logger, transportLogger); err != nil {
logger.Error(err) logger.Error(err)
} }
} }
@ -318,7 +318,7 @@ func StartServer(c *cli.Context, version string, shutdownC, graceShutdownC chan
c.Set("url", "http://"+listener.Addr().String()) c.Set("url", "http://"+listener.Addr().String())
} }
tunnelConfig, err := prepareTunnelConfig(c, buildInfo, version, logger, protoLogger) tunnelConfig, err := prepareTunnelConfig(c, buildInfo, version, logger, transportLogger)
if err != nil { if err != nil {
return err return err
} }
@ -539,10 +539,11 @@ func tunnelFlags(shouldHide bool) []cli.Flag {
Hidden: shouldHide, Hidden: shouldHide,
}), }),
altsrc.NewStringFlag(&cli.StringFlag{ altsrc.NewStringFlag(&cli.StringFlag{
Name: "proto-loglevel", Name: "transport-loglevel",
Aliases: []string{"proto-loglevel"}, // This flag used to be called proto-loglevel
Value: "warn", Value: "warn",
Usage: "Protocol logging level {panic, fatal, error, warn, info, debug}", Usage: "Transport logging level(previously called protocol logging level) {panic, fatal, error, warn, info, debug}",
EnvVars: []string{"TUNNEL_PROTO_LOGLEVEL"}, EnvVars: []string{"TUNNEL_PROTO_LOGLEVEL", "TUNNEL_TRANSPORT_LOGLEVEL"},
Hidden: shouldHide, Hidden: shouldHide,
}), }),
altsrc.NewUintFlag(&cli.UintFlag{ altsrc.NewUintFlag(&cli.UintFlag{

View File

@ -136,7 +136,7 @@ If you don't have a certificate signed by Cloudflare, run the command:
return originCert, nil return originCert, nil
} }
func prepareTunnelConfig(c *cli.Context, buildInfo *origin.BuildInfo, version string, logger, protoLogger *logrus.Logger) (*origin.TunnelConfig, error) { func prepareTunnelConfig(c *cli.Context, buildInfo *origin.BuildInfo, version string, logger, transportLogger *logrus.Logger) (*origin.TunnelConfig, error) {
hostname, err := validation.ValidateHostname(c.String("hostname")) hostname, err := validation.ValidateHostname(c.String("hostname"))
if err != nil { if err != nil {
logger.WithError(err).Error("Invalid hostname") logger.WithError(err).Error("Invalid hostname")
@ -223,7 +223,7 @@ func prepareTunnelConfig(c *cli.Context, buildInfo *origin.BuildInfo, version st
HTTPTransport: httpTransport, HTTPTransport: httpTransport,
Metrics: tunnelMetrics, Metrics: tunnelMetrics,
MetricsUpdateFreq: c.Duration("metrics-update-freq"), MetricsUpdateFreq: c.Duration("metrics-update-freq"),
ProtocolLogger: protoLogger, TransportLogger: transportLogger,
Logger: logger, Logger: logger,
IsAutoupdated: c.Bool("is-autoupdated"), IsAutoupdated: c.Bool("is-autoupdated"),
GracePeriod: c.Duration("grace-period"), GracePeriod: c.Duration("grace-period"),

View File

@ -25,15 +25,15 @@ func configMainLogger(c *cli.Context) error {
return nil return nil
} }
func configProtoLogger(c *cli.Context) (*logrus.Logger, error) { func configTransportLogger(c *cli.Context) (*logrus.Logger, error) {
protoLogLevel, err := logrus.ParseLevel(c.String("proto-loglevel")) transportLogLevel, err := logrus.ParseLevel(c.String("transport-loglevel"))
if err != nil { if err != nil {
logger.WithError(err).Fatal("Unknown protocol logging level specified") logger.WithError(err).Fatal("Unknown transport logging level specified")
return nil, errors.Wrap(err, "Unknown protocol logging level specified") return nil, errors.Wrap(err, "Unknown transport logging level specified")
} }
protoLogger := logrus.New() transportLogger := logrus.New()
protoLogger.Level = protoLogLevel transportLogger.Level = transportLogLevel
return protoLogger, nil return transportLogger, nil
} }
func initLogFile(c *cli.Context, loggers ...*logrus.Logger) error { func initLogFile(c *cli.Context, loggers ...*logrus.Logger) error {

View File

@ -55,7 +55,7 @@ type TunnelConfig struct {
HTTPTransport http.RoundTripper HTTPTransport http.RoundTripper
Metrics *TunnelMetrics Metrics *TunnelMetrics
MetricsUpdateFreq time.Duration MetricsUpdateFreq time.Duration
ProtocolLogger *log.Logger TransportLogger *log.Logger
Logger *log.Logger Logger *log.Logger
IsAutoupdated bool IsAutoupdated bool
GracePeriod time.Duration GracePeriod time.Duration
@ -236,7 +236,7 @@ func ServeTunnel(
select { select {
case <-serveCtx.Done(): case <-serveCtx.Done():
// UnregisterTunnel blocks until the RPC call returns // UnregisterTunnel blocks until the RPC call returns
err := UnregisterTunnel(handler.muxer, config.GracePeriod, config.Logger) err := UnregisterTunnel(handler.muxer, config.GracePeriod, config.TransportLogger)
handler.muxer.Shutdown() handler.muxer.Shutdown()
return err return err
case <-updateMetricsTickC: case <-updateMetricsTickC:
@ -303,7 +303,7 @@ func RegisterTunnel(
connectionID uint8, connectionID uint8,
originLocalIP string, originLocalIP string,
) error { ) error {
config.Logger.Debug("initiating RPC stream to register") config.TransportLogger.Debug("initiating RPC stream to register")
stream, err := muxer.OpenStream([]h2mux.Header{ stream, err := muxer.OpenStream([]h2mux.Header{
{Name: ":method", Value: "RPC"}, {Name: ":method", Value: "RPC"},
{Name: ":scheme", Value: "capnp"}, {Name: ":scheme", Value: "capnp"},
@ -318,8 +318,8 @@ func RegisterTunnel(
return clientRegisterTunnelError{cause: err} return clientRegisterTunnelError{cause: err}
} }
conn := rpc.NewConn( conn := rpc.NewConn(
tunnelrpc.NewTransportLogger(config.Logger.WithField("subsystem", "rpc-register"), rpc.StreamTransport(stream)), tunnelrpc.NewTransportLogger(config.TransportLogger.WithField("subsystem", "rpc-register"), rpc.StreamTransport(stream)),
tunnelrpc.ConnLog(config.Logger.WithField("subsystem", "rpc-transport")), tunnelrpc.ConnLog(config.TransportLogger.WithField("subsystem", "rpc-transport")),
) )
defer conn.Close() defer conn.Close()
ts := tunnelpogs.TunnelServer_PogsClient{Client: conn.Bootstrap(ctx)} ts := tunnelpogs.TunnelServer_PogsClient{Client: conn.Bootstrap(ctx)}
@ -531,7 +531,7 @@ func NewTunnelHandler(ctx context.Context,
IsClient: true, IsClient: true,
HeartbeatInterval: config.HeartbeatInterval, HeartbeatInterval: config.HeartbeatInterval,
MaxHeartbeats: config.MaxHeartbeats, MaxHeartbeats: config.MaxHeartbeats,
Logger: config.ProtocolLogger.WithFields(log.Fields{}), Logger: config.TransportLogger.WithFields(log.Fields{}),
CompressionQuality: h2mux.CompressionSetting(config.CompressionQuality), CompressionQuality: h2mux.CompressionSetting(config.CompressionQuality),
}) })
if err != nil { if err != nil {