feat: add max message size flag for gRPC server configuration#32
feat: add max message size flag for gRPC server configuration#32
Conversation
Introduce a `--max-msg-size` flag to configure the maximum gRPC message size for both receiving and sending. This enhances flexibility and prevents runtime issues with oversized messages by allowing customization through the command line. Defaults to 4MB if unspecified.
WalkthroughThe changes introduce a new integer variable Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant CP as Command Parser
participant GS as gRPC Server
U->>CP: Provide CLI flag (--max-msg-size)
CP->>CP: Parse the --max-msg-size flag
CP->>GS: Configure gRPC server with maxMsgSize
GS-->>U: gRPC server operates with updated message size limits
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
cmd/evm-middleware/commands/run.go (1)
39-39: Add validation and improve documentation for the max-msg-size flag.While the flag implementation is good, consider these improvements:
- Add validation to prevent negative or extremely large values
- Document the recommended range in the flag description
- runCmd.Flags().IntVar(&maxMsgSize, "max-msg-size", 4*1024*1024, "Maximum message size for gRPC connections (in bytes)") // New flag for maxMsgSize + runCmd.Flags().IntVar(&maxMsgSize, "max-msg-size", 4*1024*1024, "Maximum message size for gRPC connections (in bytes, default: 4MB, recommended range: 1MB-64MB)") + if err := runCmd.MarkFlagRequired("max-msg-size"); err != nil { + log.Fatalf("Error marking flag 'max-msg-size' as required: %v", err) + } + if err := runCmd.Flags().Lookup("max-msg-size").Value.(*pflag.IntValue).ValidateFuncs.Add(func(value pflag.Value) error { + v := value.(*pflag.IntValue).Get() + if v <= 0 { + return fmt.Errorf("max-msg-size must be positive") + } + if v > 64*1024*1024 { // 64MB + return fmt.Errorf("max-msg-size exceeds recommended maximum of 64MB") + } + return nil + }); err != nil { + log.Fatalf("Error adding validation for 'max-msg-size': %v", err) + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
cmd/evm-middleware/commands/run.go(3 hunks)
🔇 Additional comments (2)
cmd/evm-middleware/commands/run.go (2)
26-26: LGTM! Variable declaration follows Go conventions.The
maxMsgSizevariable is appropriately declared as an integer and consistently placed with other configuration variables.
75-78: LGTM! gRPC server configuration is properly implemented.The
maxMsgSizeflag value is correctly applied to both receive and send message size limits using the appropriate gRPC server options.
Overview
Introduce a
--max-msg-sizeflag to configure the maximum gRPC message size for both receiving and sending. This enhances flexibility and prevents runtime issues with oversized messages by allowing customization through the command line. Defaults to 4MB if unspecified.Resolves #31
Summary by CodeRabbit