Repository navigation
chore(test-app): show what the SDK has stored for events - #427
Open
abelonogov-ld wants to merge 329 commits into
Open
abelonogov-ld wants to merge 329 commits into
abelonogov-ld wants to merge 329 commits into
Conversation
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/OutboundEventBuffer.java
An evaluation of a tracked flag writes a summary counter and a feature event, and a debug event alongside them when debugging is on. Those writes took separate locks, so a close() landing between them delivered the counter and then refused the event, reporting an evaluation that no event describes. Widen the lock that guarded the pending events to cover the summary counters too, so the writes one evaluation makes are one critical section. drain() splits into takeSummaries() and encode() so the flush can take the run and the counters together and still encode outside the lock. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DirectEventProcessor.java
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DirectEventProcessor.java # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/OutboundEventBuffer.java
createEventAndReset hands back a period's statistics and clears them in the same call, so whoever builds the event owns it. It was built on the scheduler thread and posted from the diagnostics thread, which may have been busy with an earlier post; a transition to offline or background in that window was noticed after the build and discarded the event. The period's stream inits, events-in-batch count and dropped count went with it, and dataSinceDate had already moved, so the next event described a window beginning after the reset. Move the build onto the posting thread, behind the suspension check, so a transition leaves the counters where they are for the next period to carry. The init event keeps its check, having nothing to consume. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java
The normalization said `>= 0`, so a capacity of nought stayed nought. On main that threw from `new ArrayBlockingQueue<>(0)` at construction; with the pending list there is nothing to throw, so it became a silent refusal of every event. Worse than it sounds, because the same number is the buffer's context limit and only the processor was normalizing it: at nought neither full events nor summaries survived, and at -5 the processor allowed one event while the buffer refused to summarize at all. So the fix is one normalization in ComponentsImpl feeding both, with the processor keeping its own guard for direct construction. Co-authored-by: Cursor <cursoragent@cursor.com>
…ing the server describeConfiguration was sending the raw capacity, so a client configured with nought told the service nought while running at one. It now shares the one normalization with the buffer and the processor. The race test was flaking about one run in six. Not the processor: the test server records a request body with a single unlooped read, so a body past one socket read's worth comes back truncated, at a point that moves between runs. Thirty events instead of a hundred and fifty stays clear of it, and the test still fails on every un-fixed run. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java
Three components bound themselves by this number and each was normalizing it, or not. Clamping in the setter makes the field valid by construction, which is what the sibling setter for the diagnostic interval already does, and leaves every consumer -- the buffer, the processor, the diagnostic description -- to just use it. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java
The two init tests asserted nothing. One asked a foreground processor to go to the foreground, which setInBackground returns from before reaching any decision; the other waited for the init event before going offline, so the only thing stopping a second one was that the first had already gone. Each was held up by the guard the other claimed to cover, and both passed with every guard deleted. Coming to the foreground now goes through the background first, and waits for the diagnostics thread to come free -- while the first init is still posting, the claim is taken and the transition is turned away before it decides anything. The offline one builds a processor that never comes online, then brings it online to show the silence was the offline state and not a dead fixture. Two new ones. A must-shut-down response has to stop recording and delivery for good, which nothing exercised. And a flush running against four recorders has to keep each evaluation in one payload: close() delivers once, so it can catch an evaluation being stranded but never one being split across two deliveries. Eight trials, because a single one catches a split lock about two times in three. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java
…y/event-durability-tier3-persistence aFlushNeverSplitsAnEvaluationAcrossTwoPayloads is left behind at tier 2. It reads each payload as it went out, which says something only where a payload is the run taken straight from the pending list; here a delivery reads the store, so a counter and its event can land in one payload or two for reasons that have nothing to do with the lock. Confirmed by narrowing the lock and watching it pass five times out of five. A comment in its place says where it went. Co-authored-by: Cursor <cursoragent@cursor.com>
The MalformedJsonException in aContextAlreadyBeingCountedKeepsCountingOnceTheLimitIsReached is not a serialization race: recording is sequential on the test thread and the payload is a deterministic ~28 KB. The test-helpers HTTP server reads request bodies with a single unlooped read, so larger bodies can be truncated depending on the machine. Fill the summarizer to a limit of 10 contexts instead of 100 so each flush stays well under that size. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence
Offline means the application told the SDK to stay off the network, and closing does not revoke that, so the final delivery in close() is skipped and held events are dropped. DefaultEventProcessor behaved the same way (its FLUSH is a no-op while offline); the comments and the EventProcessor javadoc promised more than either implementation did. Add a test pinning the behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush * andrey/event-durability-tier1-buffer: Document that close() discards events held while offline
…y/event-durability-tier3-persistence * andrey/event-durability-tier2-bounded-flush: Document that close() discards events held while offline
…n reconnect The SDK builds the event processor offline and turns it on once initialization is done. Coming online used to deliver immediately, meant for the end of an outage, but it also fired on that first transition at startup and sent the initial identify alone before anything else was recorded. DefaultEventProcessor never did that, and the contract tests expect the first payload to wait for a flush. The immediate delivery existed only because cancelling the periodic flush for an outage restarted its interval on every reconnect. The flush task now stays scheduled regardless of the offline state (a run while offline does nothing), so the interval is never restarted and what an outage buffered goes out at the first run after it ends. No transition needs special handling. Co-authored-by: Cursor <cursoragent@cursor.com>
…-durability-tier2-bounded-flush Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DirectEventProcessorTest.java
…y/event-durability-tier3-persistence Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DirectEventProcessor.java # launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/EventProcessorTestBase.java
…rent constructor The context limit moved to the fourth parameter; the androidTest copy of the benchmark was never compiled by the unit-test runs and kept the old order. Co-authored-by: Cursor <cursoragent@cursor.com>
A commit takes the pending run under recordLock and encodes it outside, so until it is staged the run is in neither pending nor the store. The capacity check counted only those two, so an event recorded in that window was accepted past capacity; LDClientEventTest.testEventBufferFillsUp saw two identifies with a capacity of one once startup stopped delivering the first one alone. EventStore is no longer final so the test can pause a commit mid-staging. Co-authored-by: Cursor <cursoragent@cursor.com>
With DEFERRED persistence, flush() and blockingFlush() now write on the events thread instead of the calling thread. The event store finds its directory and process name the first time it needs them, on the events thread, not while LDClient.init builds it. close() writes on the events thread and only falls back to the caller's thread if that thread doesn't get to the write within the close budget. commit() returns before taking the I/O lock when persistence is off. The IMMEDIATE and flush() javadocs now say which thread does the write. Co-authored-by: Cursor <cursoragent@cursor.com>
updateScheduledTasks no longer returns early once the processor is closed. The closed flag now gates only starting work, so cancelling always happens, and close() cancels its tasks by calling updateScheduledTasks under stateLock instead of repeating the cancel calls itself. Co-authored-by: Cursor <cursoragent@cursor.com>
…rites everything before it returns Co-authored-by: Cursor <cursoragent@cursor.com>
…ence The caller's thread encodes and writes the one event, without waiting for a commit in progress; the held evaluations and the summaries are left to a commit queued on the commit executor in the same call. The summarizer's counters are still taken at each track or identify, so its contexts are cleared as before. Co-authored-by: Cursor <cursoragent@cursor.com>
… reserved place A track or identify at immediate persistence committed the store, which wrote whatever a commit in flight had staged so far, up to megabytes of a run or a split summary, on the application thread. It now writes just its own frame and leaves the rest to the commit that staged it. It is also reserved where it is admitted, so a recording on another thread cannot take its place while it is encoded and have it refused as a loss. A commit now releases only its own unused reservations rather than all of them. Co-authored-by: Cursor <cursoragent@cursor.com>
A summary too large for one log frame is refused whole by the store, logged, and counted as lost, so the flush that committed it answers false. Reaching that takes one context evaluating dozens of the largest JSON flags between two commits, which did not justify the packing and halving that split it. Co-authored-by: Cursor <cursoragent@cursor.com>
…e again Writing only the tracked event left the evaluations before it to a commit queued on the commit executor, so a kill straight after the track, which is what immediate persistence is for, could take those exposures with it. With the summary split gone, the commit costs the caller a normal encode of the held run and the summaries, so the track commits it again before returning. This reverts 19afcec and 1200025. Co-authored-by: Cursor <cursoragent@cursor.com>
…rsistence again" This reverts commit a65c588, which moves to a PR of its own. Co-authored-by: Cursor <cursoragent@cursor.com>
A text view under the persistence picker lists the event directory for this app and mobile key: the pending- logs processes append to and the ready- batches waiting for delivery, with the count each batch's name holds, their sizes and modification times. It reads names and sizes only, never opening a file, so looking cannot take a lock another process's recovery needs. It reads again every second while the app is in the foreground. A long press copies the directory's path. The directory comes from the SDK's own EventDirectory.defaultDirectory, through a class in the SDK's package as the benchmark runner does, so the view cannot drift from where the SDK writes. The iOS test app has the same section. Co-authored-by: Cursor <cursoragent@cursor.com>
The constructor queued the recovery of what a previous run left and scheduled the periodic flush and the diagnostics, so building a processor was enough to start work on the events thread. The constructor now only sets fields, and start() does that work. EventProcessorBuilderImpl.build calls it straight after the constructor, before anything else can use the processor, so the recovery is still the first task on the events thread and every delivery queued after it waits for it. Tests start each processor they build, as the builder does, and a new one checks that a processor not yet started leaves a previous run's log alone. Co-authored-by: Cursor <cursoragent@cursor.com>
Each environment now has the whole `capacityBytes`, like `capacity`, rather than an equal share of it. This follows the review on iOS ([ios-client-sdk#538](launchdarkly/ios-client-sdk#538 (comment))), which makes the same change. Stacked on #408 (tier 3). - **An equal share is too small where there are many environments.** Some customers configure 7, which at the default left each under 3 MiB. - **Adding an environment no longer shrinks the others.** A share was fixed when the store was built, so a directory within its old share could be over its new one, and new events were refused until delivery or expiry drained it. - **The disk the SDK may use now grows with the environments**: up to 20 MiB each at the default. Ordinary traffic reaches `capacity` (2000 events) long before that; only unusually large events, or summaries piling up through a long outage, get near it. - **`ComponentsImpl.shareOfCapacityBytes` is gone**; the store gets `capacityBytes` as it is, and already reads zero or less as the default. The `EventProcessorBuilder.capacityBytes` docs say it is for each environment. Test: `theByteCapacityIsSharedEquallyByTheConfiguredEnvironments` becomes `eachEnvironmentHasTheWholeByteCapacityHoweverManyAreConfigured`: with seven environments and a 2,400-byte capacity, an 850-byte event is delivered, where the old split's 342 bytes would have refused it. `./gradlew :launchdarkly-android-client-sdk:testDebugUnitTest`: 1257 tests, 0 failures (25 skipped). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > **Persisted event byte limits are now per environment**, matching `capacity(int)` and the iOS client change, instead of splitting `capacityBytes` evenly across all configured mobile keys. > > `ComponentsImpl` drops `shareOfCapacityBytes` and passes the configured `capacityBytes` straight into `EventStore.create`. **`EventProcessorBuilder` docs** are updated to state each secondary environment gets the full limit, so adding environments no longer shrinks others and apps with many envs (e.g. seven) aren’t stuck with tiny per-env quotas. > > The unit test is renamed and asserts that with seven environments and a 2,400-byte limit, an ~850-byte custom event still flushes—behavior that would fail under the old equal-share rule. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a809095. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: Cursor <cursoragent@cursor.com>
Changes `EventProcessorBuilder.DEFAULT_MAX_AGE_MILLIS` from 7 days to 24 hours. Persisted events that have not been delivered within 24 hours are discarded and counted as dropped, and so is what the SDK stored for a mobile key the application stopped using. Applications can still call `maxAgeMillis(long)` to keep events longer. It has no effect where `eventPersistence` is `DISABLED`. Stacked on #408 (tier 3). - `DEFAULT_MAX_AGE_MILLIS` is now `24L * 60 * 60 * 1000`, with its Javadoc updated. - `EventStoreBoundsTest.keepsABatchYoungerThanTheMaximumAge` aged its batch by 6 days, which is now past the default; it ages it by 12 hours. The tests that age by 8 days still exceed the maximum age and are unchanged. iOS counterpart: launchdarkly/ios-client-sdk#549. Tested: `:launchdarkly-android-client-sdk:testDebugUnitTest`, 1257 tests, 0 failures. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > **Shortens the default retention window** for persisted analytics events from **7 days to 24 hours** by updating `EventProcessorBuilder.DEFAULT_MAX_AGE_MILLIS` and its Javadoc. > > When event persistence is enabled, undelivered batches older than the default max age are discarded (and counted as dropped); apps can still override via `maxAgeMillis(long)`. The change has **no effect** when `eventPersistence` is `DISABLED`. > > `EventStoreBoundsTest.keepsABatchYoungerThanTheMaximumAge` now ages a batch by **12 hours** instead of 6 days so it still falls under the new default. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 057a2ef. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: Cursor <cursoragent@cursor.com>
The unknown-flag de-duplication set added in 68d3dbf is backed by a ConcurrentHashMap, which rejects null, so variation(null, ...) threw a NullPointerException on the caller's thread. A null key now skips the de-duplication and returns the default, as it did before. Co-authored-by: Cursor <cursoragent@cursor.com>
…test-app-event-storage
There was a problem hiding this comment.
Risk: medium.
Automated risk review (dry run): Medium
This PR would not be automatically approved. Human approval required.
Why: Besides the test-app Event storage inspector, this diff changes production SDK event delivery by moving DirectEventProcessor recovery and scheduled tasks from the constructor into start(). That is a meaningful behavior change, so it is Medium and would not be auto-approved.
Human review is needed and no reviewers were assigned.
If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.
Sent by Cursor Approval Agent: Dry-Run PR Approver
…ty-tier1-buffer Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # launchdarkly-android-client-sdk/build.gradle # launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java # shared-test-code/build.gradle
…-durability-tier2-bounded-flush
…y/event-durability-tier3-persistence
…test-app-event-storage
Persisted batches are posted by AnalyticsEventSender, which ignored EventProcessorBuilder.enableCompression, so only diagnostic events were compressed. The batch on disk stays plain JSON; each attempt compresses it, and one that cannot be compressed goes uncompressed. Co-authored-by: Cursor <cursoragent@cursor.com>
…test-app-event-storage
…o be discarded sdk-test-harness v2.46.0 added "events/delivery retry/payload is discarded if the retry also fails". With persistence, a batch whose retry fails is kept and posted again later (DeliveryRetryState: a failure never stops delivery), so the next post repeats the payload instead of carrying only the later event. The other delivery retry tests pass. Co-authored-by: Cursor <cursoragent@cursor.com>
…test-app-event-storage
Base automatically changed from
andrey/event-durability-tier3-persistence
to
main
November 21, 2026 01:50
This branch has not been deployed
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.


Adds an Event storage view to the test app, as the iOS test app has: what the SDK has on disk for this app and mobile key.
Stacked on #408 (tier 3).
The view is a text block under the persistence picker. A summary line, "N log(s), N batch(es) holding N event(s)", is followed by the newest six files. Each line gives the file's kind (
log,new,batch), its shortened name, the event count a batch's name holds, its size and its modification time to the second:onResumetoonPause. A file that comes and goes within a second, such as anew-log being opened, is never shown.EventDirectory.defaultDirectoryis package-private, so a smallcom.launchdarkly.sdk.android.EventStorageLocationin the test app exposes it, the wayEventPersistenceBenchmarkRunneralready reaches into the package. The view cannot drift from where the SDK writes.Tested on an emulator (API 23):
ready-batches of 7 events each. That matchesadb shell run-as … ls -l no_backup/com.launchdarkly.events/<key>file for file.:test-app:assembleDebugbuilds.Note
Overview
Adds a live on-disk event storage panel to the Android test app (pending logs and ready batches, refreshed every second while foregrounded, long-press to copy the directory path), backed by a small
EventStorageLocationhelper that resolves the same path the SDK uses.On the SDK side, startup work is no longer implicit in the
DirectEventProcessorconstructor: recovery of persisted logs and periodic flush/diagnostics scheduling move to an explicitstart()thatComponentsImpl.EventProcessorBuilderImpl#buildinvokes immediately after construction. Tests gainmakeUnstartedEventProcessorand a new case proving a left-open log is not recovered untilstart()runs.Reviewed by Cursor Bugbot for commit 91fd06d. Bugbot is set up for automated code reviews on this repo. Configure here.