Skip to content

Commit

Permalink
Make zed take an option
Browse files Browse the repository at this point in the history
  • Loading branch information
tstirrat15 committed Aug 28, 2024
1 parent 931c403 commit 1dc9136
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
27 changes: 11 additions & 16 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ type Client interface {
// NewClient defines an (overridable) means of creating a new client.
var NewClient = newGRPCClient

const oneGb = 1 * 1024 * 1024 * 1024

var defaultCallOptions = grpc.WithDefaultCallOptions(
// The default max client message size is 4mb.
// It's conceivable that a sufficiently complex
// schema will easily surpass this, so we set the
// limit higher here.
grpc.MaxCallRecvMsgSize(oneGb),
grpc.MaxCallSendMsgSize(oneGb),
)

func newGRPCClient(cmd *cobra.Command) (Client, error) {
configStore, secretStore := DefaultStorage()
token, err := storage.DefaultToken(
Expand All @@ -54,15 +43,11 @@ func newGRPCClient(cmd *cobra.Command) (Client, error) {
}
log.Trace().Interface("token", token).Send()

flagDialOpts, err := DialOptsFromFlags(cmd, token)
dialOpts, err := DialOptsFromFlags(cmd, token)
if err != nil {
return nil, err
}

// NOTE: this works as long as we don't have CallOptions
// defined in flags. We'll have to modify this logic then.
dialOpts := append(flagDialOpts, defaultCallOptions)

client, err := authzed.NewClientWithExperimentalAPIs(token.Endpoint, dialOpts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -106,9 +91,19 @@ func DialOptsFromFlags(cmd *cobra.Command, token storage.Token) ([]grpc.DialOpti
interceptors = append(interceptors, zgrpcutil.CheckServerVersion)
}

maxMessageSize := cobrautil.MustGetInt(cmd, "max-message-size")

opts := []grpc.DialOption{
grpc.WithChainUnaryInterceptor(interceptors...),
grpc.WithChainStreamInterceptor(zgrpcutil.StreamLogDispatchTrailers),
grpc.WithDefaultCallOptions(
// The default max client message size is 4mb.
// It's conceivable that a sufficiently complex
// schema will easily surpass this, so we set the
// limit higher here.
grpc.MaxCallRecvMsgSize(maxMessageSize),
grpc.MaxCallSendMsgSize(maxMessageSize),
),
}

if cobrautil.MustGetBool(cmd, "insecure") || (token.IsInsecure()) {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Run() {
rootCmd.PersistentFlags().Bool("no-verify-ca", false, "do not attempt to verify the server's certificate chain and host name")
rootCmd.PersistentFlags().Bool("debug", false, "enable debug logging")
rootCmd.PersistentFlags().String("request-id", "", "optional id to send along with SpiceDB requests for tracing")
rootCmd.PersistentFlags().Int("max-message-size", 4*1024*1024, "maximum size (bytes) of a gRPC message sent or received by zed")
_ = rootCmd.PersistentFlags().MarkHidden("debug") // This cannot return its error.

versionCmd := &cobra.Command{
Expand Down

0 comments on commit 1dc9136

Please sign in to comment.