Skip to content

Commit

Permalink
plugin/pluginapi/v1: increase gRPC call message size (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
dobarx authored Feb 28, 2024
1 parent 568f442 commit 0df8385
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions plugin/pluginapi/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

goplugin "github.com/hashicorp/go-plugin"
"google.golang.org/grpc"

"github.com/blackstork-io/fabric/pkg/sloghclog"
"github.com/blackstork-io/fabric/plugin"
Expand Down Expand Up @@ -53,6 +54,12 @@ func NewClient(loc string) (p *plugin.Schema, closefn func() error, err error) {
sloghclog.AddSource(false),
sloghclog.Level(slog.LevelInfo), // debug is too noisy for plugins
),
GRPCDialOptions: []grpc.DialOption{
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(defaultMsgSize),
grpc.MaxCallSendMsgSize(defaultMsgSize),
),
},
})
rpcClient, err := client.Client()
if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions plugin/pluginapi/v1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/blackstork-io/fabric/plugin"
)

var defaultMsgSize = 1024 * 1024 * 20

var handshake = goplugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "PLUGINS_FOR",
Expand All @@ -31,6 +33,7 @@ func (p *grpcPlugin) GRPCServer(broker *goplugin.GRPCBroker, s *grpc.Server) err

func (p *grpcPlugin) GRPCClient(ctx context.Context, broker *goplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
client := NewPluginServiceClient(c)

res, err := client.GetSchema(ctx, &GetSchemaRequest{})
if err != nil {
return nil, err
Expand All @@ -54,6 +57,13 @@ func (p *grpcPlugin) GRPCClient(ctx context.Context, broker *goplugin.GRPCBroker
return schema, nil
}

func (p *grpcPlugin) callOptions() []grpc.CallOption {
return []grpc.CallOption{
grpc.MaxCallRecvMsgSize(defaultMsgSize),
grpc.MaxCallSendMsgSize(defaultMsgSize),
}
}

func (p *grpcPlugin) clientGenerateFunc(name string, client PluginServiceClient) plugin.ProvideContentFunc {
return func(ctx context.Context, params *plugin.ProvideContentParams) (*plugin.Content, hcl.Diagnostics) {
if params == nil {
Expand Down Expand Up @@ -84,7 +94,7 @@ func (p *grpcPlugin) clientGenerateFunc(name string, client PluginServiceClient)
Config: cfgEncoded,
Args: argsEncoded,
DataContext: encodeMapData(params.DataContext),
})
}, p.callOptions()...)
if err != nil {
return nil, hcl.Diagnostics{{
Severity: hcl.DiagError,
Expand Down Expand Up @@ -128,7 +138,7 @@ func (p *grpcPlugin) clientDataFunc(name string, client PluginServiceClient) plu
Source: name,
Config: cfgEncoded,
Args: argsEncoded,
})
}, p.callOptions()...)
if err != nil {
return nil, hcl.Diagnostics{{
Severity: hcl.DiagError,
Expand Down
6 changes: 5 additions & 1 deletion plugin/pluginapi/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
context "context"

goplugin "github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"

Expand All @@ -16,7 +17,10 @@ func Serve(schema *plugin.Schema) {
Plugins: map[string]goplugin.Plugin{
schema.Name: &grpcPlugin{schema: schema},
},
GRPCServer: goplugin.DefaultGRPCServer,
GRPCServer: func(opts []grpc.ServerOption) *grpc.Server {
opts = append(opts, grpc.MaxRecvMsgSize(defaultMsgSize))
return grpc.NewServer(opts...)
},
})
}

Expand Down

0 comments on commit 0df8385

Please sign in to comment.