From 0d221064169f750540588f494cc643982499352f Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Wed, 3 Feb 2021 12:32:54 -0600 Subject: [PATCH] TUN-3848: Use transport logger for h2mux --- cmd/cloudflared/tunnel/cmd.go | 8 ++++---- cmd/cloudflared/tunnel/configuration.go | 7 ++++--- connection/connection_test.go | 2 +- connection/h2mux.go | 2 +- connection/observer.go | 4 +++- connection/observer_test.go | 2 +- origin/supervisor.go | 6 ++++-- origin/tunnel.go | 1 + origin/tunnel_test.go | 3 ++- 9 files changed, 21 insertions(+), 14 deletions(-) diff --git a/cmd/cloudflared/tunnel/cmd.go b/cmd/cloudflared/tunnel/cmd.go index 61c57457..a9e09f29 100644 --- a/cmd/cloudflared/tunnel/cmd.go +++ b/cmd/cloudflared/tunnel/cmd.go @@ -313,11 +313,11 @@ func StartServer( return fmt.Errorf(errText) } - transportLog := logger.CreateTransportLoggerFromContext(c, isUIEnabled) + logTransport := logger.CreateTransportLoggerFromContext(c, isUIEnabled) - observer := connection.NewObserver(log, isUIEnabled) + observer := connection.NewObserver(log, logTransport, isUIEnabled) - tunnelConfig, ingressRules, err := prepareTunnelConfig(c, buildInfo, version, log, observer, namedTunnel) + tunnelConfig, ingressRules, err := prepareTunnelConfig(c, buildInfo, version, log, logTransport, observer, namedTunnel) if err != nil { log.Err(err).Msg("Couldn't start tunnel") return err @@ -364,7 +364,7 @@ func StartServer( &ingressRules, tunnelConfig.HAConnections, ) - app := tunnelUI.Launch(ctx, log, transportLog) + app := tunnelUI.Launch(ctx, log, logTransport) observer.RegisterSink(app) } diff --git a/cmd/cloudflared/tunnel/configuration.go b/cmd/cloudflared/tunnel/configuration.go index 22ac21ff..26f07dce 100644 --- a/cmd/cloudflared/tunnel/configuration.go +++ b/cmd/cloudflared/tunnel/configuration.go @@ -149,7 +149,7 @@ func prepareTunnelConfig( c *cli.Context, buildInfo *buildinfo.BuildInfo, version string, - log *zerolog.Logger, + log, logTransport *zerolog.Logger, observer *connection.Observer, namedTunnel *connection.NamedTunnelConfig, ) (*origin.TunnelConfig, ingress.Ingress, error) { @@ -252,9 +252,9 @@ func prepareTunnelConfig( ReplaceExisting: c.Bool("force"), } muxerConfig := &connection.MuxerConfig{ - HeartbeatInterval: c.Duration("heartbeat-interval"), + HeartbeatInterval: c.Duration("heartbeat-interval"), // Note TUN-3758 , we use Int because UInt is not supported with altsrc - MaxHeartbeats: uint64(c.Int("heartbeat-count")), + MaxHeartbeats: uint64(c.Int("heartbeat-count")), // Note TUN-3758 , we use Int because UInt is not supported with altsrc CompressionSetting: h2mux.CompressionSetting(uint64(c.Int("compression-quality"))), MetricsUpdateFreq: c.Duration("metrics-update-freq"), @@ -272,6 +272,7 @@ func prepareTunnelConfig( LBPool: c.String("lb-pool"), Tags: tags, Log: log, + LogTransport: logTransport, Observer: observer, ReportedVersion: version, // Note TUN-3758 , we use Int because UInt is not supported with altsrc diff --git a/connection/connection_test.go b/connection/connection_test.go index f15f8c6a..df14fa91 100644 --- a/connection/connection_test.go +++ b/connection/connection_test.go @@ -27,7 +27,7 @@ var ( Scheme: "https", Host: "connectiontest.argotunnel.com", } - testObserver = NewObserver(&log, false) + testObserver = NewObserver(&log, &log, false) testLargeResp = make([]byte, largeFileSize) ) diff --git a/connection/h2mux.go b/connection/h2mux.go index 4a5d7f00..09d9b556 100644 --- a/connection/h2mux.go +++ b/connection/h2mux.go @@ -77,7 +77,7 @@ func NewH2muxConnection( // Establish a muxed connection with the edge // Client mux handshake with agent server - muxer, err := h2mux.Handshake(edgeConn, edgeConn, *muxerConfig.H2MuxerConfig(h, observer.log), h2mux.ActiveStreams) + muxer, err := h2mux.Handshake(edgeConn, edgeConn, *muxerConfig.H2MuxerConfig(h, observer.logTransport), h2mux.ActiveStreams) if err != nil { recoverable := isHandshakeErrRecoverable(err, connIndex, observer) return nil, err, recoverable diff --git a/connection/observer.go b/connection/observer.go index 63765054..2882fe41 100644 --- a/connection/observer.go +++ b/connection/observer.go @@ -17,6 +17,7 @@ const ( type Observer struct { log *zerolog.Logger + logTransport *zerolog.Logger metrics *tunnelMetrics tunnelEventChan chan Event uiEnabled bool @@ -27,9 +28,10 @@ type EventSink interface { OnTunnelEvent(event Event) } -func NewObserver(log *zerolog.Logger, uiEnabled bool) *Observer { +func NewObserver(log, logTransport *zerolog.Logger, uiEnabled bool) *Observer { o := &Observer{ log: log, + logTransport: logTransport, metrics: newTunnelMetrics(), uiEnabled: uiEnabled, tunnelEventChan: make(chan Event, observerChannelBufferSize), diff --git a/connection/observer_test.go b/connection/observer_test.go index fda48dad..b0387ca8 100644 --- a/connection/observer_test.go +++ b/connection/observer_test.go @@ -44,7 +44,7 @@ func TestRegisterServerLocation(t *testing.T) { } func TestObserverEventsDontBlock(t *testing.T) { - observer := NewObserver(&log, false) + observer := NewObserver(&log, &log, false) var mu sync.Mutex observer.RegisterSink(EventSinkFunc(func(_ Event) { // callback will block if lock is already held diff --git a/origin/supervisor.go b/origin/supervisor.go index c00ba342..8397e2fa 100644 --- a/origin/supervisor.go +++ b/origin/supervisor.go @@ -51,7 +51,8 @@ type Supervisor struct { nextConnectedIndex int nextConnectedSignal chan struct{} - log *zerolog.Logger + log *zerolog.Logger + logTransport *zerolog.Logger reconnectCredentialManager *reconnectCredentialManager useReconnectToken bool @@ -94,6 +95,7 @@ func NewSupervisor(config *TunnelConfig, reconnectCh chan ReconnectSignal, grace tunnelErrors: make(chan tunnelError), tunnelsConnecting: map[int]chan struct{}{}, log: config.Log, + logTransport: config.LogTransport, reconnectCredentialManager: newReconnectCredentialManager(connection.MetricsNamespace, connection.TunnelSubsystem, config.HAConnections), useReconnectToken: useReconnectToken, reconnectCh: reconnectCh, @@ -350,7 +352,7 @@ func (s *Supervisor) authenticate(ctx context.Context, numPreviousAttempts int) // This callback is invoked by h2mux when the edge initiates a stream. return nil // noop }) - muxerConfig := s.config.MuxerConfig.H2MuxerConfig(handler, s.log) + muxerConfig := s.config.MuxerConfig.H2MuxerConfig(handler, s.logTransport) muxer, err := h2mux.Handshake(edgeConn, edgeConn, *muxerConfig, h2mux.ActiveStreams) if err != nil { return nil, err diff --git a/origin/tunnel.go b/origin/tunnel.go index fd810aac..7802cfc3 100644 --- a/origin/tunnel.go +++ b/origin/tunnel.go @@ -51,6 +51,7 @@ type TunnelConfig struct { LBPool string Tags []tunnelpogs.Tag Log *zerolog.Logger + LogTransport *zerolog.Logger Observer *connection.Observer ReportedVersion string Retries uint diff --git a/origin/tunnel_test.go b/origin/tunnel_test.go index 8f4c973c..2484b44a 100644 --- a/origin/tunnel_test.go +++ b/origin/tunnel_test.go @@ -52,8 +52,9 @@ func TestWaitForBackoffFallback(t *testing.T) { assert.NoError(t, err) config := &TunnelConfig{ Log: &log, + LogTransport: &log, ProtocolSelector: protocolSelector, - Observer: connection.NewObserver(nil, false), + Observer: connection.NewObserver(&log, &log, false), } connIndex := uint8(1)