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

Include request variables in demand control scoring #5995

Merged
merged 4 commits into from
Sep 13, 2024

Conversation

tninesling
Copy link
Contributor

We're missing variable support in demand control scoring, so they're currently not counted. Additionally, they don't get passed through to the list size directive, which prevents users from using variables as slicing arguments. This change includes the request variables in context extensions so they can be accessed from the demand control plugin pipeline.

This includes a small refactor to wrap some of the common scoring arguments (schema, request document, etc) into a scoring context to reduce the number of arguments to each function.


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.

@tninesling tninesling requested review from a team as code owners September 11, 2024 19:17

This comment has been minimized.

@router-perf
Copy link

router-perf bot commented Sep 11, 2024

CI performance tests

  • connectors-const - Connectors stress test that runs with a constant number of users
  • 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

Value::Null => apollo_compiler::ast::Value::Null,
Value::Bool(b) => apollo_compiler::ast::Value::Boolean(*b),
Value::Number(n) => {
if n.is_f64() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way to do this conversion? This inner n is private so it's not so easy to cleanly convert it to the underlying numeric type.

Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative is:

            Value::Number(n) if n.is_f64() => {
                apollo_compiler::ast::Value::Float(n.as_f64().expect("is float").into())
            }

            Value::Number(n) => {
                apollo_compiler::ast::Value::Int((n.as_i64().expect("is int") as i32).into())
            }

.with_lock(|mut lock| lock.insert(strategy.clone()));
req.context.extensions().with_lock(|mut lock| {
lock.insert(strategy.clone());
lock.insert(req.supergraph_request.body().variables.clone());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is going to insert an entry of type Map<ByteString, Value> into the context. This type is used both for graphql request variables and graphql response extensions. Should we create some wrapper type to make sure it's disambiguated in context?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm not sure about doing this. Gonna take a look and see if there is something better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree that a wrapper type needs to be used. Maybe also include cost strategy in it so there is just one entry?

I spent a bit of time trying to figure out why we need variables for the response. This is because input fields can have a cost directive right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we need to include argument cost for a field when scoring responses, and we can't score arguments purely from the schema because we may over/under count optional fields.

@tninesling tninesling requested a review from a team as a code owner September 11, 2024 19:40
Copy link
Contributor

@BrynCooke BrynCooke left a comment

Choose a reason for hiding this comment

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

Needs a wrapper for variables in context.

@tninesling tninesling merged commit 91375ed into dev Sep 13, 2024
14 checks passed
@tninesling tninesling deleted the tninesling/demand-control-variable-check branch September 13, 2024 16:46
@abernix abernix mentioned this pull request Sep 24, 2024
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