Skip to content
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

Fix flush on JVM shutdown #37618

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
- [Fix flush on JVM shutdown](https://github.com/Azure/azure-sdk-for-java/pull/37618)

### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public CompletableResultCode send(List<TelemetryItem> telemetryItems) {
for (Map.Entry<TelemetryItemBatchKey, List<TelemetryItem>> batch : batches.entrySet()) {
resultCodeList.add(internalSendByBatch(batch.getKey(), batch.getValue()));
}
return maybeAddToActiveExportResults(resultCodeList);
maybeAddToActiveExportResults(resultCodeList);
return CompletableResultCode.ofAll(resultCodeList);
}

// visible for tests
Expand All @@ -106,14 +107,13 @@ Map<TelemetryItemBatchKey, List<TelemetryItem>> splitIntoBatches(
return groupings;
}

private CompletableResultCode maybeAddToActiveExportResults(List<CompletableResultCode> results) {
private void maybeAddToActiveExportResults(List<CompletableResultCode> results) {
if (activeExportResults.size() >= MAX_CONCURRENT_EXPORTS) {
// this is just a failsafe to limit concurrent exports, it's not ideal because it blocks
// waiting for the most recent export instead of waiting for the first export to return
operationLogger.recordFailure(
"Hit max " + MAX_CONCURRENT_EXPORTS + " active concurrent requests",
TELEMETRY_ITEM_EXPORTER_ERROR);
return CompletableResultCode.ofAll(results);
}

operationLogger.recordSuccess();
Expand All @@ -122,8 +122,6 @@ private CompletableResultCode maybeAddToActiveExportResults(List<CompletableResu
for (CompletableResultCode result : results) {
result.whenComplete(() -> activeExportResults.remove(result));
}

return CompletableResultCode.ofSuccess();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the problem, it should have been returning CompletableResultCode.ofAll(results) (which is the same as above, and so also simplified by moving it to the caller)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you catch this? i wonder if we need to update tests to catch it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I caught it during manual testing

we have a smoke test in the Java agent for testing JVM shutdown hook: https://github.com/microsoft/ApplicationInsights-Java/tree/main/smoke-tests/apps/SystemExit

we'd need to think how to test it in this repo

}

public CompletableResultCode flush() {
Expand Down
Loading