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

Support caller-specified RetryFuncs #4428

Merged
merged 6 commits into from
Sep 23, 2024
Merged

Support caller-specified RetryFuncs #4428

merged 6 commits into from
Sep 23, 2024

Conversation

manicminer
Copy link
Contributor

@manicminer manicminer commented Sep 20, 2024

Changes

  • Add a Type to SDKOperationOption to accommodate additional options that are orthogonal to the existing marshallable options (which become headers, query string arguments, or odata settings).
  • Support a caller-specified Content-Type header via SDKOperationOptionTypeContentType, useful for file uploads and other scenarios with a customizable request body.
  • Support a caller-specified RequestRetryFunc via SDKOperationOptionTypeRequestFunc, more details below.
  • For MS Graph API definitions, add a RetryFunc option to all operations.
  • For MS Graph API definitions, add a ContentType option whenever the request body is a binary payload.

Background

Currently we have some hardcoded RetryFuncs to handle specific error cases where we want to either safely retry the original request, to elect to not retry a request that would ordinarily be retried (e.g. 429 response), or to provide a custom error message for certain failures. This is already plumbed in and uses go-retryablehttp for backoff and retry handling.

There is already some hardcoded use of RetryFuncs, for example in the Resource Manager Base Client, but individual SDKs can currently also supply a RetryFunc.

With Microsoft Graph, there are lots of edge cases where certain errors need specific handling, and it's not possible to autogenerate these - nor would it be desirable since they would apply for every invocation of an operation absent of any usage context. It's therefore necessary to expose a means of supply a RetryFunc to the caller, so they can be inlined into the AzureAD provider.

This implementation makes it possible for importers to include an optional operation option to allow the caller to specify a RetryFunc. By default this is not added, and doesn't count towards possible options, so this addition will not affect the signatures of any existing operation methods (e.g. in Resource Manager SDKs, existing or future). I've elected to have the MS Graph importer add this option to every operation.

Hamilton has its own equivalent of RetryFuncs, which since it's a handwritten SDK are built into the clients. Some examples: service principals, users, groups, OAuth2 grants, access package resource requests... the list goes on.

@manicminer manicminer requested a review from a team September 20, 2024 00:21
@manicminer manicminer added enhancement New feature or request tool/generator-go-sdk Issues with the Go SDK Generator tool/data-api Issues with the Data API labels Sep 20, 2024
Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

Thanks @manicminer LGTM 🍝

@manicminer manicminer merged commit b4563a9 into main Sep 23, 2024
4 checks passed
@manicminer manicminer deleted the support-retry-funcs branch September 23, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tool/data-api Issues with the Data API tool/generator-go-sdk Issues with the Go SDK Generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants