-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Adding Options for Request Id Policy. #6370
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
Adding Options for Request Id Policy. #6370
Conversation
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/RequestIdPolicyOptions.java
Outdated
Show resolved
Hide resolved
| if (requestId == null) { | ||
| if (!Objects.isNull(requestIdPolicyOptions)) { | ||
| HttpHeaders httpHeaders = requestIdPolicyOptions.getIdHeaderSupplier().get(); | ||
| if (!Objects.isNull(httpHeaders)) { |
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.
A random header id should be added if httpHeaders is null.
sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RequestIdPolicyOptions.java
Show resolved
Hide resolved
|
|
||
| /** | ||
| * The pipeline policy that puts a UUID in the request header. Azure uses the request id as | ||
| * The pipeline policy that puts a UUID or user provided id in the request header. Azure uses the request id as |
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.
With this change, we can't guarantee that the request-id is a unique identifier. User-provided request ids may not be unique.
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.
While it's true, it may also be possible that a customer generates their own UUID and may want to correlate it with the ID generated by their system.
I have no idea how the service implements it, but as a user I would expect the service to save the provided ID with the rest of the raw data I sent, so I can analyze it later. Therefore the SDK cannot guarantee uniqueness if user provides the ID, which is fine, if the persistence layer can support it.
I want to suggest that the code will generate a default ID, and allow the customer to override it based on their need.
| * Creates a {@link RequestIdPolicy} with the provided {@link RequestIdPolicyOptions}. | ||
| * User can specify {@link java.util.function.Function} to dynamically generated id for various id headers. | ||
| * | ||
| * @param requestIdPolicyOptions with given {@link RetryPolicyOptions}. |
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.
Fix javadoc - RequestIdPolicyOptions
|
|
||
| /** | ||
| * Creates a {@link RequestIdPolicy} with the provided {@link RequestIdPolicyOptions}. | ||
| * User can specify {@link java.util.function.Function} to dynamically generated id for various id headers. |
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 should be RequestIdPolicyOptions instead of Function. Also, import packages and use class names instead of fully qualified names.
| ); | ||
| } | ||
| } else { | ||
| context.getHttpRequest().getHeaders().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.
This will now overwrite the requestId that was already in context. Existing requestId should be preserved. Random id should be used only when the requestId in context is null.
| HttpHeaders httpHeaders = requestIdPolicyOptions.getIdHeaderSupplier().get(); | ||
| if (!Objects.isNull(httpHeaders)) { | ||
| httpHeaders.stream().forEach(httpHeader -> | ||
| context.getHttpRequest().getHeaders().put(httpHeader.getName(), httpHeader.getValue()) |
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 should check for existing headers with the same name in the context. If it already exists, it should not be overwritten.
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.
I think this is a good place to have a discussion, can take it offline if needed.
@JonathanGiles is there any guidelines around whether a pipeline policy should overwrite or only add if not exists?
This isn't our only policy that could potentially mutate the headers state.
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.
I am also unsure about guideline on this. I did hear that every new request ( including retry ) to Azure service should use new Request ID. But at the same time it is "optional" in Azure Docs
https://docs.microsoft.com/en-us/rest/api/azure/devops/symbol/requests/create%20requests?view=azure-devops-rest-5.1
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.
I just spoke to Jeffery on this and his comments are "Every retry should have the same ID. This way, we can tell how many retries occurred for a single logical operation."
alzimmermsft
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.
Same questions as @srnagar
|
|
||
| /** | ||
| * The pipeline policy that puts a UUID in the request header. Azure uses the request id as | ||
| * The pipeline policy that puts a UUID or user provided id in the request header. Azure uses the request id as |
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.
While it's true, it may also be possible that a customer generates their own UUID and may want to correlate it with the ID generated by their system.
I have no idea how the service implements it, but as a user I would expect the service to save the provided ID with the rest of the raw data I sent, so I can analyze it later. Therefore the SDK cannot guarantee uniqueness if user provides the ID, which is fine, if the persistence layer can support it.
I want to suggest that the code will generate a default ID, and allow the customer to override it based on their need.
|
Closing this PR this work was done in a separate PR by adding a constructor |
Allow customers set the value in RequestId header with following headers names
Should use something like RequestIDOptions POJO to collect information from user. Reference PR https://github.com/Azure/azure-sdk-for-java/pull/6196/files
Coordinate with PR, since it is waiting for this change. : #6214
Related Issue : #6171
Additional context
This change is inline with overall strategy discussed here #6217