Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorated impressions #725

Merged
merged 39 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
489bc31
WIP
gthea Nov 27, 2024
a5f7c5e
New tests
gthea Nov 27, 2024
a416b0c
Cleanup
gthea Nov 27, 2024
f5373dc
WIP integration
gthea Nov 29, 2024
ba92544
Merge branch 'SDKS-9072_baseline' into SDKS-9031
gthea Nov 29, 2024
4d0b415
Tests modifications
gthea Nov 29, 2024
428bb5b
WIP
gthea Dec 2, 2024
4532d4a
Refactor
gthea Dec 2, 2024
fb3d56f
Fix tests
gthea Dec 2, 2024
ff03a85
Update tests
gthea Dec 2, 2024
015180d
Track segments sync by Key
gthea Dec 3, 2024
f4ea326
Rollout config
gthea Dec 3, 2024
a9d47fe
Fixes
gthea Dec 3, 2024
c8eefc8
WIP int tests
gthea Dec 4, 2024
f65f0ae
WIP
gthea Dec 4, 2024
48a311f
qMerge branch 'SDKS-9072_baseline' into SDKS-9040
gthea Dec 4, 2024
6234fa7
WIP
gthea Dec 5, 2024
f645892
Remove unused method
gthea Dec 5, 2024
b0b52aa
Remove unused method
gthea Dec 5, 2024
55d3cbb
Rename config
gthea Dec 5, 2024
06ce624
Emit SDK_READY_FROM_CACHE alongside SDK_READY, if not previously emitted
gthea Dec 5, 2024
57c4841
Merge branch 'SDKS-9072_baseline' into SDKS-9079
gthea Dec 5, 2024
910a82e
Fix test
gthea Dec 5, 2024
18779a1
Update version
gthea Dec 6, 2024
034f0cd
Fix test
gthea Dec 9, 2024
9f371a0
WIP
gthea Dec 9, 2024
ed204a7
WIP
gthea Dec 10, 2024
a041c52
WIP
gthea Dec 10, 2024
552b9ec
Minor changes to UC tests
gthea Dec 10, 2024
9f7f97a
Wip test changes
gthea Dec 10, 2024
4c3b592
Update recorder sync helper to handle multiple listeners
gthea Dec 10, 2024
89f2ece
Merge branch 'SDKS-9104_baseline' into SDKS-9095
gthea Dec 11, 2024
8d8e161
Fix test
gthea Dec 12, 2024
872f01e
Add trackImpressions to Split DTO
gthea Dec 11, 2024
3845f39
Add trackImpressions to SplitView
gthea Dec 12, 2024
23d0758
Decorated impression & evaluation result changes
gthea Dec 11, 2024
ad32409
WIP
gthea Dec 12, 2024
b0b321b
Fix tests comp issue
gthea Dec 12, 2024
ee51a6c
Merge branch 'SDKS-9104_baseline' into SDKS-9151
gthea Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/androidTest/java/fake/SyncManagerStub.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fake;

import io.split.android.client.dtos.Event;
import io.split.android.client.impressions.Impression;
import io.split.android.client.impressions.DecoratedImpression;
import io.split.android.client.service.synchronizer.SyncManager;
import io.split.android.client.shared.UserConsent;

Expand Down Expand Up @@ -42,6 +42,6 @@ public void pushEvent(Event event) {
}

@Override
public void pushImpression(Impression impression) {
public void pushImpression(DecoratedImpression impression) {
}
}
4 changes: 2 additions & 2 deletions src/androidTest/java/fake/SynchronizerSpyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import io.split.android.client.api.Key;
import io.split.android.client.dtos.Event;
import io.split.android.client.impressions.Impression;
import io.split.android.client.impressions.DecoratedImpression;
import io.split.android.client.service.synchronizer.Synchronizer;
import io.split.android.client.service.synchronizer.SynchronizerSpy;
import io.split.android.client.service.synchronizer.attributes.AttributesSynchronizer;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void pushEvent(Event event) {
}

