Skip to content

[UBP/baseserver] Allow gRPC server to receive much larger messages #12003

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

Merged
merged 3 commits into from
Aug 9, 2022
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
1 change: 1 addition & 0 deletions components/common-go/baseserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func (s *Server) initializeGRPC() error {
opts = append(opts, grpc.Creds(credentials.NewTLS(tlsConfig)))
}

opts = append(opts, grpc.MaxRecvMsgSize(100*1024*1024))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not change the gRPC base server default message size and let the caller overwrite the default message size? Because this is an optional for all gRPC server, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can probably provide an option to set this.

The question is whether a user of the baseserver would ever care that the maximum message size was too large. IMO, probably not in which case an option is not needed. Perhaps we should add the option when it's needed.

s.grpc = grpc.NewServer(opts...)

reflection.Register(s.grpc)
Expand Down
59 changes: 59 additions & 0 deletions components/usage/pkg/apiv1/size_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package apiv1

import (
"context"
"testing"
"time"

"github.com/gitpod-io/gitpod/common-go/baseserver"
v1 "github.com/gitpod-io/gitpod/usage-api/v1"
"github.com/gitpod-io/gitpod/usage/pkg/stripe"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)

func TestServerCanReceiveLargeMessages(t *testing.T) {
srv := baseserver.NewForTests(t,
baseserver.WithGRPC(baseserver.MustUseRandomLocalAddress(t)),
)

v1.RegisterBillingServiceServer(srv.GRPC(), NewBillingService(&stripe.Client{}, time.Time{}))
baseserver.StartServerForTests(t, srv)

conn, err := grpc.Dial(srv.GRPCAddress(), grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err)

client := v1.NewBillingServiceClient(conn)

_, err = client.UpdateInvoices(context.Background(), &v1.UpdateInvoicesRequest{
Sessions: getBilledSessions(),
})

require.NoError(t, err)
}

func getBilledSessions() (sessions []*v1.BilledSession) {
for i := 0; i < 900000; i++ {
sessions = append(sessions, &v1.BilledSession{
AttributionId: "user:1234",
UserId: "1234",
TeamId: "",
WorkspaceId: "",
WorkspaceType: "",
ProjectId: "",
InstanceId: "",
WorkspaceClass: "",
StartTime: &timestamppb.Timestamp{},
EndTime: &timestamppb.Timestamp{},
CreditsDeprecated: 0,
Credits: 0,
})
}
return
}
4 changes: 2 additions & 2 deletions components/usage/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func Start(cfg Config) error {
grpc.WithUnaryInterceptor(grpcClientMetrics.UnaryClientInterceptor()),
grpc.WithStreamInterceptor(grpcClientMetrics.StreamClientInterceptor()),
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(50*1024*1024),
grpc.MaxCallSendMsgSize(50*1024*1024),
grpc.MaxCallRecvMsgSize(100*1024*1024),
grpc.MaxCallSendMsgSize(100*1024*1024),
))
if err != nil {
return fmt.Errorf("failed to create self-connection to grpc server: %w", err)
Expand Down