Skip to content

Commit d4e4bbf

Browse files
PerfectSlayerclaude
andcommitted
refactor(ffe): Expose the Feature Flags configuration source as an enum
Return the configuration source enum from Config now that the previous feature flagging code is gone, and drop the source value constants. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f21dcd8 commit d4e4bbf

6 files changed

Lines changed: 55 additions & 57 deletions

File tree

‎dd-java-agent/instrumentation/datadog/openfeature/dd-openfeature-connector/src/test/java/datadog/trace/instrumentation/openfeature/ConfigurationResolutionParityTest.java‎

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static datadog.trace.api.config.FeatureFlaggingConfig.EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED;
44
import static datadog.trace.api.config.FeatureFlaggingConfig.FEATURE_FLAGS_CONFIGURATION_SOURCE;
55
import static datadog.trace.api.config.FeatureFlaggingConfig.FEATURE_FLAGS_ENABLED;
6+
import static java.util.Locale.ROOT;
67
import static org.junit.jupiter.api.Assertions.assertEquals;
78
import static org.mockito.ArgumentMatchers.anyString;
89
import static org.mockito.Mockito.mock;
@@ -25,25 +26,26 @@
2526
@ExtendWith(WithConfigExtension.class)
2627
class ConfigurationResolutionParityTest {
2728
@TableTest({
28-
"Scenario | Enabled | Source | Legacy | Expected ",
29-
"defaults | | | | agentless ",
30-
"enabled | true | | | agentless ",
31-
"enabled as number | 1 | | | agentless ",
32-
"disabled | false | | | ",
33-
"disabled as number | 0 | | | ",
34-
"disabled wins over source | false | remote_config | | ",
35-
"remote config source | | remote_config | | remote_config",
36-
"agentless source | | agentless | | agentless ",
37-
"source is normalized | | ' Remote_Config' | | remote_config",
38-
"unsupported source | | offline | | ",
39-
"legacy enabled | | | true | remote_config",
40-
"legacy disabled | | | false | ",
41-
"source wins over legacy | | agentless | true | agentless ",
42-
"source wins over legacy disabled | | remote_config | false | remote_config",
43-
"enabled with legacy disabled | true | | false | ",
44-
"uppercase boolean | TRUE | | TRUE | remote_config",
45-
"invalid boolean reads as false | maybe | | | ",
46-
"invalid legacy reads as false | | | maybe | "
29+
"Scenario | Enabled | Source | Legacy | Expected ",
30+
"defaults | | | | agentless ",
31+
"enabled | true | | | agentless ",
32+
"enabled as number | 1 | | | agentless ",
33+
"disabled | false | | | ",
34+
"disabled as number | 0 | | | ",
35+
"disabled wins over source | false | remote_config | | ",
36+
"remote config source | | remote_config | | remote_config",
37+
"agentless source | | agentless | | agentless ",
38+
"source is case insensitive | | Remote_Config | | remote_config",
39+
"padded source is unsupported | | ' agentless ' | | ",
40+
"unsupported source | | offline | | ",
41+
"legacy enabled | | | true | remote_config",
42+
"legacy disabled | | | false | ",
43+
"source wins over legacy | | agentless | true | agentless ",
44+
"source wins over legacy disabled | | remote_config | false | remote_config",
45+
"enabled with legacy disabled | true | | false | ",
46+
"uppercase boolean | TRUE | | TRUE | remote_config",
47+
"invalid boolean reads as false | maybe | | | ",
48+
"invalid legacy reads as false | | | maybe | "
4749
})
4850
void agentAndSdkResolveTheSameConfiguration(
4951
final String enabled, final String source, final String legacy, final String expected) {
@@ -61,7 +63,7 @@ private static String agentSource(final Map<String, String> settings) {
6163
settings.forEach(WithConfigExtension::injectSysConfig);
6264
final InstrumenterConfig config = InstrumenterConfig.get();
6365
return config.isFeatureFlaggingEnabled()
64-
? config.getFeatureFlaggingConfigurationSource()
66+
? config.getFeatureFlaggingConfigurationSource().name().toLowerCase(ROOT)
6567
: null;
6668
}
6769

‎dd-trace-api/src/main/java/datadog/trace/api/config/FeatureFlaggingConfig.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,5 @@ public final class FeatureFlaggingConfig {
1313
public static final String FEATURE_FLAGS_CONFIGURATION_SOURCE =
1414
"feature.flags.configuration.source";
1515

16-
public static final String CONFIGURATION_SOURCE_AGENTLESS = "agentless";
17-
18-
public static final String CONFIGURATION_SOURCE_REMOTE_CONFIG = "remote_config";
19-
2016
private FeatureFlaggingConfig() {}
2117
}

‎internal-api/src/main/java/datadog/trace/api/Config.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4859,9 +4859,8 @@ public boolean isFeatureFlaggingProviderEnabled() {
48594859
return instrumenterConfig.isFeatureFlaggingEnabled();
48604860
}
48614861

4862-
public String getFeatureFlaggingConfigurationSource() {
4863-
final FeatureFlaggingSource source = instrumenterConfig.getFeatureFlaggingConfigurationSource();
4864-
return source == FeatureFlaggingSource.UNSET ? null : source.name().toLowerCase(Locale.ROOT);
4862+
public FeatureFlaggingSource getFeatureFlaggingConfigurationSource() {
4863+
return instrumenterConfig.getFeatureFlaggingConfigurationSource();
48654864
}
48664865

48674866
public boolean isDynamicInstrumentationEnabled() {

‎internal-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,13 +3588,13 @@ class ConfigTest extends DDSpecification {
35883588
35893589
where:
35903590
value | expected
3591-
null | "agentless"
3592-
"" | "agentless"
3593-
" " | "agentless"
3594-
"ReMoTe_ConFiG" | "remote_config"
3595-
" remote_config " | "invalid"
3596-
"not-a-real-source" | "invalid"
3597-
"unset" | "invalid"
3591+
null | FeatureFlaggingSource.AGENTLESS
3592+
"" | FeatureFlaggingSource.AGENTLESS
3593+
" " | FeatureFlaggingSource.AGENTLESS
3594+
"ReMoTe_ConFiG" | FeatureFlaggingSource.REMOTE_CONFIG
3595+
" remote_config " | FeatureFlaggingSource.INVALID
3596+
"not-a-real-source" | FeatureFlaggingSource.INVALID
3597+
"unset" | FeatureFlaggingSource.INVALID
35983598
}
35993599
36003600
def "feature flag configuration applies migration precedence"() {
@@ -3619,15 +3619,15 @@ class ConfigTest extends DDSpecification {
36193619
36203620
where:
36213621
providerEnabled | source | legacyProviderEnabled | expectedEnabled | expectedSource
3622-
null | null | null | true | "agentless"
3623-
true | null | null | true | "agentless"
3624-
null | null | true | true | "remote_config"
3625-
null | null | false | false | null
3626-
null | "agentless" | true | true | "agentless"
3627-
null | "remote_config" | false | true | "remote_config"
3628-
false | "agentless" | true | false | "agentless"
3629-
true | null | false | false | null
3630-
null | "not-a-source" | null | false | "invalid"
3631-
null | "offline" | true | false | "invalid"
3622+
null | null | null | true | FeatureFlaggingSource.AGENTLESS
3623+
true | null | null | true | FeatureFlaggingSource.AGENTLESS
3624+
null | null | true | true | FeatureFlaggingSource.REMOTE_CONFIG
3625+
null | null | false | false | FeatureFlaggingSource.UNSET
3626+
null | "agentless" | true | true | FeatureFlaggingSource.AGENTLESS
3627+
null | "remote_config" | false | true | FeatureFlaggingSource.REMOTE_CONFIG
3628+
false | "agentless" | true | false | FeatureFlaggingSource.AGENTLESS
3629+
true | null | false | false | FeatureFlaggingSource.UNSET
3630+
null | "not-a-source" | null | false | FeatureFlaggingSource.INVALID
3631+
null | "offline" | true | false | FeatureFlaggingSource.INVALID
36323632
}
36333633
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.datadog.featureflag;
22

3-
import static datadog.trace.api.config.FeatureFlaggingConfig.CONFIGURATION_SOURCE_AGENTLESS;
4-
import static datadog.trace.api.config.FeatureFlaggingConfig.CONFIGURATION_SOURCE_REMOTE_CONFIG;
3+
import static datadog.trace.api.FeatureFlaggingSource.AGENTLESS;
4+
import static datadog.trace.api.FeatureFlaggingSource.REMOTE_CONFIG;
55

66
import datadog.communication.BackendApiFactory;
77
import datadog.communication.ddagent.SharedCommunicationObjects;
@@ -34,7 +34,7 @@ public FeatureFlagsBackend(final SharedCommunicationObjects sco, final Config co
3434
config,
3535
new EventProxy(
3636
new BackendApiFactory(config, sco),
37-
CONFIGURATION_SOURCE_AGENTLESS.equals(config.getFeatureFlaggingConfigurationSource())
37+
config.getFeatureFlaggingConfigurationSource() == AGENTLESS
3838
&& config.getApiKey() != null),
3939
SpanEnrichmentWriter.getInstance(),
4040
CoreMetricCollector.getInstance());
@@ -55,8 +55,7 @@ public FeatureFlagsBackend(final SharedCommunicationObjects sco, final Config co
5555

5656
/** Registers the Remote Configuration product early when it is the configuration source. */
5757
public void start() {
58-
if (CONFIGURATION_SOURCE_REMOTE_CONFIG.equals(
59-
this.config.getFeatureFlaggingConfigurationSource())
58+
if (this.config.getFeatureFlaggingConfigurationSource() == REMOTE_CONFIG
6059
&& isRemoteConfigAvailable()) {
6160
remoteConfig().start();
6261
}

‎products/feature-flagging/feature-flagging-lib/src/test/java/com/datadog/featureflag/FeatureFlagsBackendTest.java‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import datadog.remoteconfig.ConfigurationPoller;
1818
import datadog.remoteconfig.Product;
1919
import datadog.trace.api.Config;
20+
import datadog.trace.api.FeatureFlaggingSource;
2021
import datadog.trace.api.telemetry.CoreMetricCollector;
2122
import datadog.trace.bootstrap.config.provider.ConfigProvider;
2223
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -65,12 +66,12 @@ void resolvesSettingsWithAgentDefaultsFromTheAgentConfiguration() {
6566

6667
@TableTest({
6768
"Scenario | Source | RC enabled | Registers",
68-
"remote config source | remote_config | true | true ",
69-
"remote config disabled | remote_config | false | false ",
70-
"agentless source | agentless | true | false "
69+
"remote config source | REMOTE_CONFIG | true | true ",
70+
"remote config disabled | REMOTE_CONFIG | false | false ",
71+
"agentless source | AGENTLESS | true | false "
7172
})
7273
void startRegistersRemoteConfigOnlyWhenItIsTheSource(
73-
final String source, final boolean rcEnabled, final boolean registers) {
74+
final FeatureFlaggingSource source, final boolean rcEnabled, final boolean registers) {
7475
final ConfigurationPoller poller = mock(ConfigurationPoller.class);
7576
when(this.sco.configurationPoller(this.config)).thenReturn(poller);
7677
when(this.config.getFeatureFlaggingConfigurationSource()).thenReturn(source);
@@ -83,11 +84,12 @@ void startRegistersRemoteConfigOnlyWhenItIsTheSource(
8384

8485
@TableTest({
8586
"Scenario | Source | API key",
86-
"agentless with API key | agentless | key ",
87-
"agentless without API key | agentless | ",
88-
"remote config | remote_config | key "
87+
"agentless with API key | AGENTLESS | key ",
88+
"agentless without API key | AGENTLESS | ",
89+
"remote config | REMOTE_CONFIG | key "
8990
})
90-
void createsTheBackendFromTheAgentConfiguration(final String source, final String apiKey) {
91+
void createsTheBackendFromTheAgentConfiguration(
92+
final FeatureFlaggingSource source, final String apiKey) {
9193
when(this.config.getFeatureFlaggingConfigurationSource()).thenReturn(source);
9294
when(this.config.getApiKey()).thenReturn(apiKey);
9395

0 commit comments

Comments
 (0)