Skip to content

RUM-17106: Test Only Flush Client-Side-Stats before shared write executor shuts down#3603

Draft
abrooksv wants to merge 1 commit into
feature/client-side-statsfrom
abrooks/css-force-flush-tests
Draft

RUM-17106: Test Only Flush Client-Side-Stats before shared write executor shuts down#3603
abrooksv wants to merge 1 commit into
feature/client-side-statsfrom
abrooks/css-force-flush-tests

Conversation

@abrooksv

@abrooksv abrooksv commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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

…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-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.33%. Comparing base (8d12b19) to head (7bbce05).

Files with missing lines Patch % Lines
...tadog/android/trace/internal/ClientStatsFeature.kt 92.31% 0 Missing and 1 partial ⚠️
...trace/internal/domain/metrics/StatsConcentrator.kt 85.71% 0 Missing and 1 partial ⚠️
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              
Files with missing lines Coverage Δ
...ore/src/main/kotlin/com/datadog/android/Datadog.kt 80.00% <100.00%> (+6.09%) ⬆️
...tadog/android/trace/internal/ClientStatsFeature.kt 90.70% <92.31%> (+0.70%) ⬆️
...trace/internal/domain/metrics/StatsConcentrator.kt 96.20% <85.71%> (-0.41%) ⬇️

... and 40 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@abrooksv abrooksv marked this pull request as ready for review July 3, 2026 02:14
@abrooksv abrooksv requested review from a team as code owners July 3, 2026 02:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +416 to +421
sdkCore.getFeature(Feature.TRACING_CLIENT_STATS_FEATURE_NAME)
?.sendEvent(
mapOf(
"type" to "flush_and_stop_stats"
)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@abrooksv abrooksv marked this pull request as draft July 3, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants