Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Allow grpc option tweaking, i.e. keepalive settings#359

Merged
NickCao merged 1 commit intomainfrom
grpc-keepalive-settings
Mar 19, 2025
Merged

Allow grpc option tweaking, i.e. keepalive settings#359
NickCao merged 1 commit intomainfrom
grpc-keepalive-settings

Conversation

@mangelajo
Copy link
Copy Markdown
Member

@mangelajo mangelajo commented Mar 19, 2025

Summary by CodeRabbit

  • New Features
    • Added configurable options for gRPC connections, including optimized keepalive settings to enhance connection stability.
    • Introduced grpcConfig and grpcOptions parameters for both clients and exporters to expand configuration capabilities.
  • Documentation
    • Updated configuration guides to include the new grpcConfig and grpcOptions parameters for both clients and exporters.
  • Tests
    • Modified test setups to validate the enhanced gRPC configuration options, including the new grpcOptions field.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2025

Walkthrough

The changes introduce customizable gRPC options in the documentation and codebase. A new YAML section with a grpcConfig key is added to the documentation, while the client and exporter configuration classes now include grpcOptions attributes. Function signatures across various modules are updated to accept a new grpc_options parameter. The default gRPC keepalive time is changed from 350000 to 20000 milliseconds, and a helper function is added to merge default and custom gRPC options.

Changes

File(s) Summary of Changes
docs/source/cli/clients.md, docs/source/introduction/exporters.md Added new grpcConfig section with grpc.keepalive_time_ms: 20000 in YAML configuration.
packages/jumpstarter/jumpstarter/client/lease.py, packages/jumpstarter/jumpstarter/common/streams.py Updated function signatures to include/pass the grpc_options parameter for gRPC connectivity.
packages/jumpstarter/jumpstarter/common/grpc.py Modified aio_secure_channel to accept grpc_options, added _override_default_grpc_options to merge options, updated default keepalive time from 350000ms to 20000ms, and included debug print/ValueError artifacts.
packages/jumpstarter/jumpstarter/config/client.py, packages/jumpstarter/jumpstarter/config/client_config_test.py Introduced a new attribute grpcOptions in client configurations and updated test configurations with a default empty dictionary.
packages/jumpstarter/jumpstarter/config/exporter.py, packages/jumpstarter/jumpstarter/exporter/exporter.py Added a new attribute (grpcOptions/grpc_options) in exporter configurations and class; updated methods to pass these gRPC options.

Sequence Diagram(s)

sequenceDiagram
    participant ClientConfig
    participant Lease
    participant Streams
    participant GRPC
    ClientConfig->>Lease: request_lease_async(grpcOptions)
    Lease->>Streams: connect_router_stream(endpoint, token, tls_config, grpc_options)
    Streams->>GRPC: aio_secure_channel(target, credentials, grpc_options)
    GRPC->>GRPC: _override_default_grpc_options(grpc_options)
    GRPC-->>Streams: secure channel established
    Streams-->>Lease: router stream connected
    Lease-->>ClientConfig: lease established
Loading
sequenceDiagram
    participant ExporterConfig
    participant Exporter
    participant Streams
    participant GRPC
    ExporterConfig->>Exporter: serve(grpcOptions)
    Exporter->>Streams: connect_router_stream(endpoint, token, tls_config, grpc_options)
    Streams->>GRPC: aio_secure_channel(target, credentials, grpc_options)
    GRPC->>GRPC: _override_default_grpc_options(grpc_options)
    GRPC-->>Streams: secure channel established
    Streams-->>Exporter: stream connected
Loading

Possibly related PRs

  • Microshift bootc image jumpstarter#314: The changes in this PR are related as both involve modifications to the aio_secure_channel function in packages/jumpstarter/jumpstarter/common/grpc.py, specifically regarding gRPC keepalive settings, although they introduce different configurations.

Poem

Oh, what hops these changes bring,
With gRPC options we now sing.
YAML and classes dance in tune,
Defaults set by the carrot moon.
CodeRabbit hops through every byte,
Leaping joyfully into the night!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 100f1ea and f9dbbad.

📒 Files selected for processing (9)
  • docs/source/cli/clients.md (1 hunks)
  • docs/source/introduction/exporters.md (1 hunks)
  • packages/jumpstarter/jumpstarter/client/lease.py (3 hunks)
  • packages/jumpstarter/jumpstarter/common/grpc.py (2 hunks)
  • packages/jumpstarter/jumpstarter/common/streams.py (1 hunks)
  • packages/jumpstarter/jumpstarter/config/client.py (4 hunks)
  • packages/jumpstarter/jumpstarter/config/client_config_test.py (3 hunks)
  • packages/jumpstarter/jumpstarter/config/exporter.py (2 hunks)
  • packages/jumpstarter/jumpstarter/exporter/exporter.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
  • docs/source/introduction/exporters.md
  • docs/source/cli/clients.md
  • packages/jumpstarter/jumpstarter/config/exporter.py
  • packages/jumpstarter/jumpstarter/common/streams.py
  • packages/jumpstarter/jumpstarter/config/client_config_test.py
  • packages/jumpstarter/jumpstarter/exporter/exporter.py
  • packages/jumpstarter/jumpstarter/client/lease.py
  • packages/jumpstarter/jumpstarter/common/grpc.py
  • packages/jumpstarter/jumpstarter/config/client.py
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: e2e
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-utils Dockerfile.utils)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 19, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit f9dbbad
🔍 Latest deploy log https://app.netlify.com/sites/jumpstarter-docs/deploys/67db32121fe825000873cea1
😎 Deploy Preview https://deploy-preview-359--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mangelajo mangelajo requested a review from NickCao March 19, 2025 16:33
@mangelajo mangelajo force-pushed the grpc-keepalive-settings branch from 347ba22 to 7478daa Compare March 19, 2025 16:34
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

