Skip to content

chore(testkit): use Arc and DashMap instead of Mutex and HashMap#658

Merged
dotansimha merged 4 commits intomainfrom
simplify_bench_tool
Jan 13, 2026
Merged

chore(testkit): use Arc and DashMap instead of Mutex and HashMap#658
dotansimha merged 4 commits intomainfrom
simplify_bench_tool

Conversation

@ardatan
Copy link
Member

@ardatan ardatan commented Jan 12, 2026

Extracted from #628

  • SubgraphServiceState is cloned together with a Mutex<HashMap< in it so instead I made it Arc, and DashMap inside of it so no need to deal with Mutex etc. And Arc<DashMap< is easier to maintain rather than dealing with lock etc in different places. It will be more future-proof since we consider exporting the testkit for public usage in the future(probably for the plugin system).

  • The other part of changes -> In case of a invalid JSON response from the router, extract_record was failing with a parser error while tracking requests which was leading an invalid result at the end, but now it sets an empty response data.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ardatan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the SubgraphServiceState in the testkit to enhance its concurrency model. By replacing Arc<Mutex<HashMap>> with DashMap, the changes aim to improve performance and simplify the management of shared request logs. Additionally, it introduces more robust handling for potentially malformed JSON request bodies.

Highlights

  • Concurrency Model Refinement: Replaced Arc<Mutex<HashMap>> with DashMap for managing request_log within SubgraphsServiceState, simplifying concurrent access and removing the need for explicit mutex locking.
  • State Management Update: The SubgraphsServiceState struct is now directly wrapped in an Arc, aligning with the new concurrency approach and improving its shareability.
  • Dependency Update: Added the dashmap crate as a dependency to enable the use of the concurrent hash map.
  • Robust JSON Parsing: Improved error handling for JSON body parsing in the extract_record function, gracefully defaulting to an empty Value if the request body is not valid JSON.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 refactors the testkit's subgraph service to use Arc<SubgraphsServiceState> with a DashMap for logging requests, replacing the previous Mutex<HashMap> implementation, which improves concurrency and simplifies request tracking. Crucially, this change also remediates a medium-severity Denial of Service (DoS) vulnerability where the service could panic and crash due to an unsafe .unwrap() call when processing malformed JSON bodies; the fix introduces proper error handling. While the use of unwrap_or further enhances robustness, a high-severity issue regarding potential unbounded memory growth in the request log has been identified, violating the repository's style guide.

@github-actions
Copy link

github-actions bot commented Jan 12, 2026

k6-benchmark results

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

     █ setup

     checks.........................: 100.00% ✓ 241287      ✗ 0    
     data_received..................: 7.0 GB  234 MB/s
     data_sent......................: 94 MB   3.1 MB/s
     http_req_blocked...............: avg=3.26µs   min=651ns   med=1.66µs  max=5.09ms   p(90)=2.25µs  p(95)=2.56µs  
     http_req_connecting............: avg=693ns    min=0s      med=0s      max=2.07ms   p(90)=0s      p(95)=0s      
     http_req_duration..............: avg=18.2ms   min=1.79ms  med=17.27ms max=120.59ms p(90)=25.06ms p(95)=28.21ms 
       { expected_response:true }...: avg=18.2ms   min=1.79ms  med=17.27ms max=120.59ms p(90)=25.06ms p(95)=28.21ms 
     http_req_failed................: 0.00%   ✓ 0           ✗ 80449
     http_req_receiving.............: avg=129.54µs min=22.07µs med=37.2µs  max=45.76ms  p(90)=88.66µs p(95)=365.82µs
     http_req_sending...............: avg=24.41µs  min=4.81µs  med=10.2µs  max=20.4ms   p(90)=15.36µs p(95)=28.84µs 
     http_req_tls_handshaking.......: avg=0s       min=0s      med=0s      max=0s       p(90)=0s      p(95)=0s      
     http_req_waiting...............: avg=18.05ms  min=1.73ms  med=17.15ms max=120.24ms p(90)=24.82ms p(95)=27.92ms 
     http_reqs......................: 80449   2676.510028/s
     iteration_duration.............: avg=18.64ms  min=4.5ms   med=17.62ms max=224.67ms p(90)=25.53ms p(95)=28.68ms 
     iterations.....................: 80429   2675.844635/s
     vus............................: 50      min=50        max=50 
     vus_max........................: 50      min=50        max=50 

@github-actions
Copy link

🐋 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-658 ghcr.io/graphql-hive/router:sha-9c6ab9e

Docker metadata
{
"buildx.build.ref": "builder-0aeb9897-f336-445b-91c1-fe5772d073c9/builder-0aeb9897-f336-445b-91c1-fe5772d073c90/t3k9eej0eyorffs8tj2gelg7o",
"containerimage.descriptor": {
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "digest": "sha256:bdafcbde6cc0010b425d3722f36ba1b7e55c7162ab9d09f45ecc8add9630c2b9",
  "size": 1609
},
"containerimage.digest": "sha256:bdafcbde6cc0010b425d3722f36ba1b7e55c7162ab9d09f45ecc8add9630c2b9",
"image.name": "ghcr.io/graphql-hive/router:pr-658,ghcr.io/graphql-hive/router:sha-9c6ab9e"
}

Copy link
Member

@dotansimha dotansimha left a comment

Choose a reason for hiding this comment

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

@ardatan can you please elaborate on the need? I mean, it's all in the test kit and I'm not sure what's the benefit here?

@ardatan
Copy link
Member Author

ardatan commented Jan 13, 2026

@dotansimha I added more sentences to the description. I hope it makes sense. There is no huge benefit. It looks just better to avoid maintaining Mutex and cloning structs etc.

@dotansimha
Copy link
Member

@dotansimha I added more sentences to the description. I hope it makes sense. There is no huge benefit. It looks just better to avoid maintaining Mutex and cloning structs etc.

Thanks! Approved

@dotansimha dotansimha merged commit 6e7e9dd into main Jan 13, 2026
22 checks passed
@dotansimha dotansimha deleted the simplify_bench_tool branch January 13, 2026 13:51
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.

2 participants