-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Customizing azure-core Http Header in RetryPolicy #6217 #6400
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
Customizing azure-core Http Header in RetryPolicy #6217 #6400
Conversation
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RetryPolicy.java
Show resolved
Hide resolved
...pconfiguration/src/main/java/com/azure/data/appconfiguration/ConfigurationClientBuilder.java
Outdated
Show resolved
Hide resolved
|
I'm not understanding this PR. The initial design requirement was to support custom headers. This was introduced in the previously-merged PR #6196 that added the RetryPolicyOptions type, which I have suggested isn't the right approach. This PR takes this out, which is good, but instead appears to focus on customising the retry delay (which I don't think has been a feature request yet), whilst making the requested ability to support custom headers much more complicated. Have you worked through the requirements you've outlined in #6217 and determined how they will be implemented? Why is this custom header requirement being conflated with the work on custom retry duration? Asking developers to implement the calculateRetryDelay method will lead to errors that we should try to avoid, primarily due to the logic in the default implementation that users may not recreate correctly. |
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RetryPolicy.java
Show resolved
Hide resolved
| * it is called. Example of these headers are 'x-ms-client-request-id', 'x-ms-correlation-request-id'. | ||
| */ | ||
| public RequestIdPolicy(Supplier<HttpHeaders> requestIdSupplier) { | ||
| this.requestIdSupplier = requestIdSupplier; |
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.
We are using HttpHeaders because, There can be multiple headers which are of ID nature. We already have been asked for multiple id related headers by app config
"x-ms-client-request-id"
"x-ms-correlation-request-id"
Thus HttpHeaders represent multiple Headers which client can set.
sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RequestIdPolicyTests.java
Show resolved
Hide resolved
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RequestIdPolicy.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RequestIdPolicy.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RequestIdPolicy.java
Outdated
Show resolved
Hide resolved
| if (Objects.nonNull(httpHeaders) && httpHeaders.getSize() > 0) { | ||
| httpHeaders.stream().forEach(httpHeader -> { | ||
| String requestIdHeaderValue = context.getHttpRequest().getHeaders().getValue(httpHeader.getName()); | ||
| if (requestIdHeaderValue == null) { |
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.
This is a general question for all policies which mutate the request, should this just insert the header value?
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RequestIdPolicy.java
Outdated
Show resolved
Hide resolved
|
|
||
| if (Objects.nonNull(requestIdSupplier)) { | ||
| HttpHeaders httpHeaders = requestIdSupplier.get(); | ||
| if (Objects.nonNull(httpHeaders) && httpHeaders.getSize() > 0) { |
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.
Continuing from a previous comment, if the supplier is made non-nullable and we add a default header in the base constructor (and possible default to this is null is passed into the overloaded constructor), should we do nothing if the supplier returns nothing. x-ms-client-request-id is optional by many services, so this would be allowed, but it would hurt tracking issues.
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.
You answered , I think, In order to track request, we do need request id. And if client does not provide or give us empty .. we should provide it.
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RetryPolicy.java
Show resolved
Hide resolved
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RetryPolicy.java
Outdated
Show resolved
Hide resolved
|
@itye-msft Please review RequestIDPolicy. |
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RequestIdPolicy.java
Outdated
Show resolved
Hide resolved
itye-msft
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.
LGTM, thanks.
A specific test for RequestID with custom header would be nice if possible.
| * {@link HttpRequest}. | ||
| * | ||
| * @param requestIdSupplier to dynamically generate to request id for each {@link HttpRequest}. It is suggested | ||
| * that this {@link Supplier} provides unique value every time it is called. |
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.
What happens if the supplier provides a non-unique value? Will the service reject the request? How does the service use this request id?
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.
When I spoke to Jeffrey Richter about this, I understood, request-id is for telemetry purpose. For example Cognitive Search request-id is optional. https://docs.microsoft.com/en-us/rest/api/searchservice/common-http-request-and-response-headers-used-in-azure-search
Optional caller-specified request ID, in the form of a GUID with no decoration such as curly braces (for example, client-request-id: 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0). A caller-defined value that identifies the given request. If specified, this will be included in response information as a way to map the request.
| @Override | ||
| public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { | ||
|
|
||
| HttpHeaders httpHeaders = requestIdSupplier.get(); |
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.
Wouldn't this allow users to provide a random set of HTTP headers and not just the request id headers?
For e.g. the supplier can return
new HttpHeaders().put("foo", "bar").put(REQUEST_ID_HEADER, UUID.randomUUID().toString());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.
yes . But unless we keep a bag of valid request id header, we can not validate. And whenever a new request-id header is introduced, we need to update the bag and release.
Removing
RetryPolicyOptionsused byRetryPolicy. It was not present in GA release as well.Supporting Client to overwrite Custom 'Retry-After' Header in
RetryPolicy.Using Option 4 from discussion here -> #6217 (comment)
More discussion here #6217
Search team need these headers
"x-ms-client-request-id
"client-request-id"
Azure-App Config need these headers
"x-ms-client-request-id"
"x-ms-correlation-request-id"
More detail discussion : #6217
Relevant PR from search team for reference: https://github.com/Azure/azure-sdk-for-java/pull/6214/files