Skip to content

Commit 4e7c0fb

Browse files
authored
Pass through Common SDK API (#71)
* wip * target Java 8 * linter 🙄
1 parent be8eded commit 4e7c0fb

File tree

3 files changed

+61
-16
lines changed

3 files changed

+61
-16
lines changed

build.gradle

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ plugins {
55
id "com.diffplug.spotless" version "6.13.0"
66
}
77

8+
java {
9+
sourceCompatibility = JavaVersion.VERSION_1_8
10+
targetCompatibility = JavaVersion.VERSION_1_8
11+
}
12+
813
group = 'cloud.eppo'
9-
version = '3.0.0-SNAPSHOT'
14+
version = '3.0.1-SNAPSHOT'
1015
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
1116

1217
import org.apache.tools.ant.filters.ReplaceTokens
@@ -25,10 +30,11 @@ repositories {
2530
}
2631

2732
dependencies {
28-
implementation 'cloud.eppo:sdk-common-jvm:3.0.1-SNAPSHOT'
33+
// Re-export classes and interfaces that will be used upstream
34+
api 'cloud.eppo:sdk-common-jvm:3.0.2-SNAPSHOT'
35+
2936
implementation 'com.github.zafarkhaja:java-semver:0.10.2'
3037
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'
31-
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
3238
implementation 'org.ehcache:ehcache:3.10.8'
3339
implementation 'org.slf4j:slf4j-api:2.0.13'
3440
// Logback classic 1.3.x is compatible with java 8
@@ -128,16 +134,18 @@ publishing {
128134
}
129135
}
130136

131-
signing {
132-
sign publishing.publications.mavenJava
133-
if (System.env['CI']) {
134-
useInMemoryPgpKeys(System.env.GPG_PRIVATE_KEY, System.env.GPG_PASSPHRASE)
137+
if (!project.gradle.startParameter.taskNames.contains('publishToMavenLocal')) {
138+
signing {
139+
sign publishing.publications.mavenJava
140+
if (System.env['CI']) {
141+
useInMemoryPgpKeys(System.env.GPG_PRIVATE_KEY, System.env.GPG_PASSPHRASE)
142+
}
135143
}
136144
}
137145

138-
139146
javadoc {
140147
if (JavaVersion.current().isJava9Compatible()) {
141148
options.addBooleanOption('html5', true)
142149
}
150+
options.addStringOption('Xdoclint:none', '-quiet')
143151
}

src/main/java/com/eppo/sdk/EppoClient.java

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
1111

12+
/**
13+
* Class used to ingest and use the flag and bandit configurations retrieved from Eppo This class
14+
* uses the Singleton pattern. First the singleton must be initialized via it's Builder's
15+
* buildAndInit() method. Then call getInstance() to access the singleton and call methods to get
16+
* assignments and bandit actions.
17+
*/
1218
public class EppoClient extends BaseEppoClient {
1319
private static final Logger log = LoggerFactory.getLogger(EppoClient.class);
1420

@@ -40,63 +46,92 @@ private EppoClient(
4046
apiKey, host, sdkName, sdkVersion, assignmentLogger, banditLogger, isGracefulModel, false);
4147
}
4248

49+
/** Stops the client from polling Eppo for updated flag and bandit configurations */
4350
public static void stopPolling() {
4451
if (pollTimer != null) {
4552
pollTimer.cancel();
4653
}
4754
}
4855

56+
/** Builder pattern to initialize the EppoClient singleton */
4957
public static class Builder {
5058
private String apiKey;
51-
private String host = DEFAULT_HOST;
5259
private AssignmentLogger assignmentLogger;
5360
private BanditLogger banditLogger;
5461
private boolean isGracefulMode = DEFAULT_IS_GRACEFUL_MODE;
5562
private boolean forceReinitialize = DEFAULT_FORCE_REINITIALIZE;
5663
private long pollingIntervalMs = DEFAULT_POLLING_INTERVAL_MS;
64+
private String host = DEFAULT_HOST;
5765

66+
/** Sets the API Key--created within the eppo application--to use. This is required. */
5867
public Builder apiKey(String apiKey) {
5968
this.apiKey = apiKey;
6069
return this;
6170
}
6271

63-
public Builder host(String host) {
64-
this.host = host;
65-
return this;
66-
}
67-
72+
/**
73+
* Assignment logger to use to record when variations were assigned. This is needed if you want
74+
* Eppo to analyze experiments controlled by flags.
75+
*/
6876
public Builder assignmentLogger(AssignmentLogger assignmentLogger) {
6977
this.assignmentLogger = assignmentLogger;
7078
return this;
7179
}
7280

81+
/**
82+
* Bandit logger to use to record when a bandit has assigned an action. This is needed if you
83+
* are using contextual multi-armed bandits.
84+
*/
7385
public Builder banditLogger(BanditLogger banditLogger) {
7486
this.banditLogger = banditLogger;
7587
return this;
7688
}
7789

90+
/**
91+
* Sets the initial graceful mode of the client. When on (which is the default), flag evaluation
92+
* errors will be caught, and the default value returned. When off, the errors will be rethrown.
93+
*/
7894
public Builder isGracefulMode(boolean isGracefulMode) {
7995
this.isGracefulMode = isGracefulMode;
8096
return this;
8197
}
8298

99+
/**
100+
* Sets whether the singleton client should be recreated if one already has been. fetch an
101+
* updated configuration. If true, a new client will be instantiated and a new fetch for
102+
* configurations will be performed. If false (which is the default), initialization will be
103+
* ignored and the previously initialized client will be used.
104+
*/
83105
public Builder forceReinitialize(boolean forceReinitialize) {
84106
this.forceReinitialize = forceReinitialize;
85107
return this;
86108
}
87109

110+
/**
111+
* Sets how often the client should check for updated configurations, in milliseconds. The
112+
* default is 30,000 (poll every 30 seconds).
113+
*/
88114
public Builder pollingIntervalMs(long pollingIntervalMs) {
89115
this.pollingIntervalMs = pollingIntervalMs;
90116
return this;
91117
}
92118

119+
/**
120+
* Overrides the host from where it fetches configurations. This typically should not be
121+
* explicitly set so that the default of the Fastly CDN is used.
122+
*/
123+
public Builder host(String host) {
124+
this.host = host;
125+
return this;
126+
}
127+
93128
public EppoClient buildAndInit() {
94129
AppDetails appDetails = AppDetails.getInstance();
95130
String sdkName = appDetails.getName();
96131
String sdkVersion = appDetails.getVersion();
97132

98133
if (instance != null) {
99-
if (forceReinitialize) { // TODO: unit test this
134+
if (forceReinitialize) {
100135
log.warn(
101136
"Eppo SDK is already initialized, reinitializing since forceReinitialize is true");
102137
} else {

src/test/java/com/eppo/sdk/EppoClientTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010

1111
import cloud.eppo.BaseEppoClient;
1212
import cloud.eppo.EppoHttpClient;
13+
import cloud.eppo.api.Attributes;
14+
import cloud.eppo.api.BanditActions;
15+
import cloud.eppo.api.BanditResult;
1316
import cloud.eppo.helpers.AssignmentTestCase;
1417
import cloud.eppo.helpers.BanditTestCase;
1518
import cloud.eppo.helpers.TestUtils;
1619
import cloud.eppo.logging.Assignment;
1720
import cloud.eppo.logging.AssignmentLogger;
1821
import cloud.eppo.logging.BanditAssignment;
1922
import cloud.eppo.logging.BanditLogger;
20-
import cloud.eppo.ufc.dto.*;
2123
import com.github.tomakehurst.wiremock.WireMockServer;
2224
import com.github.tomakehurst.wiremock.client.WireMock;
2325
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;

0 commit comments

Comments
 (0)