Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: increase grpc max call send & receive msg size #192

Merged
merged 2 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compass.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ db:
service:
host: localhost
port: 8080
grpc_port: 8081
identity:
headerkey_uuid: Compass-User-UUID
headerkey_email: Compass-User-Email
provider_default_name: shield
grpc:
port: 8081
max_send_msg_size: 33554432
max_recv_msg_size: 33554432

client:
host: localhost:8080
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ require (
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/net v0.0.0-20220919232410-f2f64ebce3c1
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc
google.golang.org/grpc v1.49.0
Expand Down
27 changes: 21 additions & 6 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ import (
)

type Config struct {
Host string `mapstructure:"host" default:"0.0.0.0"`
Port int `mapstructure:"port" default:"8080"`
GRPCPort int `mapstructure:"grpc_port" default:"8081"`
BaseUrl string `mapstructure:"baseurl" default:"localhost:8080"`
Host string `mapstructure:"host" default:"0.0.0.0"`
Port int `mapstructure:"port" default:"8080"`
BaseUrl string `mapstructure:"baseurl" default:"localhost:8080"`

// User Identity
Identity IdentityConfig `mapstructure:"identity"`

// GRPC Config
GRPC GRPCConfig `mapstructure:"grpc"`
}

func (cfg Config) addr() string { return fmt.Sprintf("%s:%d", cfg.Host, cfg.Port) }
func (cfg Config) grpcAddr() string { return fmt.Sprintf("%s:%d", cfg.Host, cfg.GRPCPort) }
func (cfg Config) grpcAddr() string { return fmt.Sprintf("%s:%d", cfg.Host, cfg.GRPC.Port) }

type IdentityConfig struct {
// User Identity
Expand All @@ -51,6 +53,12 @@ type IdentityConfig struct {
ProviderDefaultName string `mapstructure:"provider_default_name" default:""`
}

type GRPCConfig struct {
Port int `mapstructure:"port" default:"8081"`
MaxRecvMsgSize int `mapstructure:"max_recv_msg_size" default:"33554432"`
MaxSendMsgSize int `mapstructure:"max_send_msg_size" default:"33554432"`
}

func Serve(
ctx context.Context,
config Config,
Expand Down Expand Up @@ -100,7 +108,14 @@ func Serve(

headerMatcher := makeHeaderMatcher(config)

grpcConn, err := grpc.DialContext(grpcDialCtx, config.grpcAddr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
grpcConn, err := grpc.DialContext(
grpcDialCtx,
config.grpcAddr(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(config.GRPC.MaxRecvMsgSize),
grpc.MaxCallSendMsgSize(config.GRPC.MaxSendMsgSize),
))
if err != nil {
return err
}
Expand Down