RUM-17106: Test Only Flush Client-Side-Stats before shared write executor shuts down#3603
RUM-17106: Test Only Flush Client-Side-Stats before shared write executor shuts down#3603abrooksv wants to merge 1 commit into
Conversation
…utor shuts down Add StatsConcentrator.drainAndFlush() and wire it into flushAndShutdownExecutors() via a new "flush_and_stop_stats" event, so CSS buckets are synchronously flushed before the shared write executor is shut down instead of being dropped when the periodic timer hasn't fired yet. This is used by RUM Fit to flush the CSS data during test runs
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feature/client-side-stats #3603 +/- ##
=============================================================
+ Coverage 73.29% 73.33% +0.04%
=============================================================
Files 986 986
Lines 35988 36011 +23
Branches 6066 6070 +4
=============================================================
+ Hits 26375 26406 +31
+ Misses 7930 7922 -8
Partials 1683 1683
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7bbce05b8f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sdkCore.getFeature(Feature.TRACING_CLIENT_STATS_FEATURE_NAME) | ||
| ?.sendEvent( | ||
| mapOf( | ||
| "type" to "flush_and_stop_stats" | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Drain context work before stopping stats aggregation
When spans were just published, StatsConcentrator.record() may still have only enqueued its withContext callback on the core context executor; this sends flush_and_stop_stats before (sdkCore as? DatadogCore)?.flushStoredData() drains that executor. In that case drainAndFlush() shuts down the stats executor, and the later-drained context callback rejects stats-aggregate, so the newest client-side stats are dropped during the test flush this change is meant to make reliable.
Useful? React with 👍 / 👎.
| val tasks = arrayListOf<Runnable>() | ||
| (executorService as? ThreadPoolExecutor)?.queue?.drainTo(tasks) | ||
| executorService.shutdown() | ||
| executorService.awaitTermination(DRAIN_WAIT_SECONDS, TimeUnit.SECONDS) |
There was a problem hiding this comment.
Avoid waiting on the periodic stats flush during drain
In a normally initialized client-stats feature there is always a 30-second delayed schedulePeriodicFlush() task in this ScheduledThreadPoolExecutor; queue.drainTo does not remove unexpired delayed tasks, and shutdown() leaves them queued, so this await commonly blocks for the full 10-second timeout before the final synchronous flush. Calls to the internal test flush soon after initialization will therefore get an avoidable 10-second stall unless the delayed task is cancelled/removed or shutdownNow()/shutdown policy is used before awaiting.
Useful? React with 👍 / 👎.
What does this PR do?
Add StatsConcentrator.drainAndFlush() and wire it into flushAndShutdownExecutors() via a new "flush_and_stop_stats" event, so CSS buckets are synchronously flushed before the shared write executor is shut down instead of being dropped when the periodic timer hasn't fired yet.
This follows the pattern that RUM Monitor established
Motivation
This is used by RUM Fit to flush the CSS data during test runs