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 demand control for uplink #1564

Merged
merged 10 commits into from Mar 10, 2022
Merged

Add demand control for uplink #1564

merged 10 commits into from Mar 10, 2022

Conversation

Y-Guo
Copy link
Contributor

@Y-Guo Y-Guo commented Mar 3, 2022

Implements https://github.com/mdg-private/planning/issues/727

This PR uses the new minDelaySeconds returned by uplink to set the polling interval instead of gateways polling every 10 seconds by default configurable on the gateway side. If no minDelaySeconds is provided by uplink, pollIntervalInMs will still be used.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 3, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@Y-Guo Y-Guo marked this pull request as ready for review March 7, 2022 21:54
@trevor-scheer
Copy link
Member

trevor-scheer commented Mar 7, 2022

Can we add a test that demonstrates gateway utilizing this value? Additionally, a new test that exercises the Math.max logic (largest value overrides) would be good too.

I'm wondering if pollIntervalInMs should be renamed, this new behavior might be surprising just based on the name of the config option. In what case would there not be a designated poll interval coming from uplink? Can we just fall back to 10s in the case that it's not provided and remove the option from managed mode configurations altogether? Open to ideas here, I'm just throwing out the first things that come to mind.

});

expect(result).toBeNull();
expect(fetcher).toHaveBeenCalledTimes(1);
});

it("Waits the correct time before retrying", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't use mocked timers here because there's an issue with jest and nock that me and Jeffery Burt couldn't figure out how to solve. Using real timers here as a workaround and not writing a test for the polling/math.max with pollIntervalInMs for this reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

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

Thanks for the test addition 👍 The code changes LGTM.

I'm still concerned about pollIntervalInMs.

In managed mode, is there ever a case where the user's configuration is relevant after this change? Is it just the failure case?

I would be inclined to have a sane default which the gateway uses if it doesn't get one from Uplink and remove this notion of polling configurability altogether. Either that, or create a more appropriately named option for what this actually does now, which is more like fallbackPollIntervalInMs.

I think we should get some other opinions on this from @apollographql/atlas.

@Y-Guo
Copy link
Contributor Author

Y-Guo commented Mar 10, 2022

From a quick look in the code it seems pollIntervalInMs is only used by the UplinkFetcher, IntrospectAndCompose, and LegacyFetcher.
Assuming legacy doesn't matter, IntrospectAndCompose is only initialized when isServiceListConfig() is true
BUT there's also a check that warns against using pollIntervalInMs and isServiceListConfig() at the same time!

@cpeacock
Copy link
Contributor

I like the idea of setting it as fallbackPollIntervalInMs and creating less confusion with that value being far less useful as a result of this PR. I think you're right that legacy doesn't matter in this case because it's not using uplink. A sane default in the case of an outage may lead to a traffic stampede when service returns, so, while it's very unlikely to happen in practice, is something at the back of my head.

Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

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

LGTM!

@trevor-scheer trevor-scheer added the ↪️ backport-to-0.x landed on 2.x, but needs to be backported to the 0.x series label Mar 10, 2022
@trevor-scheer trevor-scheer merged commit 89833ff into apollographql:main Mar 10, 2022
trevor-scheer added a commit that referenced this pull request Mar 11, 2022
Co-authored-by: Yangzi Guo <Yangzi1guo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
↪️ backport-to-0.x landed on 2.x, but needs to be backported to the 0.x series
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants