Skip to content

Commit

Permalink
fix: Allow configuring maximum grpc received message size (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-nour-fdc authored May 24, 2024
1 parent e39c3b3 commit 750ea74
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions charts/kuberpult/templates/frontend-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ spec:
{{- end }}
- name: KUBERPULT_MAX_WAIT_DURATION
value: {{ .Values.frontend.maxWaitDuration | quote }}
- name: KUBERPULT_GRPC_MAX_RECV_MSG_SIZE
value: "{{ .Values.frontend.grpcMaxRecvMsgSize }}"
volumeMounts:
{{- if .Values.pgp.keyRing }}
- name: keyring
Expand Down
34 changes: 34 additions & 0 deletions charts/kuberpult/tests/charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,40 @@ auth:
},
ExpectedMissing: []core.EnvVar{},
},
{
Name: "Test default value for grpcMaxRecvMsgSize",
Values: `
git:
url: "testURL"
ingress:
domainName: "kuberpult-example.com"
`,
ExpectedEnvs: []core.EnvVar{
{
Name: "KUBERPULT_GRPC_MAX_RECV_MSG_SIZE",
Value: "4",
},
},
ExpectedMissing: []core.EnvVar{},
},
{
Name: "Test different value for grpcMaxRecvMsgSize",
Values: `
git:
url: "testURL"
ingress:
domainName: "kuberpult-example.com"
frontend:
grpcMaxRecvMsgSize: 8
`,
ExpectedEnvs: []core.EnvVar{
{
Name: "KUBERPULT_GRPC_MAX_RECV_MSG_SIZE",
Value: "8",
},
},
ExpectedMissing: []core.EnvVar{},
},
}

for _, tc := range tcs {
Expand Down
2 changes: 2 additions & 0 deletions charts/kuberpult/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ frontend:
batchClient:
# This value needs to be higher than the network timeout for git
timeout: 2m
# The maximum message size in mega bytes the client can receive.
grpcMaxRecvMsgSize: 4
rollout:
enabled: false
image: kuberpult-rollout-service
Expand Down
1 change: 1 addition & 0 deletions docker-compose-earthly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ services:
- KUBERPULT_API_ENABLE_DESPITE_NO_AUTH=true
- KUBERPULT_BATCH_CLIENT_TIMEOUT=2m
- KUBERPULT_DEX_RBAC_POLICY_PATH=/etc/policy.csv
- KUBERPULT_GRPC_MAX_RECV_MSG_SIZE=8
ports:
- "8081:8081"
depends_on:
Expand Down
4 changes: 4 additions & 0 deletions services/frontend-service/pkg/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import (
var c config.ServerConfig
var backendServiceId string = ""

const megaBytes int = 1024 * 1024

func getBackendServiceId(c config.ServerConfig, ctx context.Context) string {
if c.GKEBackendServiceID == "" && c.GKEBackendServiceName == "" {
logger.FromContext(ctx).Warn("gke environment variables are not set up correctly! missing backend_service_id or backend_service_name")
Expand Down Expand Up @@ -155,6 +157,7 @@ func runServer(ctx context.Context) error {
logger.FromContext(ctx).Info("config.gke_project_number: " + c.GKEProjectNumber + "\n")
logger.FromContext(ctx).Info("config.gke_backend_service_id: " + c.GKEBackendServiceID + "\n")
logger.FromContext(ctx).Info("config.gke_backend_service_name: " + c.GKEBackendServiceName + "\n")
logger.FromContext(ctx).Info(fmt.Sprintf("config.grpc_max_recv_msg_size: %d", c.GrpcMaxRecvMsgSize*megaBytes))

if c.GKEProjectNumber != "" {
backendServiceId = getBackendServiceId(c, ctx)
Expand Down Expand Up @@ -260,6 +263,7 @@ func runServer(ctx context.Context) error {
gsrv := grpc.NewServer(
grpc.ChainStreamInterceptor(grpcStreamInterceptors...),
grpc.ChainUnaryInterceptor(grpcUnaryInterceptors...),
grpc.MaxRecvMsgSize(c.GrpcMaxRecvMsgSize*megaBytes),
)
cdCon, err := grpc.Dial(c.CdServer, grpcClientOpts...)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions services/frontend-service/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type ServerConfig struct {
MaxWaitDuration time.Duration `default:"10m" split_words:"true"`
ApiEnableDespiteNoAuth bool `default:"false" split_words:"true"`
IapEnabled bool `default:"false" split_words:"true"`
GrpcMaxRecvMsgSize int `default:"4" split_words:"true"`
}

type FrontendConfig struct {
Expand Down

0 comments on commit 750ea74

Please sign in to comment.