feat(sdk-metrics): align PeriodicMetricReader export timeout semantics - #8684
feat(sdk-metrics): align PeriodicMetricReader export timeout semantics#8684Rajkaran-122 wants to merge 12 commits into
Conversation
Pull request dashboard statusWaiting on the author · refreshed 2026-09-08 22:30 UTC Respond to 4 review items (e.g. link a commit, explain why not, ask a follow-up): Status above doesn't look right?
|
…cheduler Replace scheduler-based withTimeout() with CompletableResultCode.join(), matching the established pattern in BatchSpanProcessor and BatchLogRecordProcessor. The previous approach used scheduler.schedule() which throws RejectedExecutionException during shutdown because the scheduler is intentionally shut down before the final export flush.
|
Hi @Rajkaran-122 — just a friendly reminder that this pull request is waiting on you. The dashboard status comment has the open items and is kept current.
|
…ication - Added setExporterTimeout() API to PeriodicMetricReaderBuilder with 30-second default per spec - Removed @SInCE 1.40.0 annotations as requested by reviewer - Updated API-diff to reflect new public API - Added comprehensive tests for timeout behavior - Implemented conditional timeout enforcement (only when explicitly configured) - Addressed blocking concern by making timeout opt-in via setExporterTimeout()
|
…Reader Add asynchronous timeout enforcement for MetricExporter operations in PeriodicMetricReader using a dedicated timeout executor. This preserves the existing asynchronous scheduling and batching behavior while enforcing the spec-required 30-second default export timeout. Changes: - Add dedicated ScheduledExecutorService for timeout scheduling - Implement applyTimeout() method with asynchronous timeout enforcement - Preserve async batch processing with Iterator-based sequential execution - Fix Error Prone warnings (UnusedVariable, PreferJavaTimeOverload) - Add timeout enforcement test The timeout executor is shut down after final export completes to avoid RejectedExecutionException during shutdown. Timeout enforcement fails the result when timeout expires without blocking the periodic scheduler. Resolves CI compilation failures in PR open-telemetry#8684.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8684 +/- ##
============================================
- Coverage 91.48% 91.30% -0.19%
- Complexity 10467 10503 +36
============================================
Files 1021 1006 -15
Lines 27694 28370 +676
Branches 3247 3587 +340
============================================
+ Hits 25337 25902 +565
- Misses 1615 1675 +60
- Partials 742 793 +51 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| @Test | ||
| void explicitTimeout_exporterCompletesBeforeTimeout() throws Exception { |
There was a problem hiding this comment.
This and the test below is (and maybe all the validation cases could be parameterized tests
… jack-berg review - Remove separate timeout executor and reuse existing scheduler - Increase scheduler from 1 to 2 threads to handle both periodic exports and timeout tasks - Simplify applyTimeout() by removing AtomicBoolean/timedOut state tracking - Combine SlowMetricExporter and FastMetricExporter into single DelayingMetricExporter - Add RejectedExecutionException handling for shutdown race condition - Fix BooleanParameter warnings in tests
|
Thanks, @jack-berg sir. I've updated the implementation based on your feedback:
I also handled the scheduler-shutdown case in applyTimeout() because the final shutdown export can race with scheduler shutdown when scheduling the timeout task. All relevant sdk:metrics formatting, compilation, and PeriodicMetricReaderTest checks pass. |
|
@jack-berg sir , please review this pr. |
|
I ran JAIPilot Cloud against this exact PR head. It found one deterministic follow-up: when an export is already complete, skip creating and immediately cancelling the timeout task. The focused path changed from 1 schedule/cancel pair to 0. Baseline passed 31 focused tests, candidate passed 32 including the new regression test, and both clean Cloud-generated draft and evidence: skrcode#2 Feel free to merge or cherry-pick if it fits the intended timeout semantics. |
|
@jack-berg sir, please review the pr. |
- Change default timeout from min(interval, 30s) to exactly the configured interval - Remove DEFAULT_EXPORT_TIMEOUT_MILLIS constant (no longer used) - Update Javadoc for both timeout overloads to document new default behavior - Add Javadoc explaining timeout applies to each batch when maxExportBatchSize is configured - Update test to verify default timeout equals interval - Add test to verify explicit timeout is preserved with large intervals
|
@jack-berg sir, please review the pr. |
|
I'm away I'll get back to this when I can |
|
@jack-berg sir PTAL. |
This is from the PR description but is no longer accurate. Can you review the whole PR description and make sure its aligned with the current state of the PR? Thanks. |
…test improvements Critical Concurrency Fix: - Fixed critical backpressure issue where timeout firing released exportAvailable while underlying exporter.export(...) was still running - Separated backpressure (tied to raw export result) from timeout reporting (tied to timeout result) in doRun() - Removed applyTimeout() from exportMetrics() to apply timeout only at the top level for reporting, not for backpressure - This prevents concurrent exports from accumulating when exporters are slow Test Improvements: - Replaced per-export Thread spawning with shared ExecutorService in tests - Added deterministic timeout regression test using LogCapturer to verify timeout warning was actually logged - Added concurrency semantics test to prove timeout does not release backpressure - Fixed Error Prone warning about ignored Future return value All tests pass, spotless clean, git diff --check clean.
Please don't ignore comments. Also, respond to comments and mark resolved if you feel your changes resolve them. |
Ok sir . |
|
Thanks for the review @jack-berg sir. I’ve addressed the requested changes:
All relevant tests are passing, and formatting and diff checks are clean. I’ve also addressed the corresponding review comments and resolved the threads. |
|
@jack-berg sir PTAL . |
Fixes #8311
Summary
Align
PeriodicMetricReaderexport timeout behavior with the Metrics specification by enforcing an exporter timeout for each export batch.Changes
PeriodicMetricReaderBuilderPeriodicMetricReaderTesting
git diff --checkNotes
This change updates export timeout behavior without affecting metric collection or normal scheduling semantics.