Skip to content

Commit a207eb9

Browse files
committed
Fix agentless feature flagging CI coverage
1 parent e4393c2 commit a207eb9

5 files changed

Lines changed: 265 additions & 30 deletions

File tree

dd-smoke-tests/openfeature/src/test/groovy/datadog/smoketest/springboot/OpenFeatureProviderSmokeTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class OpenFeatureProviderSmokeTest extends AbstractServerSmokeTest {
4242
command.addAll(['-jar', springBootShadowJar, "--server.port=${httpPort}".toString()])
4343
final builder = new ProcessBuilder(command).directory(new File(buildDirectory))
4444
builder.environment().put('DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED', 'true')
45+
builder.environment().put('DD_FEATURE_FLAGS_CONFIGURATION_SOURCE', 'remote_config')
4546
return builder
4647
}
4748

products/feature-flagging/feature-flagging-agent/src/main/java/com/datadog/featureflag/FeatureFlaggingSystem.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,18 @@ static ConfigurationSourceService createConfigurationSourceService(
3434
final ConfigurationSource configurationSource =
3535
ConfigurationSource.from(config.getFeatureFlaggingConfigurationSource());
3636

37-
switch (configurationSource) {
38-
case REMOTE_CONFIG:
39-
if (!config.isRemoteConfigEnabled()) {
40-
throw new IllegalStateException("Feature Flagging system started without RC");
41-
}
42-
return new RemoteConfigServiceImpl(sco, config);
43-
case AGENTLESS:
44-
return new AgentlessConfigurationSource(config);
45-
case OFFLINE:
46-
LOGGER.debug(
47-
"Feature Flagging offline configuration source selected; no config service started");
48-
return null;
49-
default:
50-
throw new IllegalArgumentException(
51-
"Unsupported Feature Flagging configuration source: "
52-
+ config.getFeatureFlaggingConfigurationSource());
37+
if (configurationSource == ConfigurationSource.REMOTE_CONFIG) {
38+
if (!config.isRemoteConfigEnabled()) {
39+
throw new IllegalStateException("Feature Flagging system started without RC");
40+
}
41+
return new RemoteConfigServiceImpl(sco, config);
42+
}
43+
if (configurationSource == ConfigurationSource.AGENTLESS) {
44+
return new AgentlessConfigurationSource(config);
5345
}
46+
LOGGER.debug(
47+
"Feature Flagging offline configuration source selected; no config service started");
48+
return null;
5449
}
5550

5651
public static void stop() {

products/feature-flagging/feature-flagging-agent/src/test/java/com/datadog/featureflag/FeatureFlaggingSystemTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static datadog.trace.api.config.FeatureFlaggingConfig.FEATURE_FLAGS_CONFIGURATION_SOURCE;
44
import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIGURATION_ENABLED;
5+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
56
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
67
import static org.junit.jupiter.api.Assertions.assertNull;
78
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -109,6 +110,16 @@ void offlineConfigurationSourceDoesNotStartNetworkSource() {
109110
sharedCommunicationObjects(), Config.get()));
110111
}
111112

113+
@Test
114+
@WithConfig(key = FEATURE_FLAGS_CONFIGURATION_SOURCE, value = "offline")
115+
void startWithOfflineConfigurationSourceSkipsConfigService() {
116+
try {
117+
assertDoesNotThrow(() -> FeatureFlaggingSystem.start(sharedCommunicationObjects()));
118+
} finally {
119+
FeatureFlaggingSystem.stop();
120+
}
121+
}
122+
112123
private static SharedCommunicationObjects sharedCommunicationObjects() {
113124
DDAgentFeaturesDiscovery discovery = mock(DDAgentFeaturesDiscovery.class);
114125
when(discovery.supportsEvpProxy()).thenReturn(true);

products/feature-flagging/feature-flagging-lib/src/main/java/com/datadog/featureflag/AgentlessConfigurationSource.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void pollOnceSafely() {
113113
}
114114

115115
private boolean fetchAndApply() {
116-
for (int attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
116+
for (int attempt = 1; ; attempt++) {
117117
try {
118118
final UfcHttpResponse response = client.fetch(endpoint, config, etag);
119119
if (isRetryableStatus(response.status) && attempt < MAX_ATTEMPTS) {
@@ -127,7 +127,6 @@ private boolean fetchAndApply() {
127127
}
128128
}
129129
}
130-
return false;
131130
}
132131

133132
private boolean apply(final UfcHttpResponse response) {
@@ -220,10 +219,10 @@ static final class UfcHttpResponse {
220219
}
221220
}
222221

223-
private static final class OkHttpUfcHttpClient implements UfcHttpClient {
222+
static final class OkHttpUfcHttpClient implements UfcHttpClient {
224223
private final OkHttpClient httpClient;
225224

226-
private OkHttpUfcHttpClient(final OkHttpClient httpClient) {
225+
OkHttpUfcHttpClient(final OkHttpClient httpClient) {
227226
this.httpClient = httpClient;
228227
}
229228

@@ -237,15 +236,12 @@ public UfcHttpResponse fetch(final HttpUrl endpoint, final Config config, final
237236
final Request request = prepareRequest(endpoint, headers, config, true).get().build();
238237
try (Response response = httpClient.newCall(request).execute()) {
239238
final ResponseBody responseBody = response.body();
240-
return new UfcHttpResponse(
241-
response.code(),
242-
response.header("ETag"),
243-
responseBody == null ? null : responseBody.bytes());
239+
return new UfcHttpResponse(response.code(), response.header("ETag"), responseBody.bytes());
244240
}
245241
}
246242
}
247243

248-
private static final class UfcHttpThreadFactory implements ThreadFactory {
244+
static final class UfcHttpThreadFactory implements ThreadFactory {
249245
@Override
250246
public Thread newThread(final Runnable runnable) {
251247
final Thread thread = new Thread(runnable, "dd-feature-flagging-http-poller");

0 commit comments

Comments
 (0)