feat(rum): apply a rate that leaves zero to the running session - #44
Open
Fiona2016 wants to merge 1 commit into
Open
feat(rum): apply a rate that leaves zero to the running session#44Fiona2016 wants to merge 1 commit into
Fiona2016 wants to merge 1 commit into
Conversation
A session sample rate published above 0 now ends the session of a visitor whose session was drawn AT 0, so collection starts at their next interaction instead of waiting for that session to rotate -- up to four hours. This is the case where waiting shows an operator who has just switched collection on nothing at all, and nothing at all is indistinguishable from a broken integration. It joins the two changes that already did not wait: a stricter privacy level, and a rate of 0. Written against the rate the session was DRAWN at rather than against whether it is being collected, which is what keeps it honest. Re-drawing every session that is not collected would spare the winners and re-roll the losers, so a fleet drawn at 20 and moved to 50 would come out at 60. A rate of 0 is the one value with no winners to spare -- nothing was collected and no coin was flipped -- so re-drawing everyone lands exactly on the new rate. A rate rising from one real value to another therefore still waits. Answering that question needed a record a sampled-out session never had. Such a session is given no id, so its draw was not recorded at all and the rate it was drawn at fell back to init -- which reads a session that lost a draw at 30 as one drawn at 0 and re-draws it, the bias above. Its draw is now recorded in the same single entry as a collected session's, under an id no session can hold, so the two cannot read each other's. That sentinel shares one id across every sampled-out session, so the id check that makes a stale record inert for a collected session does nothing here. What replaces it is that the page which draws now owns the slot: reportDraw hands over every draw rather than only the ones worth keeping, so a draw that lands on the init values clears the record instead of leaving the previous session's behind to answer for it. Resolving a rate runs the site's beforeSampling callback, so it is asked only where the answer settles whether the session ends, not once per announcement for every visitor.
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.
A session sample rate published above 0 now ends the session of a visitor whose
session was drawn at 0, so collection starts at their next interaction rather
than waiting for that session to rotate — up to four hours. It joins the two
changes that already did not wait: a stricter default privacy level, and a rate
of 0.
This is the case where waiting shows an operator who has just switched collection
on nothing at all, and nothing at all is indistinguishable from a broken
integration.
Why only a session drawn at 0
The rule is written against the rate the session was drawn at, not against
whether it is currently being collected. Re-drawing every session that is not
collected would spare the winners and re-roll the losers, so a fleet drawn at 20
and moved to 50 would come out at 60. A rate of 0 is the one value with no
winners to spare — nothing was collected and no coin was flipped — so re-drawing
everyone lands exactly on the new rate.
A rate rising from one real value to another still waits for the next session, as
before: only a second draw could say whether a session drawn at 30 should have
been kept at 80, and drawing twice turns a rate p into p².
Recording the draw of a sampled-out session
Answering that question needed a record such a session never had. A session that
loses its draw is given no id, so its draw was not recorded at all and the rate it
was drawn at fell back to the init value — which reads a session that lost a draw
at 30 as one drawn at 0, the bias above. Its draw now goes into the same single
localStorageentry a collected session's goes to, under an id no session canhold, so neither can read the other's. No new storage entry and no extra request.
That sentinel shares one id across every sampled-out session, so the id check that
makes a stale record inert for a collected session does nothing there. What
replaces it: the page that draws owns the slot.
reportDrawnow hands over everydraw rather than only the ones worth keeping, so a draw landing on the init values
clears the record instead of leaving the previous session's behind to answer for
it.
Also
Resolving a rate runs the site's
beforeSamplingcallback, so it is now askedonly where the answer settles whether the session ends, rather than once per
delivered configuration for every visitor.
Tests
yarn test:unit— 2998 passing. Nine tests added, two that asserted the previousbehaviour removed. Each new rule was checked by reverting the implementation and
confirming the intended tests fail:
beforeSamplingnot consulted when no rate could decide anything