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 better context config for coprocessor to help migration #6752

Merged
merged 17 commits into from
Feb 12, 2025
Merged

Conversation

bnjjj
Copy link
Contributor

@bnjjj bnjjj commented Feb 10, 2025

Context configuration

You can configure what you want to send from the context to your coprocessor. By default it's disabled (false) and doesn't send any context keys to the coprocessor. You now have the ability to give an array
containing all the context keys you want to send to your coprocessor. Sending only a selective list of context keys will increase the performances because it will lower the size of payloads between the router and coprocessor.
You can also set context: deprecated if you still want to use deprecated context key names from router 1.x. If you want to pass all context keys with new naming just set context: all.

Example:

coprocessor:
  url: http://127.0.0.1:3000 # mandatory URL which is the address of the coprocessor
  supergraph:
    request:
      headers: true
      context: # It will only send these 2 context keys to your coprocessor
        selective:
          - apollo::supergraph::operation_name
          - apollo::demand_control::actual_cost
      body: true
    response:
      headers: true
      context: all # It will send all context keys with new names (2.x version)
      body: true
  subgraph:
    all:
      request:
        context: deprecated # It will send all the context keys with deprecated names (1.x version)

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.

bnjjj added 6 commits February 4, 2025 11:50
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
@bnjjj bnjjj requested review from a team as code owners February 10, 2025 10:09
@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Feb 10, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 1 changed, 0 removed
* graphos/reference/upgrade/from-router-v1.mdx

Build ID: 737f6a158aa049d92b86fcd3

URL: https://www.apollographql.com/docs/deploy-preview/737f6a158aa049d92b86fcd3

Copy link
Contributor

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

Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
@lennyburdette
Copy link
Contributor

👍🏻 to this idea — we added a connectors-specific config option to do something similar: https://github.com/apollographql/router/blob/dev/apollo-router/src/plugins/connectors/configuration.rs#L43

should we remove that option in favor of this approach?

@bnjjj
Copy link
Contributor Author

bnjjj commented Feb 10, 2025

@lennyburdette good catch ! I think yes that would probably be enough to just include the context key in the coprocessor config. But for now the default config is to pass all context keys. Could it be an issue if your connector keys are passed by default ?

@lennyburdette
Copy link
Contributor

we add the key only if you set that connectors-specific config value: https://github.com/apollographql/router/blob/dev/apollo-router/src/plugins/connectors/plugin.rs#L147-L175 ... we could switch this logic to read from your new config?

@theJC
Copy link
Contributor

theJC commented Feb 11, 2025

I like this idea, but I would argue that a prerequisite would be for Apollo to supply a compendium/reference of all possible context keys in the Router documentation for your customers, so they know what context keys they can choose from.

A list was added to the docs in docs/source/routing/customization/overview.mdx in this MR: https://github.com/apollographql/router/pull/6572/files#diff-e95018a62736abd100a39b77182d90ffa70565ec35cad5cb0cd366b1535f306a

But then subsequent document updates seemed to have removed it.

Copy link
Contributor

@garypen garypen left a comment

Choose a reason for hiding this comment

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

General Comment:

I don't like having DEPRECATED const values scattered around the code base. I'd prefer if they were isolated to a single deprecated source file.

I have a question about the selective option. Does it only work with "new" names or can you use "deprecated" names? Also, is it possible to mix and match them within the same array? Would this lead to duplication and confusion?

Co-authored-by: Gary Pennington <gary@apollographql.com>
@bnjjj
Copy link
Contributor Author

bnjjj commented Feb 11, 2025

@garypen

I have a question about the selective option. Does it only work with "new" names or can you use "deprecated" names? Also, is it possible to mix and match them within the same array? Would this lead to duplication and confusion?

No it's only new names

Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
@bnjjj
Copy link
Contributor Author

bnjjj commented Feb 11, 2025

Good catch @theJC I added back the docs for context keys you linked

@bnjjj
Copy link
Contributor Author

bnjjj commented Feb 11, 2025

@lennyburdette if it's an opt-in option that's even better. I think you're right it should check the new configuration for context and add it if it's included in the context keys list

@bnjjj
Copy link
Contributor Author

bnjjj commented Feb 11, 2025

@garypen I agree with you about the deprecated context keys. I think it's better to put everything into the same module/file. Can we just consider doing this in a follow up PR ?

@garypen
Copy link
Contributor

garypen commented Feb 11, 2025

@garypen I agree with you about the deprecated context keys. I think it's better to put everything into the same module/file. Can we just consider doing this in a follow up PR ?

It could be done in a follow-up.

@garypen
Copy link
Contributor

garypen commented Feb 11, 2025

@garypen

I have a question about the selective option. Does it only work with "new" names or can you use "deprecated" names? Also, is it possible to mix and match them within the same array? Would this lead to duplication and confusion?

No it's only new names

We should document that clearly.

Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
@bnjjj
Copy link
Contributor Author

bnjjj commented Feb 11, 2025

@garypen Added in 05bc550

@bnjjj bnjjj requested a review from garypen February 11, 2025 11:43
@goto-bus-stop
Copy link
Member

Is/should this also be available for Rhai scripts?

@bnjjj
Copy link
Contributor Author

bnjjj commented Feb 12, 2025

@goto-bus-stop Yes but we will do this in a followup PR because it's taking more time. And I think it's also easier to spot in a rhai script when you're using a deprecated key

Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
@bnjjj bnjjj merged commit 2b7cca0 into dev Feb 12, 2025
15 checks passed
@bnjjj bnjjj deleted the bnjjj/feat_1011 branch February 12, 2025 10:33
@theJC
Copy link
Contributor

theJC commented Feb 14, 2025

While focusing on optimizing the performance/efficiency of communicating with the coprocessor, can I please put a bug in your ear regarding looking into the possibility of adding Unix Domain socket support for communicating with coprocessor (#5739)

Potentially better long term might be looking into the viability of refactoring/DRYing as much as possible of the httpclientservice used for outbound calls to subgraphs and the similar/duplicative work done for outbound calls for the coprocessor. That way advances/improvements/changes/observability there are available and leveraged for both pieces of communication (as well as hopefully sharing common configuration)

Not having this consistent/common between these areas causes and will continue to cause additional efforts and asks from your customers to get them aligned as well as duplicative work for you.

Several examples of efforts and asks to get coprocessor calling caught up with subgraph calling capabilities:

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.

6 participants