Skip to content

Commit abab7bb

Browse files
authored
Merge 2.0.0 changes to master (#584)
* Fix null ref check in telemetry correlation Utils (#541) * Fix null ref check in TelemetryCorrelationUtils * Modifying log level to warning * Updating Changelog * Fix handling of NaN and +/-Infinity in JSON serializer (#499) * Handle NaN and +/-Infinity in metrics * Default NaN/Infinity serialization to 0 to be consistent with other AI SDKs and make the code compatible with Java 6 * fixed javadoc errors and added section to generate pom.xml with all builds (#551) * Updating version number to 2.0.0 * Implementing Retry logic [Reliable Channel] [STABLE Branch] (#561) * Initial commit of retry and backoff logic fixes * Fixing warnings on files I touched this round * Fix the eclipse UI from screaming about the docker Contstants * Fixed backoff logic to use existing method. Added more logging to the sender channel. * Added the partial response handler, more logging * Added gson to core. Fixed backoff manager to keep original functionality. Added extension to return the timeout values as expected before. * Added unit tests. * Fixing string typed ArrayList<> to List<> per Dhaval * Missed one * Making tests consistent. * Added javadoc comments, simplified logic for a few methods * Added exception logging per @dhaval24. Fixed formatting on touched files * Updates per last round of commits Moved the Handlers out of the concrete package to the common package to keep the same consistency. Removed a couple of unessecary methods. Added docs. * Latest fixes * Add MaxInstantRetry Added MaxInstantRetry configuration to allow for instantaneous retry on a failed transmission. * Javadoc Updates Javadoc and formatting updates * NumberFormatException fix Added null check * JavaDocs for TPM * Fixing FixedRateSampling to work in old and new version of sampling (#540) Overriding default sampling percentage when programatically specified sampling percentage by user. * upgrade to logback v1.2.3 (#565) * Reliable channel: replacing logAlways "TRACE" statements with "info" (#571) * Reliable channel: close resources in finally block. (#572) * Reliable channel: close resources in finally block. * change logging to warning when closing resources * Bugfix against retry logic (#576) * Refactor * BUGFIX Logic would never backoff After adding the instant retry amount logic to the code this line of code could cause the transmissions to not back off. * Changes requested * Fixed javadocs tags, that caused build errors while executing `javadoc` gradle task (#578) * Update Changelog * Fix link in changelog * Fix another link in changelog * Update gradle.properties * Fix customizing pom.xml in Gradle build (#582) * Fix customizing pom.xml in Gradle build * Insert license after 1. row in pom.xml * Filter artifacts relocated by shadow task from pom dependencies - match artifacts by groupId - fixes #583 * Generate a pom file "beside" the artifact jar file
1 parent 6b435fe commit abab7bb

38 files changed

+1663
-418
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
- Fixed Issue #526 (NPE in MapUtil.copy())
1414
- Fixed Issue #513 (Memory leak in SDKShutdownActivity). This fix upgrades our Servlet version from 2.5 to 3.0. The SDK must now be run on an application server supporting Servlet 3.0.
1515

16+
## Version 2.0.0
17+
- Upgraded logback dependency version to 1.2.3
18+
- Improved FixedRateSampling so that it also supports Sampling Percentage set by users programmatically. Fixes [issue #535](https://github.com/Microsoft/ApplicationInsights-Java/issues/535)
19+
- Fault Tolerance improvements: introducing retries and exponential backoff capabilities with disk persistence.
20+
- [Issue #499](https://github.com/Microsoft/ApplicationInsights-Java/pull/499): Fix handling of NaN and +/-Infinity in JSON serializer
21+
- [Issue #506](https://github.com/Microsoft/ApplicationInsights-Java/pull/506): Null Reference Check causing Null Pointer Exception in `TelemetryCorrelationUtils.java`
22+
1623
## Version 2.0.0-BETA
1724
- Updating various dependencies to latest version
1825
- Introducing public class CustomClassWriter in Agent to enable finding common super classes used for Agent instrumentation without loading it

core/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies {
5353
compile ([group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'])
5454
compile ([group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'])
5555
compile ([group: 'com.google.guava', name: 'guava', version: '20.0'])
56+
compile ([group: 'com.google.code.gson', name: 'gson', version: '2.8.2'])
5657
testCompile group: 'junit', name: 'junit', version: '4.12'
5758
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
5859
testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
@@ -65,6 +66,7 @@ shadowJar {
6566
relocate 'org.apache.commons', 'com.microsoft.applicationinsights.core.dependencies.apachecommons'
6667
relocate 'com.google.common', 'com.microsoft.applicationinsights.core.dependencies.googlecommon'
6768
relocate 'javax.annotation', 'com.microsoft.applicationinsights.core.dependencies.javaxannotation'
69+
relocate 'com.google.gson', 'com.microsoft.applicationinsights.core.dependencies.gson'
6870
}
6971

7072
jar {
@@ -95,8 +97,11 @@ projectPomDescription = "This is the core module of " + project.msftAppInsightsJ
9597

9698
whenPomConfigured = { p ->
9799
def agentArtifactId = project(":agent").jar.baseName
98-
p.dependencies = p.dependencies.findAll { dep -> dep.artifactId != agentArtifactId }
99-
writePomToArtifactsDirectory(p, project.name)
100+
p.dependencies = p.dependencies.findAll { dep ->
101+
dep.artifactId != agentArtifactId &&
102+
!(dep.groupId in ['org.apache.http', 'eu.infomas', 'org.apache.commons', 'commons-io',
103+
'com.google.guava', 'com.google.code.gson', 'org.apache.httpcomponents'])
104+
}
100105
}
101106

102107
// endregion Publishing properties

core/src/main/java/com/microsoft/applicationinsights/channel/concrete/inprocess/InProcessTelemetryChannel.java

Lines changed: 97 additions & 69 deletions
Large diffs are not rendered by default.

core/src/main/java/com/microsoft/applicationinsights/channel/concrete/inprocess/InProcessTelemetryChannelFactory.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@
3333
* Created by gupele on 1/15/2015.
3434
*/
3535
final class InProcessTelemetryChannelFactory implements TransmitterFactory {
36+
private final int DEFAULT_RETRY = 3;
37+
@Override
38+
public TelemetriesTransmitter create(String endpoint, String maxTransmissionStorageCapacity, boolean throttlingIsEnabled) {
39+
return create(endpoint, maxTransmissionStorageCapacity, throttlingIsEnabled, DEFAULT_RETRY);
40+
}
3641
@Override
37-
public TelemetriesTransmitter create(String endpoint, String maxTransmissionStorageCapacity, boolean throttlingIsEnabled) {
38-
final TransmissionPolicyManager transmissionPolicyManager = new TransmissionPolicyManager(throttlingIsEnabled);
39-
42+
public TelemetriesTransmitter create(String endpoint, String maxTransmissionStorageCapacity, boolean throttlingIsEnabled, int maxInstantRetries) {
43+
final TransmissionPolicyManager transmissionPolicyManager = new TransmissionPolicyManager(throttlingIsEnabled);
44+
transmissionPolicyManager.addTransmissionHandler(new ErrorHandler(transmissionPolicyManager));
45+
transmissionPolicyManager.addTransmissionHandler(new PartialSuccessHandler(transmissionPolicyManager));
46+
transmissionPolicyManager.addTransmissionHandler(new ThrottlingHandler(transmissionPolicyManager));
47+
transmissionPolicyManager.setMaxInstantRetries(maxInstantRetries);
4048
// An active object with the network sender
4149
TransmissionNetworkOutput actualNetworkSender = TransmissionNetworkOutput.create(endpoint, transmissionPolicyManager);
4250

@@ -51,6 +59,7 @@ public TelemetriesTransmitter create(String endpoint, String maxTransmissionStor
5159
// The dispatcher works with the two active senders
5260
TransmissionDispatcher dispatcher = new NonBlockingDispatcher(new TransmissionOutput[] {networkSender, activeFileSystemOutput});
5361
actualNetworkSender.setTransmissionDispatcher(dispatcher);
62+
5463

5564
// The loader works with the file system loader as the active one does
5665
TransmissionsLoader transmissionsLoader = new ActiveTransmissionLoader(fileSystemSender, stateFetcher, dispatcher);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.microsoft.applicationinsights.internal.channel;
2+
3+
/**
4+
* An interface that is used to create a concrete class that is called by the the {@link TransmissionHandlerObserver}
5+
* <p>
6+
* This is used to implement classes like {@link com.microsoft.applicationinsights.internal.channel.common.ErrorHandler}
7+
* and {@link com.microsoft.applicationinsights.internal.channel.common.PartialSuccessHandler}.
8+
* @author jamdavi
9+
*/
10+
public interface TransmissionHandler {
11+
/**
12+
* Called when a transmission is sent by the {@link TransmissionOutput}.
13+
* @param args The {@link TransmissionHandlerArgs} for this handler.
14+
*/
15+
void onTransmissionSent(TransmissionHandlerArgs args);
16+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.microsoft.applicationinsights.internal.channel;
2+
3+
import org.apache.http.Header;
4+
5+
import com.microsoft.applicationinsights.internal.channel.common.Transmission;
6+
7+
/**
8+
* This class is used to store information between the transmission sender and the transmission handlers
9+
* <p>
10+
* An example class that uses this are {@link com.microsoft.applicationinsights.internal.channel.common.ErrorHandler}
11+
* @author jamdavi
12+
*
13+
*/
14+
public class TransmissionHandlerArgs {
15+
private String responseBody;
16+
/**
17+
* Set the response body.
18+
* @param body The HTTP Response from the sender
19+
*/
20+
public void setResponseBody(String body) { this.responseBody = body;}
21+
/**
22+
* Get the response body
23+
* @return The HTTP Response from the sender
24+
*/
25+
public String getResponseBody() { return this.responseBody;}
26+
27+
28+
private TransmissionDispatcher transmissionDispatcher;
29+
/**
30+
* Set the {@link TransmissionDispatcher} used by the sender
31+
* @param dispatcher The {@link TransmissionDispatcher} used by the sender
32+
*/
33+
public void setTransmissionDispatcher(TransmissionDispatcher dispatcher) { this.transmissionDispatcher = dispatcher;}
34+
/**
35+
* Get the {@link TransmissionDispatcher} used by the sender
36+
* @return The {@link TransmissionDispatcher} used by the sender
37+
*/
38+
public TransmissionDispatcher getTransmissionDispatcher() { return this.transmissionDispatcher;}
39+
40+
private Transmission transmission;
41+
/**
42+
* Set the transmission that needs to be passed to the handler.
43+
* @param transmission The transmission that needs to be passed to the handler.
44+
*/
45+
public void setTransmission(Transmission transmission) { this.transmission = transmission;}
46+
/**
47+
* Get the transmission that needs to be passed to the handler.
48+
* @return The transmission used by the handler.
49+
*/
50+
public Transmission getTransmission() { return this.transmission;}
51+
52+
private int responseCode;
53+
/**
54+
* Set the response code to be passed to the handler.
55+
* @param code The HTTP response code.
56+
*/
57+
public void setResponseCode(int code) { this.responseCode = code;}
58+
/**
59+
* Get the response code for the handler to use.
60+
* @return The HTTP response code.
61+
*/
62+
public int getResponseCode() { return this.responseCode;}
63+
64+
private Throwable exception;
65+
/**
66+
* Set the exception thrown by the sender to be passed the handler.
67+
* @param ex The exception
68+
*/
69+
public void setException(Throwable ex) { this.exception = ex;}
70+
/**
71+
* Get the exception thrown by the sender to be used by the handler.
72+
* @return The exception
73+
*/
74+
public Throwable getException() { return this.exception;}
75+
76+
private Header retryHeader;
77+
/**
78+
* Set the Retry-After header to be passed to the handler.
79+
* @param head The Retry-After header
80+
*/
81+
public void setRetryHeader(Header head) { this.retryHeader = head;}
82+
/**
83+
* Get the Retry-After header to be passed to the handler.
84+
* @return The Retry-After header
85+
*/
86+
public Header getRetryHeader() { return this.retryHeader;}
87+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.microsoft.applicationinsights.internal.channel;
2+
3+
4+
/**
5+
* Enables the {@link com.microsoft.applicationinsights.internal.channel.common.TransmissionPolicyManager} to handle transmission states.
6+
* <p>
7+
* This interface extends {@link TransmissionHandler} to add the ability to observe when the transmission is completed.
8+
* @author jamdavi
9+
*
10+
*/
11+
public interface TransmissionHandlerObserver extends TransmissionHandler {
12+
13+
/**
14+
* Used to add a {@link TransmissionHandler} to the collection stored by the
15+
* {@link com.microsoft.applicationinsights.internal.channel.common.TransmissionPolicyManager}.
16+
* @param handler The handler to add to the collection.
17+
*/
18+
void addTransmissionHandler(TransmissionHandler handler);
19+
}

core/src/main/java/com/microsoft/applicationinsights/internal/channel/TransmitterFactory.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,21 @@
2525
* Created by gupele on 12/21/2014.
2626
*/
2727
public interface TransmitterFactory {
28+
/**
29+
* Creates the {@link TelemetriesTransmitter} for use by the {@link com.microsoft.applicationinsights.channel.TelemetryChannel}
30+
* @param endpoint HTTP Endpoint to send telemetry to
31+
* @param maxTransmissionStorageCapacity Max amount of disk space in KB for persistent storage to use
32+
* @param throttlingIsEnabled Allow the network telemetry sender to be throttled
33+
* @return The {@link TelemetriesTransmitter} object
34+
*/
2835
TelemetriesTransmitter create(String endpoint, String maxTransmissionStorageCapacity, boolean throttlingIsEnabled);
36+
/**
37+
* Creates the {@link TelemetriesTransmitter} for use by the {@link com.microsoft.applicationinsights.channel.TelemetryChannel}
38+
* @param endpoint HTTP Endpoint to send telemetry to
39+
* @param maxTransmissionStorageCapacity Max amount of disk space in KB for persistent storage to use
40+
* @param throttlingIsEnabled Allow the network telemetry sender to be throttled
41+
* @param maxInstantRetries Number of instant retries in case of a temporary network outage
42+
* @return The {@link TelemetriesTransmitter} object
43+
*/
44+
TelemetriesTransmitter create(String endpoint, String maxTransmissionStorageCapacity, boolean throttlingIsEnabled, int maxInstantRetries);
2945
}

core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/ActiveTransmissionLoader.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
import java.util.concurrent.TimeUnit;
2727
import java.util.concurrent.atomic.AtomicBoolean;
2828

29+
import com.google.common.base.Preconditions;
2930
import com.microsoft.applicationinsights.internal.channel.TransmissionDispatcher;
3031
import com.microsoft.applicationinsights.internal.channel.TransmissionsLoader;
3132
import com.microsoft.applicationinsights.internal.logger.InternalLogger;
3233

33-
import com.google.common.base.Preconditions;
34-
import com.microsoft.applicationinsights.internal.shutdown.Stoppable;
35-
3634
/**
3735
* The class is responsible for loading transmission files that were saved to the disk
3836
*
@@ -109,7 +107,7 @@ public void run() {
109107
case UNBLOCKED:
110108
fetchNext(true);
111109
break;
112-
110+
case BACKOFF:
113111
case BLOCKED_BUT_CAN_BE_PERSISTED:
114112
Thread.sleep(DEFAULT_SLEEP_INTERVAL_AFTER_DISPATCHING_IN_MILLS);
115113
break;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.microsoft.applicationinsights.internal.channel.common;
2+
3+
/**
4+
* Utility class used by the {@link PartialSuccessHandler}
5+
*
6+
* @author jamdavi
7+
*
8+
*/
9+
class BackendResponse {
10+
11+
int itemsReceived;
12+
int itemsAccepted;
13+
Error[] errors;
14+
15+
class Error {
16+
public int index;
17+
public int statusCode;
18+
public String message;
19+
}
20+
}

0 commit comments

Comments
 (0)