Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a JSON manipulation plugin stage #5865

Draft
wants to merge 23 commits into
base: dev
Choose a base branch
from
Draft

Conversation

Geal
Copy link
Contributor

@Geal Geal commented Aug 22, 2024

Note: I am asking for an early review of this before going through all the relevant API, docs, test work to make this production ready, so we can discuss first if the pipeline changes described below make sense, or if some of them should be moved elsewhere

this stage sits between the router stage and supergraph stage, and allows request and response manipulation in JSON format, without needing explicit buffering and deserialization at the router stage, and working with data that does not serialize cleanly to GraphQL requests and response objects.

This change will only add the new stage with a private plugin part. The public plugin, rhai and coprocessor usage will come as a follow up.

Notable changes:

  • batching is now handled at the JSON stage. This is a bit easier to handle since it is directly working on JSON values. Batching has been updated to use serde_json_bytes::Value natively instead of the similar type from serde_json
  • operations transmitted in the query string are transformed to a JSON body at the router service level, to make sure that JSON service plugins are always working with JSON bodies (in the future, headers would not be relevant anymore at that stage)
  • the multipart protocol needs to work on JSON values now instead of GraphQL response objects. This makes it a bit more brittle
  • APQ and persisted queries are now executed in the JSON service. They could be moved to a JSON service plugin
  • query analysis now runs in the JSON service. That means that the query will be modifiable by users (once we add a plugin/rhai/coprocessor step) before going through validation, without having to deserialize and reserialize a JSON request
  • this will probably have some latency overhead, because instead of going directly between bytes and GraphQL request/response objects, we go through a JSON value. Probably low overhead on the request side, and we should check on the response side if we can reduce it, because most of the data will already be in the form of a JSON value

Questions that we should ask:

  • are the different tasks performed at the right point? (especially query string parsing and batching)
  • which plugins should be moved from supergraph service to JSON service?
  • what do we need in the request and response API at that level?
  • the fact that this passes existing tests is a good sign, but are there more tests that we culd add to validate the interaction between router service, JSON service and supergraph service?
  • is JsonServerService the right name for it?

Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Tests added and passing3
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

this stage will sit between the router stage and supergraph stage, and allow request and response manipulation in JSON format, without needing explicit buffering and deserialization at the router stage, and working with data that does not serialize cleanly to GraphQL requests and response objects.
Copy link
Contributor

@Geal, please consider creating a changeset entry in /.changesets/. These instructions describe the process and tooling.

@router-perf
Copy link

router-perf bot commented Aug 22, 2024

CI performance tests

  • const - Basic stress test that runs with a constant number of users
  • demand-control-instrumented - A copy of the step test, but with demand control monitoring and metrics enabled
  • demand-control-uninstrumented - A copy of the step test, but with demand control monitoring enabled
  • enhanced-signature - Enhanced signature enabled
  • events - Stress test for events with a lot of users and deduplication ENABLED
  • events_big_cap_high_rate - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity
  • events_big_cap_high_rate_callback - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity using callback mode
  • events_callback - Stress test for events with a lot of users and deduplication ENABLED in callback mode
  • events_without_dedup - Stress test for events with a lot of users and deduplication DISABLED
  • events_without_dedup_callback - Stress test for events with a lot of users and deduplication DISABLED using callback mode
  • extended-reference-mode - Extended reference mode enabled
  • large-request - Stress test with a 1 MB request payload
  • no-tracing - Basic stress test, no tracing
  • reload - Reload test over a long period of time at a constant rate of users
  • step-jemalloc-tuning - Clone of the basic stress test for jemalloc tuning
  • step-local-metrics - Field stats that are generated from the router rather than FTV1
  • step-with-prometheus - A copy of the step test with the Prometheus metrics exporter enabled
  • step - Basic stress test that steps up the number of users over time
  • xlarge-request - Stress test with 10 MB request payload
  • xxlarge-request - Stress test with 100 MB request payload

@Geal Geal marked this pull request as ready for review August 26, 2024 10:27
@Geal Geal requested review from a team as code owners August 26, 2024 10:27
Comment on lines +112 to +117
|| response
.as_object()
.and_then(|o| o.get("payload"))
.and_then(|v| v.as_object())
.map(|o| !o.is_empty())
.unwrap_or(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it won't work, it's more complicated than this IIRC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you see cases where it would fail, that I could add to unit tests?

Comment on lines +129 to +139
&& response
.as_object()
.and_then(|o| o.get("payload"))
.and_then(|v| v.as_object())
.is_none()
&& response
.as_object()
.and_then(|o| o.get("errors"))
.and_then(|v| v.as_array())
.map(|v| v.is_empty())
.unwrap_or(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here. I think we make a difference between Some(Null) and None

_ => response.into(),
},
};
serde_json_bytes::to_value(r).unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use expect

@Geal Geal marked this pull request as draft September 16, 2024 08:44
@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Nov 18, 2024

✅ Docs Preview Ready

No new or changed pages found.

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.

3 participants