[ISSUE #10240] Add BatchSplittingMetricExporter to prevent OTLP gRPC export failures#10239
Merged
lizhimins merged 4 commits intoapache:developfrom Apr 3, 2026
Merged
Conversation
When high-cardinality metrics (consumer_group x topic) produce OTLP export payloads exceeding the gRPC 32MB limit or SLS per-RPC processing limit, all metrics fail to export. This adds a MetricExporter decorator that: - Splits large batches of MetricData objects into smaller sub-batches - Splits single oversized MetricData objects by their internal data points into multiple smaller MetricData objects (supports all 7 MetricDataType) - Configurable via BrokerConfig.metricsExportBatchMaxDataPoints (default 1000) - Fast path with zero overhead when data points are within threshold - Logs failed batch details for debugging
3 tasks
Contributor
Author
New commit: Fix AIOOBE from concurrent callback modificationAdded commit What changed: Impact: Shallow copy only (object references), ~800KB overhead per export cycle for 100K data points. Negligible compared to the gRPC export itself. This fix works together with the original batch-splitting logic — the snapshot ensures marshaling safety, while batch-splitting ensures payload size compliance. |
The OTel SDK's NumberDataPointMarshaler.createRepeated allocates an array based on points.size() then iterates. If callback threads concurrently add data points between size() and iteration, an ArrayIndexOutOfBoundsException occurs. This adds a defensive snapshot of all data point collections at the start of export(), ensuring the delegate exporter always receives immutable point collections.
- testSnapshotCreatesNewMetricData: verify delegate receives snapshotted MetricData, not the original reference - testSnapshotFallsBackToOriginal: verify catch block falls back to original when snapshot fails (e.g., mock without type) - testSnapshotPointsAreIndependentCopy: verify the snapshotted points collection is a separate instance from the original
f148458 to
21215a8
Compare
RongtongJin
approved these changes
Apr 3, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is the purpose of the change
Closes #10240
When high-cardinality metrics (e.g., consumer lag with consumer_group × topic combinations) are exported
via OTLP gRPC, the payload can exceed the gRPC 32MB message size limit or the backend's per-RPC processing
limit, causing all metrics to fail to export.
The OpenTelemetry Java SDK does not support automatic batch splitting for metrics export
(see opentelemetry-java#5394).
This PR adds a
MetricExporterdecorator that:MetricDataobjects into smaller sub-batches by data point countMetricDataobjects by their internal data points into multiplesmaller
MetricDataobjects (supports all 7MetricDataTypevariants)BrokerConfig.metricsExportBatchMaxDataPoints(default 1000)Brief changelog
BatchSplittingMetricExporterimplementingMetricExporteras a decoratorBrokerMetricsManagerto wrapOtlpGrpcMetricExportermetricsExportBatchMaxDataPointsconfig toBrokerConfig(default 1000, dynamically updatable)Verifying this change
This change added tests and can be verified as follows:
mvn test -pl broker -Dtest=BatchSplittingMetricExporterTest