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 strict checking of AWS API mock endpoints. #370

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

theipster
Copy link

@theipster theipster commented Mar 20, 2023

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

References: #369. (This PR updates the existing test suite to assert on mock API counts. These count assertions can then be used to replicate the scenario mentioned in #369.)


MR description

Previously, an unordered list of endpoint definitions were provided to the mock API server and incoming requests were matched with a simple existence lookup.

Now:

  • the list is ordered and requests are matched in FIFO order (i.e. any out-of-sequence request will be returned a HTTP 400); and,
  • matched requests will be shifted off the list (to avoid being matched multiple times); and,
  • every test scenario will additionally check that the list of expected endpoints for that scenario is fully exhausted.

Ultimately, the result is that each test scenario must exactly match the list of expected endpoints - no more and no less.

The objective is to expose duplicated API calls that are not only inefficient, but also potentially cause the API service to rate-limit (see hashicorp/terraform-provider-aws#27071).

Alan Ip added 2 commits March 20, 2023 06:51
Previously, an unordered list of endpoint definitions were provided to
the mock API server and incoming requests were matched with a simple
existence lookup.

Now:

 - the list is ordered and requests are matched in FIFO order (i.e. any
   out-of-sequence request will be returned a HTTP 400); and,
 - matched requests will be shifted off the list (to avoid being matched
   multiple times); and,
 - every test scenario will additionally check that the list of expected
   endpoints for that scenario is fully exhausted.

Ultimately, the result is that each test scenario must match the list of
expected endpoints exactly - no more and no less.

The objective is to expose duplicated API calls that are not only
inefficient, but also potentially cause the API service to rate-limit.
@theipster theipster requested a review from a team as a code owner March 20, 2023 19:46
@theipster
Copy link
Author

The corollary / pièce de résistance lies in the mock endpoints here: https://github.com/theipster/aws-sdk-go-base/pull/3/files#diff-ffb4ec9fa0ecffd143689744bed517bd2de0400060c2c0855755ab247dbfd94fR1244-R1257.

You can see that the servicemocks.MockStsAssumeRoleWithWebIdentityValidEndpoint mock endpoint is invoked once per provider, whereas it could theoretically be cached given that the inputs come from environment variables only.

Scale this up to a non-trivial number of providers, and this is where AWS STS starts throttling requests (as per hashicorp/terraform-provider-aws#27071).

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.

1 participant