Skip to content

Commit 5837b5a

Browse files
authored
add v2.1/track endpoint, add retry policy (#1714)
1 parent 2400cdc commit 5837b5a

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

core/src/main/java/com/microsoft/applicationinsights/TelemetryChannel.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.azure.core.http.*;
44
import com.azure.core.http.policy.HttpPipelinePolicy;
5+
import com.azure.core.http.policy.RetryPolicy;
56
import com.azure.core.util.tracing.Tracer;
67
import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem;
78
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -16,6 +17,7 @@
1617
import java.io.IOException;
1718
import java.net.URL;
1819
import java.nio.ByteBuffer;
20+
import java.util.ArrayList;
1921
import java.util.Iterator;
2022
import java.util.List;
2123

@@ -36,15 +38,18 @@ class TelemetryChannel {
3638
private final URL endpoint;
3739

3840
TelemetryChannel(URL endpoint) {
41+
List<HttpPipelinePolicy> policies = new ArrayList<>();
3942
HttpClient client = HttpClient.createDefault();
4043
HttpPipelineBuilder pipeline = new HttpPipelineBuilder()
4144
.httpClient(client);
45+
// Retry policy for failed requests
46+
policies.add(new RetryPolicy());
4247
// TODO handle authentication exceptions
4348
HttpPipelinePolicy authenticationPolicy = AadAuthentication.getInstance().getAuthenticationPolicy();
4449
if (authenticationPolicy != null) {
45-
pipeline.policies(authenticationPolicy);
50+
policies.add(authenticationPolicy);
4651
}
47-
// TODO check existing retry policy, and its configuration
52+
pipeline.policies(policies.toArray(new HttpPipelinePolicy[0]));
4853
this.pipeline = pipeline.build();
4954
this.endpoint = endpoint;
5055
}
@@ -88,7 +93,7 @@ List<ByteBuffer> encode(List<TelemetryItem> telemetryItems) throws IOException {
8893
}
8994

9095
private CompletableResultCode internalSend(List<ByteBuffer> byteBuffers) {
91-
HttpRequest request = new HttpRequest(HttpMethod.POST, endpoint + "v2/track");
96+
HttpRequest request = new HttpRequest(HttpMethod.POST, endpoint + "v2.1/track");
9297

9398
request.setBody(Flux.fromIterable(byteBuffers));
9499

core/src/main/java/com/microsoft/applicationinsights/internal/authentication/AadAuthentication.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.azure.core.http.HttpPipelineBuilder;
66
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
77
import com.azure.core.http.policy.HttpPipelinePolicy;
8+
import com.azure.core.http.policy.RetryPolicy;
89
import com.azure.identity.ClientSecretCredentialBuilder;
910
import com.azure.identity.IntelliJCredentialBuilder;
1011
import com.azure.identity.ManagedIdentityCredential;
@@ -15,6 +16,9 @@
1516
import com.microsoft.applicationinsights.internal.system.SystemInformation;
1617
import org.checkerframework.checker.nullness.qual.Nullable;
1718

19+
import java.util.ArrayList;
20+
import java.util.List;
21+
1822
public class AadAuthentication {
1923
private static final String APPLICATIONINSIGHTS_AUTHENTICATION_SCOPE = "https://monitor.azure.com//.default";
2024

@@ -108,13 +112,16 @@ private static HttpPipelinePolicy getAuthenticationPolicyWithSAMI() {
108112
}
109113

110114
public HttpPipeline newHttpPipeLineWithAuthentication() {
111-
115+
List<HttpPipelinePolicy> policies = new ArrayList<>();
116+
// Retry policy for failed requests
117+
policies.add(new RetryPolicy());
112118
HttpPipelinePolicy authenticationPolicy = getAuthenticationPolicy();
113119
HttpClient httpClient = LazyAzureHttpClient.getInstance();
114120
HttpPipelineBuilder pipelineBuilder = new HttpPipelineBuilder().httpClient(httpClient);
115121
if(authenticationPolicy != null) {
116-
pipelineBuilder.policies(authenticationPolicy);
122+
policies.add(authenticationPolicy);
117123
}
124+
pipelineBuilder.policies(policies.toArray(new HttpPipelinePolicy[0]));
118125
return pipelineBuilder.build();
119126
}
120127
}

core/src/main/java/com/microsoft/applicationinsights/internal/config/connection/EndpointProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.net.URISyntaxException;
88

99
public class EndpointProvider {
10-
@VisibleForTesting static final String INGESTION_URI_PATH = "v2/track";
10+
@VisibleForTesting static final String INGESTION_URI_PATH = "v2.1/track";
1111
@VisibleForTesting static final String LIVE_URI_PATH = "QuickPulseService.svc";
1212
@VisibleForTesting static final String API_PROFILES_APP_ID_URI_PREFIX = "api/profiles/"; // <base uri, with host>/api/profiles/<ikey>/appid
1313
@VisibleForTesting static final String API_PROFILES_APP_ID_URI_SUFFIX = "/appId";

test/fakeIngestion/servlet/src/main/java/com/microsoft/applicationinsights/test/fakeingestion/MockedAppInsightsIngestionServlet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
159159
// FIXME (trask) this only accept be "/v2/track"
160160
case "/v2/track":
161161
case "/v2//track":
162+
case "/v2.1/track":
162163
StringWriter w = new StringWriter();
163164
try {
164165
String contentEncoding = req.getHeader("content-encoding");
@@ -173,7 +174,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
173174
CharStreams.copy(reader, w);
174175
String body = w.toString();
175176
if (PING.equals(body)) {
176-
logit("Ping received for /v2/track");
177+
logit("Ping received for /v2.1/track");
177178
resp.getWriter().append(PONG);
178179
}
179180
else {

test/smoke/framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest/AiSmokeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public boolean apply(@Nullable Envelope input) {
483483
protected static void checkMockedIngestionHealth() throws Exception {
484484
String ok = HttpHelper.get("http://localhost:"+mockedIngestion.getPort()+"/");
485485
assertEquals(MockedAppInsightsIngestionServlet.ENDPOINT_HEALTH_CHECK_RESPONSE, ok);
486-
String postResponse = HttpHelper.post("http://localhost:6060/v2/track", MockedAppInsightsIngestionServlet.PING);
486+
String postResponse = HttpHelper.post("http://localhost:6060/v2.1/track", MockedAppInsightsIngestionServlet.PING);
487487
assertEquals(MockedAppInsightsIngestionServlet.PONG, postResponse);
488488
}
489489

test/smoke/testApps/CoreAndFilter/src/main/resources/ApplicationInsights.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</TelemetryInitializers>
3636

3737
<Channel>
38-
<EndpointAddress>http://non-existent-host/v2/track</EndpointAddress>
38+
<EndpointAddress>http://non-existent-host/v2.1/track</EndpointAddress>
3939
<DeveloperMode>true</DeveloperMode>
4040
<FlushIntervalInSeconds>1</FlushIntervalInSeconds>
4141
</Channel>

0 commit comments

Comments
 (0)