Skip to content

Conversation

@hemanttanwar
Copy link
Contributor

@hemanttanwar hemanttanwar commented Nov 18, 2019

  1. Removing RetryPolicyOptions used by RetryPolicy . It was not present in GA release as well.

  2. Supporting Client to overwrite Custom 'Retry-After' Header in RetryPolicy .

Using Option 4 from discussion here -> #6217 (comment)
More discussion here #6217

  1. Supporting ability to set multiple id header in RequestIdPolicy :
    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

@hemanttanwar hemanttanwar requested review from JonathanGiles, alzimmermsft, conniey and srnagar and removed request for alzimmermsft November 18, 2019 23:32
@JonathanGiles
Copy link
Member

JonathanGiles commented Nov 19, 2019

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.

@hemanttanwar hemanttanwar changed the title Implement RetryPolicy based on issue #6217 Do Not Review Yet- Implement RetryPolicy based on issue #6217 Nov 19, 2019
@hemanttanwar hemanttanwar changed the title Do Not Review Yet- Implement RetryPolicy based on issue #6217 Customizing azure-core Http Header in Http Policy #6217 Nov 20, 2019
@hemanttanwar hemanttanwar marked this pull request as ready for review November 20, 2019 23:06
@hemanttanwar hemanttanwar changed the title Customizing azure-core Http Header in Http Policy #6217 Customizing azure-core Http Header in RetryPolicy #6217 Nov 21, 2019
* 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;
Copy link
Contributor Author

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.

if (Objects.nonNull(httpHeaders) && httpHeaders.getSize() > 0) {
httpHeaders.stream().forEach(httpHeader -> {
String requestIdHeaderValue = context.getHttpRequest().getHeaders().getValue(httpHeader.getName());
if (requestIdHeaderValue == null) {
Copy link
Member

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?

@JonathanGiles @srnagar


if (Objects.nonNull(requestIdSupplier)) {
HttpHeaders httpHeaders = requestIdSupplier.get();
if (Objects.nonNull(httpHeaders) && httpHeaders.getSize() > 0) {
Copy link
Member

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.

Copy link
Contributor Author

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.

@hemanttanwar
Copy link
Contributor Author

@itye-msft Please review RequestIDPolicy.

Copy link

@itye-msft itye-msft left a 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.
Copy link
Member

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?

Copy link
Contributor Author

@hemanttanwar hemanttanwar Nov 22, 2019

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();
Copy link
Member

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());

Copy link
Contributor Author

@hemanttanwar hemanttanwar Nov 22, 2019

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.

@hemanttanwar hemanttanwar requested a review from mssfang November 22, 2019 20:53
@hemanttanwar hemanttanwar merged commit 3862907 into Azure:master Nov 23, 2019
@hemanttanwar hemanttanwar deleted the 6217-retrypolicy-custom-responseheaders branch November 23, 2019 00:26
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.

7 participants