🧹 Nitpick comments (3)
packages/jumpstarter/jumpstarter/config/client.py (1)

51-51: Added gRPC configuration options to ClientConfig.

The grpcOptions field allows users to configure gRPC parameters through client configuration. Note that the type allows for None values, which differs from other implementations in the codebase.

Consider using a consistent approach for nullable vs. non-nullable fields across the codebase. Since you're using default_factory=dict, the None case might be unnecessary.

-    grpcOptions: dict[str, Any] | None = Field(default_factory=dict)
+    grpcOptions: dict[str, Any] = Field(default_factory=dict)
packages/jumpstarter/jumpstarter/exporter/exporter.py (1)

29-29: Type inconsistency in gRPC options.

The grpc_options attribute is typed as dict[str, str] here, but as dict[str, Any] in Lease class. This inconsistency might cause issues if gRPC options need non-string values.

Consider using a consistent type definition across the codebase:

-    grpc_options: dict[str, str] = field(default_factory=dict)
+    grpc_options: dict[str, Any] = field(default_factory=dict)

This would require adding from typing import Any to the imports.

packages/jumpstarter/jumpstarter/common/streams.py (1)

35-35: Missing type hint for gRPC options.

The function signature has been updated to include the grpc_options parameter, but no type hint is provided.

Consider adding a type hint for the grpc_options parameter for consistency and better code documentation:

- async def connect_router_stream(endpoint, token, stream, tls_config, grpc_options):
+ async def connect_router_stream(endpoint, token, stream, tls_config, grpc_options: dict[str, Any]):

This would require adding from typing import Any to the imports.

🛑 Comments failed to post (2)
packages/jumpstarter/jumpstarter/common/grpc.py (2)

47-61: ⚠️ Potential issue

Critical error: Debugging code will prevent normal execution.

There's a raise ValueError(options) statement on line 57 that will always throw an exception, breaking the function. Additionally, print statements after this line are unreachable.

def _override_default_grpc_options(grpc_options: dict[str, Any] | None) -> Sequence[Tuple[str, Any]]:
    defaults = (
        ("grpc.lb_policy_name", "round_robin"),
        # we keep a low keepalive time to avoid idle timeouts on cloud load balancers
        ("grpc.keepalive_time_ms", 20000),
        ("grpc.keepalive_timeout_ms", 5000),
        ("grpc.http2.max_pings_without_data", 5),
        ("grpc.keepalive_permit_without_calls", 1),
    )
    options = dict(defaults, **(grpc_options or {}))
-   raise ValueError(options)
-   print("grpc_options", grpc_options)
-   print(options)
    return tuple(options.items())
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

def _override_default_grpc_options(grpc_options: dict[str, Any] | None) -> Sequence[Tuple[str, Any]]:
    defaults = (
        ("grpc.lb_policy_name", "round_robin"),
        # we keep a low keepalive time to avoid idle timeouts on cloud load balancers
        ("grpc.keepalive_time_ms", 20000),
        ("grpc.keepalive_timeout_ms", 5000),
        ("grpc.http2.max_pings_without_data", 5),
        ("grpc.keepalive_permit_without_calls", 1),
    )
    options = dict(defaults, **(grpc_options or {}))
    return tuple(options.items())

56-56: 🛠️ Refactor suggestion

Potential issue with dictionary construction.

The current dictionary construction approach with tuple input might not work as expected. Consider using dict() conversion first.

-   options = dict(defaults, **(grpc_options or {}))
+   options = dict(defaults)
+   options.update(grpc_options or {})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    options = dict(defaults)
    options.update(grpc_options or {})

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/jumpstarter/jumpstarter/common/grpc.py (2)

56-57: Consider adding validation for critical gRPC options.

While the implementation correctly merges default and custom options, there's no validation for potentially problematic values. Consider adding checks for critical options to prevent configuration issues.

 def _override_default_grpc_options(grpc_options: dict[str, Any] | None) -> Sequence[Tuple[str, Any]]:
     defaults = (
         ("grpc.lb_policy_name", "round_robin"),
         # we keep a low keepalive time to avoid idle timeouts on cloud load balancers
         ("grpc.keepalive_time_ms", 20000),
         ("grpc.keepalive_timeout_ms", 5000),
         ("grpc.http2.max_pings_without_data", 5),
         ("grpc.keepalive_permit_without_calls", 1),
     )