@Override
public void pushImpression(Impression impression) {
public void pushImpression(DecoratedImpression impression) {
mSynchronizer.pushImpression(impression);
}

Expand Down
21 changes: 17 additions & 4 deletions src/main/java/io/split/android/client/EvaluationResult.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
package io.split.android.client;

import androidx.annotation.VisibleForTesting;

public final class EvaluationResult {
private final String mTreatment;
private final String mLabel;
private final Long mChangeNumber;
private final String mConfigurations;
private final boolean mTrackImpression;

@VisibleForTesting
public EvaluationResult(String treatment, String label) {
this(treatment, label, null);
this(treatment, label, null, null, true);
}

public EvaluationResult(String treatment, String label, boolean trackImpression) {
this(treatment, label, null, null, trackImpression);
}

EvaluationResult(String treatment, String label, Long changeNumber) {
this(treatment, label, changeNumber, null);
EvaluationResult(String treatment, String label, Long changeNumber, boolean trackImpression) {
this(treatment, label, changeNumber, null, trackImpression);
}

public EvaluationResult(String treatment, String label, Long changeNumber, String configurations) {
public EvaluationResult(String treatment, String label, Long changeNumber, String configurations, boolean trackImpression) {
mTreatment = treatment;
mLabel = label;
mChangeNumber = changeNumber;
mConfigurations = configurations;
mTrackImpression = trackImpression;
}

public String getTreatment() {
Expand All @@ -36,4 +45,8 @@ public Long getChangeNumber() {
public String getConfigurations() {
return mConfigurations;
}

public boolean getTrackImpression() {
return mTrackImpression;
}
}
14 changes: 7 additions & 7 deletions src/main/java/io/split/android/client/EvaluatorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ public EvaluationResult getTreatment(String matchingKey, String bucketingKey, St
try {
ParsedSplit parsedSplit = mSplitParser.parse(mSplitsStorage.get(splitName), matchingKey);
if (parsedSplit == null) {
return new EvaluationResult(Treatments.CONTROL, TreatmentLabels.DEFINITION_NOT_FOUND);
return new EvaluationResult(Treatments.CONTROL, TreatmentLabels.DEFINITION_NOT_FOUND, true);
}

return getTreatment(matchingKey, bucketingKey, parsedSplit, attributes);
} catch (ChangeNumberExceptionWrapper ex) {
Logger.e(ex, "Catch Change Number Exception");
return new EvaluationResult(Treatments.CONTROL, TreatmentLabels.EXCEPTION, ex.changeNumber());
return new EvaluationResult(Treatments.CONTROL, TreatmentLabels.EXCEPTION, ex.changeNumber(), true);
} catch (Exception e) {
Logger.e(e, "Catch All Exception");
return new EvaluationResult(Treatments.CONTROL, TreatmentLabels.EXCEPTION);
return new EvaluationResult(Treatments.CONTROL, TreatmentLabels.EXCEPTION, true);
}
}

Expand All @@ -52,7 +52,7 @@ public EvaluationResult getTreatment(String matchingKey, String bucketingKey, St
private EvaluationResult getTreatment(String matchingKey, String bucketingKey, ParsedSplit parsedSplit, Map<String, Object> attributes) throws ChangeNumberExceptionWrapper {
try {
if (parsedSplit.killed()) {
return new EvaluationResult(parsedSplit.defaultTreatment(), TreatmentLabels.KILLED, parsedSplit.changeNumber(), configForTreatment(parsedSplit, parsedSplit.defaultTreatment()));
return new EvaluationResult(parsedSplit.defaultTreatment(), TreatmentLabels.KILLED, parsedSplit.changeNumber(), configForTreatment(parsedSplit, parsedSplit.defaultTreatment()), parsedSplit.trackImpressions());
}

/*
Expand All @@ -75,7 +75,7 @@ private EvaluationResult getTreatment(String matchingKey, String bucketingKey, P

if (bucket > parsedSplit.trafficAllocation()) {
// out of split
return new EvaluationResult(parsedSplit.defaultTreatment(), TreatmentLabels.NOT_IN_SPLIT, parsedSplit.changeNumber(), configForTreatment(parsedSplit, parsedSplit.defaultTreatment()));
return new EvaluationResult(parsedSplit.defaultTreatment(), TreatmentLabels.NOT_IN_SPLIT, parsedSplit.changeNumber(), configForTreatment(parsedSplit, parsedSplit.defaultTreatment()), parsedSplit.trackImpressions());
}

}
Expand All @@ -84,11 +84,11 @@ private EvaluationResult getTreatment(String matchingKey, String bucketingKey, P

if (parsedCondition.matcher().match(matchingKey, bucketingKey, attributes, this)) {
String treatment = Splitter.getTreatment(bk, parsedSplit.seed(), parsedCondition.partitions(), parsedSplit.algo());
return new EvaluationResult(treatment, parsedCondition.label(), parsedSplit.changeNumber(), configForTreatment(parsedSplit, treatment));
return new EvaluationResult(treatment, parsedCondition.label(), parsedSplit.changeNumber(), configForTreatment(parsedSplit, treatment), parsedSplit.trackImpressions());
}
}

return new EvaluationResult(parsedSplit.defaultTreatment(), TreatmentLabels.DEFAULT_RULE, parsedSplit.changeNumber(), configForTreatment(parsedSplit, parsedSplit.defaultTreatment()));
return new EvaluationResult(parsedSplit.defaultTreatment(), TreatmentLabels.DEFAULT_RULE, parsedSplit.changeNumber(), configForTreatment(parsedSplit, parsedSplit.defaultTreatment()), parsedSplit.trackImpressions());
} catch (Exception e) {
throw new ChangeNumberExceptionWrapper(e, parsedSplit.changeNumber());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import io.split.android.client.service.mysegments.MySegmentsTaskFactory;
import io.split.android.client.service.synchronizer.SyncManager;
import io.split.android.client.shared.SplitClientContainer;
import io.split.android.client.storage.common.SplitStorageContainer;
import io.split.android.client.storage.attributes.AttributesStorage;
import io.split.android.client.storage.attributes.PersistentAttributesStorage;
import io.split.android.client.storage.common.SplitStorageContainer;
import io.split.android.client.storage.splits.SplitsStorage;
import io.split.android.client.telemetry.TelemetrySynchronizer;
import io.split.android.client.telemetry.storage.TelemetryInitProducer;
Expand All @@ -43,7 +43,7 @@ public class SplitClientFactoryImpl implements SplitClientFactory {
private final SplitParser mSplitParser;
private final AttributesManagerFactory mAttributesManagerFactory;
private final TreatmentManagerFactory mTreatmentManagerFactory;
private final ImpressionListener mCustomerImpressionListener;
private final ImpressionListener.FederatedImpressionListener mCustomerImpressionListener;
private final SplitValidatorImpl mSplitValidator;
private final EventsTracker mEventsTracker;

Expand All @@ -57,7 +57,7 @@ public SplitClientFactoryImpl(@NonNull SplitFactory splitFactory,
@NonNull ValidationMessageLogger validationLogger,
@NonNull KeyValidator keyValidator,
@NonNull EventsTracker eventsTracker,
@NonNull ImpressionListener customerImpressionListener,
@NonNull ImpressionListener.FederatedImpressionListener customerImpressionListener,
@Nullable FlagSetsFilter flagSetsFilter) {
mSplitFactory = checkNotNull(splitFactory);
mClientContainer = checkNotNull(clientContainer);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/split/android/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.split.android.client.events.EventsManagerCoordinator;
import io.split.android.client.factory.FactoryMonitor;
import io.split.android.client.factory.FactoryMonitorImpl;
import io.split.android.client.impressions.DecoratedImpressionListener;
import io.split.android.client.impressions.ImpressionListener;
import io.split.android.client.impressions.SyncImpressionListener;
import io.split.android.client.lifecycle.SplitLifecycleManager;
Expand Down Expand Up @@ -243,17 +244,16 @@ private SplitFactoryImpl(@NonNull String apiToken, @NonNull Key key, @NonNull Sp
}

ExecutorService impressionsLoggingTaskExecutor = factoryHelper.getImpressionsLoggingTaskExecutor();
final ImpressionListener splitImpressionListener
final DecoratedImpressionListener splitImpressionListener
= new SyncImpressionListener(mSyncManager, impressionsLoggingTaskExecutor);
final ImpressionListener customerImpressionListener;
final ImpressionListener.FederatedImpressionListener customerImpressionListener;

List<ImpressionListener> impressionListeners = new ArrayList<>();
if (config.impressionListener() != null) {
List<ImpressionListener> impressionListeners = new ArrayList<>();
impressionListeners.add(splitImpressionListener);
impressionListeners.add(config.impressionListener());
customerImpressionListener = new ImpressionListener.FederatedImpressionListener(impressionListeners);
customerImpressionListener = new ImpressionListener.FederatedImpressionListener(splitImpressionListener, impressionListeners);
} else {
customerImpressionListener = splitImpressionListener;
customerImpressionListener = new ImpressionListener.FederatedImpressionListener(splitImpressionListener, impressionListeners);
}
EventsTracker eventsTracker = buildEventsTracker();
mUserConsentManager = new UserConsentManagerImpl(config,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.split.android.client.impressions;

public class DecoratedImpression {

private final Impression mImpression;
private final boolean mTrackImpressions;

public DecoratedImpression(Impression impression, boolean trackImpressions) {
mImpression = impression;
mTrackImpressions = trackImpressions;
}

public Impression getImpression() {
return mImpression;
}

public boolean getTrackImpressions() {
return mTrackImpressions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.split.android.client.impressions;

public interface DecoratedImpressionListener {

void log(DecoratedImpression impression);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,29 @@ public interface ImpressionListener {
*/
void close();

final class NoopImpressionListener implements ImpressionListener {
final class NoopImpressionListener implements ImpressionListener, DecoratedImpressionListener {
@Override
public void log(Impression impression) {
// noop
}

@Override
public void log(DecoratedImpression impression) {

}

@Override
public void close() {
// noop
}
}

final class FederatedImpressionListener implements ImpressionListener {
private List<ImpressionListener> _delegates;
final class FederatedImpressionListener implements ImpressionListener, DecoratedImpressionListener {
private final DecoratedImpressionListener mDecoratedImpressionListener;
private final List<ImpressionListener> _delegates;

public FederatedImpressionListener(List<ImpressionListener> delegates) {
public FederatedImpressionListener(DecoratedImpressionListener decoratedImpressionListener, List<ImpressionListener> delegates) {
mDecoratedImpressionListener = decoratedImpressionListener;
_delegates = delegates;
}

Expand All @@ -45,6 +52,11 @@ public void log(Impression impression) {
}
}

@Override
public void log(DecoratedImpression impression) {
mDecoratedImpressionListener.log(impression);
}

@Override
public void close() {
for (ImpressionListener listener : _delegates) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
class ImpressionLoggingTask implements Runnable {

private final SyncManager mSyncManager;
private final Impression mImpression;
private final DecoratedImpression mImpression;

ImpressionLoggingTask(@NonNull SyncManager syncManager,
Impression impression) {
DecoratedImpression impression) {
mSyncManager = checkNotNull(syncManager);
mImpression = impression;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.split.android.client.service.synchronizer.SyncManager;
import io.split.android.client.utils.logger.Logger;

public class SyncImpressionListener implements ImpressionListener {
public class SyncImpressionListener implements DecoratedImpressionListener {

private final SyncManager mSyncManager;
private final ExecutorService mExecutorService;
Expand All @@ -21,15 +21,11 @@ public SyncImpressionListener(@NonNull SyncManager syncManager,
}

@Override
public void log(Impression impression) {
public void log(DecoratedImpression impression) {
try {
mExecutorService.submit(new ImpressionLoggingTask(mSyncManager, impression));
} catch (Exception ex) {
Logger.w("Error submitting impression logging task: " + ex.getLocalizedMessage());
}
}

@Override
public void close() {
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package io.split.android.client.localhost;

import io.split.android.client.impressions.DecoratedImpression;
import io.split.android.client.impressions.DecoratedImpressionListener;
import io.split.android.client.impressions.Impression;
import io.split.android.client.impressions.ImpressionListener;

public class LocalhostImpressionsListener implements ImpressionListener {
public class LocalhostImpressionsListener implements ImpressionListener, DecoratedImpressionListener {
@Override
public void log(Impression impression) {
}

@Override
public void log(DecoratedImpression impression) {
}

@Override
public void close() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ public boolean track(String eventType, double value, Map<String, Object> propert
return false;
}

private ImpressionListener getImpressionsListener(SplitClientConfig config) {
private ImpressionListener.FederatedImpressionListener getImpressionsListener(SplitClientConfig config) {
if (config.impressionListener() != null) {
return config.impressionListener();
return new ImpressionListener.FederatedImpressionListener(new ImpressionListener.NoopImpressionListener(), Collections.singletonList(config.impressionListener()));
} else {
return new LocalhostImpressionsListener();
return new ImpressionListener.FederatedImpressionListener(new ImpressionListener.NoopImpressionListener(), Collections.emptyList());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.split.android.client.service.impressions;

import io.split.android.client.impressions.Impression;
import io.split.android.client.impressions.DecoratedImpression;

public interface ImpressionManager {

void enableTracking(boolean enable);

void pushImpression(Impression impression);
void pushImpression(DecoratedImpression impression);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import io.split.android.client.impressions.Impression;
import io.split.android.client.impressions.DecoratedImpression;
import io.split.android.client.service.impressions.strategy.PeriodicTracker;
import io.split.android.client.service.impressions.strategy.ProcessStrategy;
import io.split.android.client.utils.logger.Logger;
Expand All @@ -33,16 +33,16 @@ public StrategyImpressionManager(Pair<ProcessStrategy, PeriodicTracker> noneComp
}

@Override
public void pushImpression(Impression impression) {
public void pushImpression(DecoratedImpression impression) {
if (!isTrackingEnabled.get()) {
Logger.v("Impression not tracked because tracking is disabled");
return;
}

if (track(impression)) {
mProcessStrategy.apply(impression);
if (impression.getTrackImpressions()) {
mProcessStrategy.apply(impression.getImpression());
} else {
mNoneStrategy.apply(impression);
mNoneStrategy.apply(impression.getImpression());
}
}

Expand Down Expand Up @@ -71,8 +71,4 @@ public void stopPeriodicRecording() {
tracker.stopPeriodicRecording();
}
}

private static boolean track(Impression impression) {
return true; // TODO: Placeholder method
}
}
Loading
Loading