Class EvaluationExposureDeduper
Deduplication is opt-in per hook: a hook is told about every evaluation until you wrap it in a
DedupingHook, which is what consults a deduper.
Components.hooks()
.addHook(new MetricsHook()) // told about every evaluation
.addHook(new DedupingHook(new ObservabilityHook())) // default window
.addHook(new DedupingHook(new TelemetryHook(), 30_000))
.addHook(new DedupingHook(new ExperimentHook(), myCustomDeduper))
This class is the SDK's implementation: it remembers the result each flag last reported, and tells
the hook about the flag again as soon as that result changes, or once the window elapses while it
stays the same. Tracking one result per flag rather than every result seen keeps a flag that flips
back and forth from hiding the flips, and holds one record per flag the application evaluates, so
the window is the only thing there is to configure. Subclass this to implement a different policy;
only shouldRecord(EvaluationExposureKey, long) and reset() are called by
DedupingHook.
A deduper is consulted once per evaluation, before the series opens, so a suppressed evaluation
invokes neither beforeEvaluation nor afterEvaluation. Implementations must be
thread-safe, because evaluations may be made from any thread. Give each hook its own instance
unless you intend hooks to share a window: the first hook to be told about an exposure starts the
window that suppresses the rest.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe dedupe window used by a deduper built without a window of its own: 10 minutes, in milliseconds. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a deduper with a window ofDEFAULT_WINDOW_MILLIS.EvaluationExposureDeduper(int windowMillis) -
Method Summary
Modifier and TypeMethodDescriptionvoidreset()Clears all recorded exposures, so the next evaluation of each is reported again.booleanshouldRecord(EvaluationExposureKey key, long nowMillis) Returns whether the hook should be told about the evaluation identified by the given key, and if so starts a new dedupe window for the flag.
-
Field Details
-
DEFAULT_WINDOW_MILLIS
public static final int DEFAULT_WINDOW_MILLISThe dedupe window used by a deduper built without a window of its own: 10 minutes, in milliseconds.- See Also:
-
-
Constructor Details
-
EvaluationExposureDeduper
public EvaluationExposureDeduper()Creates a deduper with a window ofDEFAULT_WINDOW_MILLIS. -
EvaluationExposureDeduper
public EvaluationExposureDeduper(int windowMillis) - Parameters:
windowMillis- the dedupe window in milliseconds; zero or negative disables deduplication, so every evaluation reaches the hook
-
-
Method Details
-
shouldRecord
Returns whether the hook should be told about the evaluation identified by the given key, and if so starts a new dedupe window for the flag.DedupingHookcalls this once per evaluation. This implementation answers true when the flag is reporting a different result than it last did, and when the window has elapsed on the result it is repeating. SeeEvaluationExposureKeyfor what makes two evaluations the same result.- Parameters:
key- the key identifying the evaluation resultnowMillis- a reading of a clock that counts from an arbitrary point, in milliseconds.DedupingHookpassesSystemClock.elapsedRealtime(), so that correcting the device clock cannot stretch a window. Only differences between readings are meaningful: this is not a time of day, and comparing it withSystem.currentTimeMillis()is a mistake.- Returns:
- true if the hook should observe this evaluation, false if it should be suppressed
-
reset
public void reset()Clears all recorded exposures, so the next evaluation of each is reported again.DedupingHookcalls this when the evaluation context changes.
-