Skip to content

Commit

Permalink
TUN-8489: Add default noop logger for capnprpc
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinCarr committed Jul 2, 2024
1 parent d875839 commit 6174c45
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tunnelrpc/quic/cloudflared_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewCloudflaredClient(ctx context.Context, stream io.ReadWriteCloser, reques
return nil, fmt.Errorf("expect to write %d bytes for RPC stream protocol signature, wrote %d", len(rpcStreamProtocolSignature), n)
}
transport := tunnelrpc.SafeTransport(stream)
conn := rpc.NewConn(transport)
conn := tunnelrpc.NewClientConn(transport)
client := pogs.NewCloudflaredServer_PogsClient(conn.Bootstrap(ctx), conn)
return &CloudflaredClient{
client: client,
Expand Down
4 changes: 1 addition & 3 deletions tunnelrpc/quic/cloudflared_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"io"
"time"

"zombiezen.com/go/capnproto2/rpc"

"github.com/cloudflare/cloudflared/tunnelrpc"
"github.com/cloudflare/cloudflared/tunnelrpc/pogs"
)
Expand Down Expand Up @@ -58,7 +56,7 @@ func (s *CloudflaredServer) handleRPC(ctx context.Context, stream io.ReadWriteCl
defer transport.Close()

main := pogs.CloudflaredServer_ServerToClient(s.sessionManager, s.configManager)
rpcConn := rpc.NewConn(transport, rpc.MainInterface(main.Client))
rpcConn := tunnelrpc.NewServerConn(transport, main.Client)
defer rpcConn.Close()

// We ignore the errors here because if cloudflared fails to handle a request, we will just move on.
Expand Down
2 changes: 1 addition & 1 deletion tunnelrpc/quic/session_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewSessionClient(ctx context.Context, stream io.ReadWriteCloser, requestTim
return nil, fmt.Errorf("expect to write %d bytes for RPC stream protocol signature, wrote %d", len(rpcStreamProtocolSignature), n)
}
transport := tunnelrpc.SafeTransport(stream)
conn := rpc.NewConn(transport)
conn := tunnelrpc.NewClientConn(transport)
return &SessionClient{
client: pogs.NewSessionManager_PogsClient(conn.Bootstrap(ctx), conn),
transport: transport,
Expand Down
4 changes: 1 addition & 3 deletions tunnelrpc/quic/session_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"io"
"time"

"zombiezen.com/go/capnproto2/rpc"

"github.com/cloudflare/cloudflared/tunnelrpc"
"github.com/cloudflare/cloudflared/tunnelrpc/pogs"
)
Expand Down Expand Up @@ -48,7 +46,7 @@ func (s *SessionManagerServer) Serve(ctx context.Context, stream io.ReadWriteClo
defer transport.Close()

main := pogs.SessionManager_ServerToClient(s.sessionManager)
rpcConn := rpc.NewConn(transport, rpc.MainInterface(main.Client))
rpcConn := tunnelrpc.NewServerConn(transport, main.Client)
defer rpcConn.Close()

select {
Expand Down
2 changes: 1 addition & 1 deletion tunnelrpc/registration_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type registrationClient struct {

func NewRegistrationClient(ctx context.Context, stream io.ReadWriteCloser, requestTimeout time.Duration) RegistrationClient {
transport := SafeTransport(stream)
conn := rpc.NewConn(transport)
conn := NewClientConn(transport)
client := pogs.NewRegistrationServer_PogsClient(conn.Bootstrap(ctx), conn)
return &registrationClient{
client: client,
Expand Down
5 changes: 1 addition & 4 deletions tunnelrpc/registration_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"io"

"zombiezen.com/go/capnproto2/rpc"

"github.com/cloudflare/cloudflared/tunnelrpc/pogs"
)

Expand All @@ -28,8 +26,7 @@ func (s *RegistrationServer) Serve(ctx context.Context, stream io.ReadWriteClose
defer transport.Close()

main := pogs.RegistrationServer_ServerToClient(s.registrationServer)
rpcConn := rpc.NewConn(transport, rpc.MainInterface(main.Client))
defer rpcConn.Close()
rpcConn := NewServerConn(transport, main.Client)

select {
case <-rpcConn.Done():
Expand Down
20 changes: 20 additions & 0 deletions tunnelrpc/utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package tunnelrpc

import (
"context"
"io"
"time"

"github.com/pkg/errors"
capnp "zombiezen.com/go/capnproto2"
"zombiezen.com/go/capnproto2/rpc"
)

Expand Down Expand Up @@ -67,3 +69,21 @@ func isTemporaryError(e error) bool {
t, ok := e.(temp)
return ok && t.Temporary()
}

// NoopCapnpLogger provides a logger to discard all capnp rpc internal logging messages as
// they are by default provided to stdout if no logger interface is provided. These logging
// messages in cloudflared have typically not provided a high amount of pratical value
// as the messages are extremely verbose and don't provide a good insight into the message
// contents or rpc method names.
type noopCapnpLogger struct{}

func (noopCapnpLogger) Infof(ctx context.Context, format string, args ...interface{}) {}
func (noopCapnpLogger) Errorf(ctx context.Context, format string, args ...interface{}) {}

func NewClientConn(transport rpc.Transport) *rpc.Conn {
return rpc.NewConn(transport, rpc.ConnLog(noopCapnpLogger{}))
}

func NewServerConn(transport rpc.Transport, client capnp.Client) *rpc.Conn {
return rpc.NewConn(transport, rpc.MainInterface(client), rpc.ConnLog(noopCapnpLogger{}))
}

0 comments on commit 6174c45

Please sign in to comment.