Skip to content

Conversation

ardatan
Copy link
Member

@ardatan ardatan commented Oct 10, 2025

Implementation of Timeout in #317
This also adds subgraphs and all options to traffic_shaping as in Apollo Router. So subgraph specific configuration can be done with subgraphs;

Apollo Router -> https://www.apollographql.com/docs/graphos/routing/performance/traffic-shaping#configuration

traffic_shaping:
   all:
      timeout:
         duration: 5s
   subgraphs:
       products:
           timeout:
                expression: |
                   if (.request.operation.kind == "mutation") {
                        10000
                    } else {
                        5000
                    }

Notes:

  • I found out that tokio's timeout works as expected. But let me know if this is not the right way. Also let me know if dynamic timeout expression implementation is good for you.
  • I also switched to the executor wrapping approach here --> 911142d

Copy link

github-actions bot commented Oct 10, 2025

k6-benchmark results

     ✓ response code was 200
     ✓ no graphql errors
     ✓ valid response structure

     █ setup

     checks.........................: 100.00% ✓ 237942      ✗ 0    
     data_received..................: 7.0 GB  232 MB/s
     data_sent......................: 93 MB   3.1 MB/s
     http_req_blocked...............: avg=3.62µs   min=661ns  med=1.68µs  max=4.01ms   p(90)=2.36µs  p(95)=2.75µs  
     http_req_connecting............: avg=1.01µs   min=0s     med=0s      max=3.25ms   p(90)=0s      p(95)=0s      
     http_req_duration..............: avg=18.47ms  min=2.04ms med=17.59ms max=224.03ms p(90)=25.32ms p(95)=28.26ms 
       { expected_response:true }...: avg=18.47ms  min=2.04ms med=17.59ms max=224.03ms p(90)=25.32ms p(95)=28.26ms 
     http_req_failed................: 0.00%   ✓ 0           ✗ 79334
     http_req_receiving.............: avg=174.04µs min=24µs   med=40.06µs max=188.65ms p(90)=85.27µs p(95)=380.71µs
     http_req_sending...............: avg=22.19µs  min=5.28µs med=10.59µs max=22.85ms  p(90)=15.96µs p(95)=28.55µs 
     http_req_tls_handshaking.......: avg=0s       min=0s     med=0s      max=0s       p(90)=0s      p(95)=0s      
     http_req_waiting...............: avg=18.28ms  min=1.97ms med=17.46ms max=49.66ms  p(90)=25.08ms p(95)=27.94ms 
     http_reqs......................: 79334   2639.043156/s
     iteration_duration.............: avg=18.9ms   min=4.93ms med=17.94ms max=272.69ms p(90)=25.77ms p(95)=28.78ms 
     iterations.....................: 79314   2638.377856/s
     vus............................: 50      min=50        max=50 
     vus_max........................: 50      min=50        max=50 

Copy link

github-actions bot commented Oct 10, 2025

🐋 This PR was built and pushed to the following Docker images:

Image Names: ghcr.io/graphql-hive/router

Platforms: linux/amd64,linux/arm64

Image Tags: ghcr.io/graphql-hive/router:pr-478 ghcr.io/graphql-hive/router:sha-3535e07

Docker metadata
{
"buildx.build.ref": "builder-e245c9ad-3ca0-4cd4-9450-56f1f68fdc6f/builder-e245c9ad-3ca0-4cd4-9450-56f1f68fdc6f0/tcg5nw4ixl9l0pt8aj4zwbdrf",
"containerimage.descriptor": {
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "digest": "sha256:ca064b18f1364a6a8b62caa28762c68d3aca1fcce3b5ac09e8d7368fca3e0d5b",
  "size": 1609
},
"containerimage.digest": "sha256:ca064b18f1364a6a8b62caa28762c68d3aca1fcce3b5ac09e8d7368fca3e0d5b",
"image.name": "ghcr.io/graphql-hive/router:pr-478,ghcr.io/graphql-hive/router:sha-3535e07"
}

@ardatan
Copy link
Member Author

ardatan commented Oct 10, 2025

@gemini-code-assist review and summary

@ardatan ardatan requested a review from Copilot October 10, 2025 15:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements timeout configuration for subgraph requests, adding support for both fixed duration timeouts and dynamic expression-based timeouts using VRL (Vector Remap Language). The implementation also restructures the traffic shaping configuration to support global defaults and per-subgraph overrides, following Apollo Router's pattern.

Key changes:

  • Added timeout configuration with support for fixed durations and VRL expressions
  • Restructured traffic shaping config to support all (global) and subgraphs (per-subgraph) configurations
  • Implemented timeout execution using tokio::time::timeout

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/router-config/src/traffic_shaping.rs Added HTTPTimeoutConfig enum and timeout field to TrafficShapingExecutorConfig
lib/router-config/src/lib.rs Restructured traffic shaping config with TrafficShapingConfig wrapper
lib/executor/src/executors/timeout.rs New module implementing timeout logic with VRL expression support
lib/executor/src/executors/mod.rs Added timeout module export
lib/executor/src/executors/map.rs Updated executor map creation to handle per-subgraph configurations
lib/executor/src/executors/http.rs Integrated timeout functionality into HTTP executor
lib/executor/src/executors/error.rs Added RequestTimeout error variant
lib/executor/src/executors/common.rs Added client_request field to HttpExecutionRequest
lib/executor/src/execution/plan.rs Updated request creation to include client_request
docs/README.md Updated documentation to reflect new configuration structure

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable feature for configuring timeouts on subgraph requests, both globally and on a per-subgraph basis. The implementation correctly uses tokio::time::timeout for handling timeouts and VRL expressions for dynamic timeout values. The configuration structure is well-designed, allowing for flexible overrides. My review includes suggestions to correct the documentation examples to align with the implementation, prevent a potential panic when handling negative timeout values from VRL expressions, and an optimization for resource usage related to request deduplication maps.

ardatan and others added 7 commits October 10, 2025 18:15
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ardatan ardatan requested a review from Copilot October 10, 2025 15:19
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

lib/executor/src/executors/timeout.rs:1

  • Corrected 'type' to 'kind' to match the actual field name in OperationDetails.
use std::collections::BTreeMap;

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ardatan
Copy link
Member Author

ardatan commented Oct 10, 2025

@gemin-code-assist review again

@ardatan ardatan marked this pull request as ready for review October 10, 2025 15:23
@ardatan ardatan marked this pull request as draft October 10, 2025 15:23
@ardatan ardatan marked this pull request as ready for review October 12, 2025 08:57
@ardatan
Copy link
Member Author

ardatan commented Oct 12, 2025

@gemini-code-assist review again

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a powerful timeout configuration feature for subgraphs, including support for dynamic timeouts using VRL expressions. The implementation is solid, using the decorator pattern to wrap executors with timeout logic. The configuration is also well-structured, allowing for both global and per-subgraph settings, similar to Apollo Router.

My review focuses on improving the documentation to make these new features clearer to users and suggests a couple of small enhancements for better flexibility and efficiency. Overall, this is a great addition.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant