Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
[EN-17473] Propagate the variation name to the AssignmentLogData
Browse files Browse the repository at this point in the history
  • Loading branch information
simondale00 committed Jan 25, 2024
1 parent 00717d8 commit 0ddfb37
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.glossgenius</groupId>
<artifactId>eppo-java-server-sdk</artifactId>
<version>2.1.0-0.1.1</version>
<version>2.1.0-0.2.0</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>Eppo Server-Side SDK for Java</description>
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/com/eppo/sdk/EppoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Timer;

import static com.eppo.sdk.dto.AssignmentLogData.OVERRIDE_ALLOCATION_KEY;
import static com.eppo.sdk.dto.AssignmentLogData.OVERRIDE_ASSIGNMENT_NAME;

@Slf4j
public class EppoClient {
Expand Down Expand Up @@ -78,7 +79,14 @@ public Optional<AssignmentLogData> getAssignmentWithDetails(
// Check if subject has override variations
EppoValue subjectVariationOverride = this.getSubjectVariationOverride(subjectKey, configuration);
if (!subjectVariationOverride.isNull()) {
AssignmentLogData data = getAssignmentLogData(subjectKey, flagKey, subjectAttributes, OVERRIDE_ALLOCATION_KEY, subjectVariationOverride);
AssignmentLogData data = getAssignmentLogData(
subjectKey,
flagKey,
subjectAttributes,
OVERRIDE_ALLOCATION_KEY,
OVERRIDE_ASSIGNMENT_NAME,
subjectVariationOverride
);
return Optional.of(data);
}

Expand Down Expand Up @@ -107,7 +115,16 @@ public Optional<AssignmentLogData> getAssignmentWithDetails(
// Get assigned variation
Variation assignedVariation = this.getAssignedVariation(subjectKey, flagKey, configuration.getSubjectShards(),
allocation.getVariations());
return Optional.of(getAssignmentLogData(subjectKey, flagKey, subjectAttributes, allocationKey, assignedVariation.getTypedValue()));
return Optional.of(
getAssignmentLogData(
subjectKey,
flagKey,
subjectAttributes,
allocationKey,
assignedVariation.getName(),
assignedVariation.getTypedValue()
)
);
}

/**
Expand Down Expand Up @@ -146,12 +163,15 @@ private AssignmentLogData getAssignmentLogData(
String flagKey,
SubjectAttributes subjectAttributes,
String allocationKey,
EppoValue assignmentValue) {
String assignmentName,
EppoValue assignmentValue
) {
String experimentKey = ExperimentHelper.generateKey(flagKey, allocationKey);
return new AssignmentLogData(
experimentKey,
flagKey,
allocationKey,
assignmentName,
assignmentValue,
subjectKey,
subjectAttributes);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/eppo/sdk/dto/AssignmentLogData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
public class AssignmentLogData {
public static final String OVERRIDE_ALLOCATION_KEY = "override";

public static final String OVERRIDE_ASSIGNMENT_NAME = "override_assignment";

public String experiment;
public String featureFlag;
public String allocation;
Expand All @@ -21,6 +23,7 @@ public AssignmentLogData(
String experiment,
String featureFlag,
String allocation,
String variationName,
EppoValue variationValue,
String subject,
SubjectAttributes subjectAttributes
Expand All @@ -29,7 +32,7 @@ public AssignmentLogData(
this.featureFlag = featureFlag;
this.allocation = allocation;
this.variationValue = variationValue;
this.variation = variationValue.stringValue();
this.variation = variationName;
this.timestamp = new Date();
this.subject = subject;
this.subjectAttributes = subjectAttributes;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/eppo/sdk/dto/Variation.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.eppo.sdk.dto;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* Experiment's Variation Class
*/
@Data
public class Variation {
private String name;
private EppoValue typedValue;
private ShardRange shardRange;
}

0 comments on commit 0ddfb37

Please sign in to comment.