-
Notifications
You must be signed in to change notification settings - Fork 208
add support for sse redirect and http proxy settings #1718
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7154acc
add support for sse redirect, add v2.1/track for aad auth path and v2…
kryalama 53ace94
reverting v2/track changes
kryalama 61f2b88
addressing comments
kryalama d777285
address comments, increase webflux test timeout to 10000ms due to ret…
kryalama 453daac
use lazyAzureHttpClient in telemetry channel
kryalama 6e14f2a
add logging policy to httppipeline and handle 401,403 in response
kryalama fcfa74c
Merge branch 'aad' into kryalama/addsse
kryalama d749135
add 307 support
kryalama 590dd74
fix smoke test
kryalama a90132a
fix bug based on aad enabled flag
kryalama 50d6fca
address comments
kryalama 55ed186
address comments
kryalama 344beaa
add comment to AadAuthentication.init() when authentication is disabled
kryalama 2950da1
add comments to loggingpolicy
kryalama 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
95 changes: 95 additions & 0 deletions
95
...com/microsoft/applicationinsights/internal/authentication/AzureMonitorRedirectPolicy.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * ApplicationInsights-Java | ||
| * Copyright (c) Microsoft Corporation | ||
| * All rights reserved. | ||
| * | ||
| * MIT License | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
| * software and associated documentation files (the ""Software""), to deal in the Software | ||
| * without restriction, including without limitation the rights to use, copy, modify, merge, | ||
| * publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
| * persons to whom the Software is furnished to do so, subject to the following conditions: | ||
| * The above copyright notice and this permission notice shall be included in all copies or | ||
| * substantial portions of the Software. | ||
| * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
| * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
| * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| * DEALINGS IN THE SOFTWARE. | ||
| */ | ||
|
|
||
| package com.microsoft.applicationinsights.internal.authentication; | ||
|
|
||
| import com.azure.core.http.HttpPipelineCallContext; | ||
| import com.azure.core.http.HttpPipelineNextPolicy; | ||
| import com.azure.core.http.HttpRequest; | ||
| import com.azure.core.http.HttpResponse; | ||
| import com.azure.core.http.policy.HttpPipelinePolicy; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.net.HttpURLConnection; | ||
|
|
||
| // This is a copy from Azure Monitor Open Telemetry Exporter SDK AzureMonitorRedirectPolicy | ||
| public final class AzureMonitorRedirectPolicy implements HttpPipelinePolicy { | ||
|
|
||
| private static final int PERMANENT_REDIRECT_STATUS_CODE = 308; | ||
| private static final int TEMP_REDIRECT_STATUS_CODE = 307; | ||
| // Based on Stamp specific redirects design doc | ||
| private static final int MAX_REDIRECT_RETRIES = 10; | ||
| private static final Logger logger = LoggerFactory.getLogger(AzureMonitorRedirectPolicy.class); | ||
| private volatile String redirectedEndpointUrl; | ||
|
|
||
| @Override | ||
| public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { | ||
| return attemptRetry(context, next, context.getHttpRequest(), 0); | ||
| } | ||
|
|
||
| /** | ||
| * Function to process through the HTTP Response received in the pipeline | ||
| * and retry sending the request with new redirect url. | ||
| */ | ||
| private Mono<HttpResponse> attemptRetry(final HttpPipelineCallContext context, | ||
| final HttpPipelineNextPolicy next, | ||
| final HttpRequest originalHttpRequest, | ||
| final int retryCount) { | ||
| // make sure the context is not modified during retry, except for the URL | ||
| context.setHttpRequest(originalHttpRequest.copy()); | ||
| if (this.redirectedEndpointUrl != null) { | ||
| context.getHttpRequest().setUrl(this.redirectedEndpointUrl); | ||
| } | ||
| return next.clone().process() | ||
| .flatMap(httpResponse -> { | ||
| if (shouldRetryWithRedirect(httpResponse.getStatusCode(), retryCount)) { | ||
| String responseLocation = httpResponse.getHeaderValue("Location"); | ||
| if (responseLocation != null) { | ||
| this.redirectedEndpointUrl = responseLocation; | ||
| return attemptRetry(context, next, originalHttpRequest, retryCount + 1); | ||
| } | ||
| } | ||
| return Mono.just(httpResponse); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Determines if it's a valid retry scenario based on statusCode and tryCount. | ||
| * | ||
| * @param statusCode HTTP response status code | ||
| * @param tryCount Redirect retries so far | ||
| * @return True if statusCode corresponds to HTTP redirect response codes and redirect | ||
| * retries is less than {@code MAX_REDIRECT_RETRIES}. | ||
| */ | ||
| private boolean shouldRetryWithRedirect(int statusCode, int tryCount) { | ||
| if (tryCount >= MAX_REDIRECT_RETRIES) { | ||
| logger.warn("Max redirect retries limit reached:{}.", MAX_REDIRECT_RETRIES); | ||
| return false; | ||
| } | ||
| return statusCode == HttpURLConnection.HTTP_MOVED_TEMP | ||
| || statusCode == HttpURLConnection.HTTP_MOVED_PERM | ||
| || statusCode == PERMANENT_REDIRECT_STATUS_CODE | ||
| || statusCode == TEMP_REDIRECT_STATUS_CODE; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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
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.
does this need to pass around
originalHttpRequestor can it usecontext.getHttpRequest()each time?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 believe we can use context.getHttpRequest, but I followed the same standard of setting the context from https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RetryPolicy.java#L96