-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Update RequestIdPolicy.java #6214
Closed
+7
−2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,18 @@ | |
* the unique identifier for the request. | ||
*/ | ||
public class RequestIdPolicy implements HttpPipelinePolicy { | ||
private static final String REQUEST_ID_HEADER = "x-ms-client-request-id"; | ||
private static final String REQUEST_ID_HEADER = "client-request-id"; | ||
private static final String LEGACY_REQUEST_ID_HEADER = "x-ms-client-request-id"; | ||
|
||
@Override | ||
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { | ||
String requestId = context.getHttpRequest().getHeaders().getValue(REQUEST_ID_HEADER); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to the changes being made in this PR, but a general question around the policy, could we add in another constructor which allows for a |
||
if (requestId == null) { | ||
context.getHttpRequest().getHeaders().put(REQUEST_ID_HEADER, UUID.randomUUID().toString()); | ||
String randomUUID = UUID.randomUUID().toString(); | ||
context.getHttpRequest().getHeaders().put(REQUEST_ID_HEADER, randomUUID); | ||
|
||
//also set the legacy header for backwards compatibility. | ||
context.getHttpRequest().getHeaders().put(LEGACY_REQUEST_ID_HEADER, randomUUID); | ||
} | ||
return next.process(); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it possible that the request-id is set only in the legacy header? Do we need to check both here?
Also, if only one is set, we should add logic to set the other as well.
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.
Based on the docs (https://docs.microsoft.com/en-us/rest/api/searchservice/common-http-request-and-response-headers-used-in-azure-search) and Swagger spec, Search uses
client-request-id
andreturn-client-request-id
.So it's not clear why to check the status of the legacy header. Instead, it should be always equal to the valid header header, regardless of the value it contains.
The options are:
So the problem arises where the values are not equal, in which case a decision needs to be made for which of legacyRequestId or requestId is to taken and replace the other.
This feels to me like a product question rather than a code question, because there may other considerations.
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.
Since the changes are in
azure-core
, several other Azure services will be using this outside of Search. I am not sure if they all follow the same guidelines as Search.