+    # Merge default options with user-provided options
     options = dict(defaults, **(grpc_options or {}))
+    
+    # Validate critical options
+    if "grpc.keepalive_time_ms" in grpc_options and grpc_options["grpc.keepalive_time_ms"] < 1000:
+        raise ConfigurationError("grpc.keepalive_time_ms must be at least 1000ms")
+    
     return tuple(options.items())

38-58: Consider adding documentation for the new parameter.

The function lacks docstring documentation for the new grpc_options parameter. Consider adding documentation to help users understand what options can be passed and their format.

 def aio_secure_channel(target: str,
                        credentials: grpc.ChannelCredentials,
                        grpc_options: dict[str, Any] | None):
+    """
+    Create a secure gRPC channel with customizable options.
+    
+    Args:
+        target: The server address to connect to.
+        credentials: The credentials to use for the connection.
+        grpc_options: Optional dictionary of gRPC channel options to override defaults.
+                     Keys should be gRPC option names (e.g., "grpc.keepalive_time_ms").
+    
+    Returns:
+        A secure gRPC channel.
+    """
     return grpc.aio.secure_channel(
         target,
         credentials,
         options=_override_default_grpc_options(grpc_options),
     )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 347ba22 and 7478daa.

📒 Files selected for processing (9)
  • docs/source/cli/clients.md (1 hunks)
  • docs/source/introduction/exporters.md (1 hunks)
  • packages/jumpstarter/jumpstarter/client/lease.py (3 hunks)
  • packages/jumpstarter/jumpstarter/common/grpc.py (2 hunks)
  • packages/jumpstarter/jumpstarter/common/streams.py (1 hunks)
  • packages/jumpstarter/jumpstarter/config/client.py (4 hunks)
  • packages/jumpstarter/jumpstarter/config/client_config_test.py (3 hunks)
  • packages/jumpstarter/jumpstarter/config/exporter.py (2 hunks)
  • packages/jumpstarter/jumpstarter/exporter/exporter.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • docs/source/introduction/exporters.md
  • packages/jumpstarter/jumpstarter/config/client_config_test.py
  • docs/source/cli/clients.md
  • packages/jumpstarter/jumpstarter/client/lease.py
  • packages/jumpstarter/jumpstarter/common/streams.py
  • packages/jumpstarter/jumpstarter/config/client.py
  • packages/jumpstarter/jumpstarter/config/exporter.py
  • packages/jumpstarter/jumpstarter/exporter/exporter.py
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: e2e
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-utils Dockerfile.utils)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
🔇 Additional comments (5)
packages/jumpstarter/jumpstarter/common/grpc.py (5)

6-6: Appropriate import additions.

The additional imports from typing are necessary for the new type annotations in the updated function signatures.


38-40: Good signature update with proper type annotations.

The function signature now correctly includes the new grpc_options parameter with appropriate type annotations. Using dict[str, Any] | None allows for both passing custom options and defaulting to None when not needed.


44-44: Properly handles the new options parameter.

The implementation now correctly passes the processed options to the underlying gRPC channel.


47-58: Well-implemented helper function for gRPC options.

The _override_default_grpc_options function is a clean implementation that:

  1. Defines sensible defaults for gRPC
  2. Reduces keepalive time to 20000ms (from 350000ms) to avoid idle timeouts
  3. Correctly merges custom options with defaults
  4. Returns options in the format expected by gRPC

The change in keepalive time aligns with the PR objective to allow tweaking these settings.


50-51: Improved keepalive time for better connection stability.

Reducing the keepalive time from 350000ms to 20000ms (as indicated in the AI summary) is a good improvement to prevent cloud load balancers from dropping idle connections. The comment clearly explains the reasoning.

Comment thread packages/jumpstarter/jumpstarter/client/lease.py
Comment thread packages/jumpstarter/jumpstarter/common/grpc.py Outdated
@NickCao
Copy link
Copy Markdown
Collaborator

NickCao commented Mar 19, 2025

Also missing a call site at packages/jumpstarter/jumpstarter/config/client.py line 61.

@mangelajo
Copy link
Copy Markdown
Member Author

Also missing a call site at packages/jumpstarter/jumpstarter/config/client.py line 61.

yup, I just found from E2E, thanks :D

@mangelajo mangelajo force-pushed the grpc-keepalive-settings branch from 7478daa to 100f1ea Compare March 19, 2025 17:43
@mangelajo
Copy link
Copy Markdown
Member Author

@NickCao let's see if it's all good now.

@NickCao NickCao force-pushed the grpc-keepalive-settings branch from 100f1ea to f9dbbad Compare March 19, 2025 21:07
@NickCao NickCao enabled auto-merge March 19, 2025 21:13
@NickCao NickCao merged commit 9fef5c7 into main Mar 19, 2025
18 checks passed
@NickCao NickCao deleted the grpc-keepalive-settings branch March 31, 2025 15:44
@mangelajo mangelajo added this to the 0.6.0 milestone May 8, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Oct 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants