-
Notifications
You must be signed in to change notification settings - Fork 25
feat(gateway): add support for new Hive CDN mirror and circuit breaker #1738
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @EmrysMyrddin, 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 significantly upgrades the gateway's schema fetching capabilities by introducing support for a new Hive CDN fetcher. This enhancement includes the addition of a secondary CDN mirror for improved resilience and the integration of a circuit breaker mechanism to prevent service degradation during upstream issues. Furthermore, it ensures that all components, particularly the circuit breaker, are properly disposed of when the gateway shuts down, contributing to overall system stability. Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 support for a secondary CDN mirror and a circuit breaker for Hive, enhancing the reliability of schema fetching. The changes primarily involve refactoring the schema and supergraph fetchers to use the new createCDNArtifactFetcher and to properly handle disposal of resources, which is a great improvement for graceful shutdown. I've identified a minor bug in URL manipulation and a couple of areas where the implementation could be safer and more readable. Overall, this is a solid feature addition.
| ? url | ||
| : joinUrl( | ||
| url.endsWith('/services') | ||
| ? url.substring(0, url.length - 8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a small off-by-one error here. The length of '/services' is 9, but you are subtracting 8. This will leave a trailing slash in the URL before it's passed to joinUrl. While joinUrl might handle this gracefully, it's more precise to subtract the correct length to avoid potential issues.
| ? url.substring(0, url.length - 8) | |
| ? url.substring(0, url.length - 9) |
| ), | ||
| ); | ||
| const fetcher = createCDNArtifactFetcher({ | ||
| endpoint: endpoints as [string, string], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type assertion as [string, string] is not always correct. When a single endpoint string is provided in the configuration, the endpoints array will only contain one element. This cast can hide a type mismatch and lead to potential runtime errors if createCDNArtifactFetcher expects a tuple of two strings. A more accurate type assertion would be safer.
| endpoint: endpoints as [string, string], | |
| endpoint: endpoints as [string, ...string[]], |
| ); | ||
|
|
||
| const fetcher = createCDNArtifactFetcher({ | ||
| endpoint: endpoints as [string, string], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the other usage of createCDNArtifactFetcher, the type assertion as [string, string] is not always correct here. If a single endpoint string is provided, the endpoints array will have only one element. This could lead to runtime issues. A more accurate type assertion would be safer.
| endpoint: endpoints as [string, string], | |
| endpoint: endpoints as [string, ...string[]], |
🚀 Snapshot Release (
|
| Package | Version | Info |
|---|---|---|
@graphql-tools/batch-delegate |
10.0.6-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-tools/delegate |
12.0.0-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-tools/federation |
4.2.4-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-mesh/fusion-runtime |
1.6.0-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-hive/gateway |
2.1.20-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-hive/nestjs |
2.0.25-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-hive/plugin-aws-sigv4 |
2.0.18-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-hive/plugin-opentelemetry |
1.2.2-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-mesh/plugin-prometheus |
2.1.6-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-hive/router-runtime |
1.1.0-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-hive/gateway-runtime |
2.4.0-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-tools/stitch |
10.1.4-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-tools/stitching-directives |
4.0.6-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-hive/gateway-testing |
3.0.0-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
@graphql-tools/wrap |
11.1.0-alpha-bad695e6dd6ff62553b712e1629b8f6578032c4d |
npm ↗︎ unpkg ↗︎ |
| ); | ||
|
|
||
| const fetcher = createCDNArtifactFetcher({ | ||
| endpoint: endpoints as [string, string], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe asArray can be used here instead of casting.
| } | ||
| }, | ||
| onDispose() { | ||
| async onDispose() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| async onDispose() { | |
| onDispose() { |
| async onDispose() { | ||
| pausePolling(); | ||
| return transportExecutorStack.disposeAsync(); | ||
| await transportExecutorStack.disposeAsync(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| await transportExecutorStack.disposeAsync(); | |
| return handleMaybePromise(() => transportExecutorStack.disposeAsync(), () => schemaFetcher.dispose?.()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used async/await here because disposeAsync type advertises that it always return a Promise, so I'm not sure handleMaybePromise is needed?
🚀 Snapshot Release (Node Docker Image)The latest changes of this PR are available as image on GitHub Container Registry (based on the declared |
🚀 Snapshot Release (Bun Docker Image)The latest changes of this PR are available as image on GitHub Container Registry (based on the declared |
|
Since it is not in the todos: Just to make sure: the mirror must also be providable for persisted documents |
a27a06b to
00eb94d
Compare
69c4d19 to
bad695e
Compare
|
Waiting for graphql-hive/console#7287 to be released first |
enisdenjo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small remarks, otherwise looking good.
| '@graphql-hive/gateway-runtime': minor | ||
| --- | ||
|
|
||
| ## New Hive CDN mirror and circuit breaker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First line should be the name of the changeset, dont title it, it will look weird when listing all changesets.
| "vitest": "3.2.4" | ||
| }, | ||
| "resolutions": { | ||
| "@graphql-hive/core": "0.16.0-alpha-20251126142740-d265dc6d6d73bf62ec597dbe41409f466b9d9874", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this released? Do we want the alpha?
| const endpoints = (Array.isArray(endpoint) ? endpoint : [endpoint]).map( | ||
| (url) => (url.endsWith('/supergraph') ? url : `${url}/supergraph`), | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing this in the gateway? Shouldn't the supergraph fetcher handle this instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because It was handled by the schema fetcher before, not anymore (because there is no schema fetcher anymore, it's a generic artifacts fetcher)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's just to avoid a breaking change on our end
|
Do you have understanding whether people use the config or CLI parameters for providing the configuration, and whether it should also be possible to provide these by other means than the config? |
|
We can probably make the endpoint a multiple flag, so that you can provide more than one. For the circuit breaker, seems a bit advanced to have it as CLI flag, but we can introduce env variables if you want ? |
|
Oh, I was only referring towards the endpoint option, sorry for the confusion! I think most (read as: probably all) people should not configure circuit breaker and use the defaults, I don't see a need to make this a CLI parameter. For the endpoint it might make sense. I am fine with omitting this here and making it a follow up pull request. I have no clue if people provide this via CLI or config file |
Description
Adds support for the new Hive CDN fetcher with the addition of a secondary mirror and a circuit breaker.
Details
This PR also ensures the schema fetcher is actually disposed, since the circuit breaker has to be disposed to properly shut down the gateway.
Ref GW-535
Todo