Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
91b087c
WIP: Add metrics batcher in the SDK
psx95 Apr 13, 2026
9534dea
Allow exporting metricData batches
psx95 Apr 14, 2026
70d4e15
Make existing tests compatible with changes
psx95 Apr 14, 2026
6b97875
Add docs and update existing tests
psx95 Apr 14, 2026
b2b78c3
Fix MetricExportBatcher logic and add tests
psx95 Apr 15, 2026
40226ae
Add support for EXPONENTIAL_HISTOGRAM and SUMMARY data types
psx95 Apr 15, 2026
af9fad2
Fix metrics checkstyle issue
psx95 Apr 15, 2026
3c3bc1a
Add missing generated diff files
psx95 Apr 15, 2026
7b3feb8
Update unit tests for enhanced coverage
psx95 Apr 15, 2026
0083b54
Add unit tests for PeriodicMetricReader
psx95 Apr 15, 2026
1b3ad77
Fix checkstyle issues
psx95 Apr 15, 2026
5e18a7c
Clean up inline code comments
psx95 Apr 15, 2026
a5b0120
Fix bug for miscalculating remaining capacity of a batch
psx95 Apr 15, 2026
1751b57
Add missing Javadoc for public facing API
psx95 Apr 15, 2026
6ea146e
Refactor logic in prepareExportBatches to remove redundancy
psx95 Apr 15, 2026
c5356f6
Address comment about defensive copy for original point sublist
psx95 Apr 16, 2026
c02c3c8
Prevent copying MetricData for 0 points
psx95 Apr 16, 2026
1e8c645
Add test case to verify there are no batches with empty metric points
psx95 Apr 16, 2026
48575c2
Switch to sequential export
psx95 Apr 19, 2026
e90ab8d
Add tests to verify sequential export for PeriodicMetricReader
psx95 Apr 19, 2026
6538745
Fix batched forceFlush failure propagation
zeitlinger Apr 21, 2026
1b7874d
Make metric export batching linear
zeitlinger Apr 21, 2026
741a8a4
Restore forceFlush partial-success behavior
zeitlinger Apr 23, 2026
55c10c7
Resolve lane A review follow-ups
zeitlinger Apr 27, 2026
19546a6
Merge remote-tracking branch 'psx95/issue-8245' into lane-a-pr-8296
zeitlinger Apr 27, 2026
2628fe4
Merge remote-tracking branch 'gregor/gregor/8296-forceflush-failure-p…
zeitlinger Apr 27, 2026
8aff51d
Restore forceFlush doRun failure handling
zeitlinger Apr 27, 2026
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 @@ -66,7 +66,7 @@ Collection<Collection<MetricData>> batchMetrics(Collection<MetricData> metrics)
return Collections.emptyList();
}
Collection<Collection<MetricData>> preparedBatchesForExport = new ArrayList<>();
Collection<MetricData> currentBatch = new ArrayList<>(maxExportBatchSize);
BatchState currentBatch = new BatchState(new ArrayList<>(maxExportBatchSize), 0);

// Fill active batch and split overlapping metric points if needed
for (MetricData metricData : metrics) {
Expand All @@ -76,8 +76,8 @@ Collection<Collection<MetricData>> batchMetrics(Collection<MetricData> metrics)
}

// Push trailing capacity block
if (!currentBatch.isEmpty()) {
preparedBatchesForExport.add(currentBatch);
if (!currentBatch.metrics.isEmpty()) {
preparedBatchesForExport.add(currentBatch.metrics);
}
return Collections.unmodifiableCollection(preparedBatchesForExport);
}
Expand All @@ -92,16 +92,13 @@ Collection<Collection<MetricData>> batchMetrics(Collection<MetricData> metrics)
* @return A result containing the prepared batches and the last in-progress batch.
*/
private MetricDataSplitOperationResult prepareExportBatches(
MetricData metricData, Collection<MetricData> currentBatch) {
int currentBatchPoints = 0;
for (MetricData m : currentBatch) {
currentBatchPoints += m.getData().getPoints().size();
}
int remainingCapacityInCurrentBatch = maxExportBatchSize - currentBatchPoints;
MetricData metricData, BatchState currentBatch) {
int remainingCapacityInCurrentBatch = maxExportBatchSize - currentBatch.points;
int totalPointsInMetricData = metricData.getData().getPoints().size();

if (remainingCapacityInCurrentBatch >= totalPointsInMetricData) {
currentBatch.add(metricData);
currentBatch.metrics.add(metricData);
currentBatch.points += totalPointsInMetricData;
return new MetricDataSplitOperationResult(Collections.emptyList(), currentBatch);
} else {
// Remaining capacity can't hold all points, partition existing metric data object
Expand All @@ -114,15 +111,16 @@ private MetricDataSplitOperationResult prepareExportBatches(
Math.min(totalPointsInMetricData - currentIndex, remainingCapacityInCurrentBatch);

if (pointsToTake > 0) {
currentBatch.add(
currentBatch.metrics.add(
copyMetricData(metricData, originalPointsList, currentIndex, pointsToTake));
currentBatch.points += pointsToTake;
currentIndex += pointsToTake;
remainingCapacityInCurrentBatch -= pointsToTake;
}

if (remainingCapacityInCurrentBatch == 0) {
preparedBatches.add(currentBatch);
currentBatch = new ArrayList<>(maxExportBatchSize);
preparedBatches.add(currentBatch.metrics);
currentBatch = new BatchState(new ArrayList<>(maxExportBatchSize), 0);
remainingCapacityInCurrentBatch = maxExportBatchSize;
}
}
Expand Down Expand Up @@ -233,7 +231,7 @@ private static MetricData createMetricDataWithPoints(
*/
private static class MetricDataSplitOperationResult {
private final Collection<Collection<MetricData>> preparedBatches;
private final Collection<MetricData> lastInProgressBatch;
private final BatchState lastInProgressBatch;

/**
* Creates a new MetricDataSplitOperationResult.
Expand All @@ -245,8 +243,7 @@ private static class MetricDataSplitOperationResult {
* than {@link #maxExportBatchSize} points.
*/
MetricDataSplitOperationResult(
Collection<Collection<MetricData>> preparedBatches,
Collection<MetricData> lastInProgressBatch) {
Collection<Collection<MetricData>> preparedBatches, BatchState lastInProgressBatch) {
this.preparedBatches = preparedBatches;
this.lastInProgressBatch = lastInProgressBatch;
}
Expand All @@ -255,8 +252,29 @@ Collection<Collection<MetricData>> getPreparedBatches() {
return preparedBatches;
}

Collection<MetricData> getLastInProgressBatch() {
BatchState getLastInProgressBatch() {
return lastInProgressBatch;
}
}

/**
* Tracks the active batch while batching stays linear: {@code metrics} is the current export
* payload being assembled and {@code points} is its running point count, so callers do not need
* to rescan the batch on every append.
*/
private static final class BatchState {
private final Collection<MetricData> metrics;
private int points;

/**
* Creates the mutable state for the current in-progress batch.
*
* @param metrics metric entries collected into the current export batch
* @param points running total of data points across {@code metrics}
*/
private BatchState(Collection<MetricData> metrics, int points) {
this.metrics = metrics;
this.points = points;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ void periodicExport_SequentialBatches_PartialFailure() throws Exception {

batch3Result.succeed();

// Flush result should still be success
// Failed export results are logged, but forceFlush preserves the prior partial-success
// behavior.
assertThat(flushResult.join(5, TimeUnit.SECONDS).isSuccess()).isTrue();

boolean logFound =
Expand Down
Loading