Skip to content

Commit 8576219

Browse files
committed
refactor(feature-flagging): separate agent runtime and telemetry
1 parent bca75fa commit 8576219

28 files changed

Lines changed: 522 additions & 431 deletions

File tree

dd-smoke-tests/openfeature/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ smokeTestApp {
2121

2222
dependencies {
2323
testImplementation project(':dd-smoke-tests')
24-
testImplementation project(':products:feature-flagging:feature-flagging-lib')
24+
testImplementation project(':products:feature-flagging:feature-flagging-agent-runtime')
2525
}
2626

2727
spotless {

products/feature-flagging/feature-flagging-lib/build.gradle.kts renamed to products/feature-flagging/feature-flagging-agent-runtime/build.gradle.kts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ plugins {
55

66
apply(from = "$rootDir/gradle/java.gradle")
77

8-
description = "Feature flagging remote config and exposure handling"
9-
10-
extra["excludedClassesCoverage"] = listOf(
11-
// POJOs
12-
"com.datadog.featureflag.ExposureCache.Key",
13-
"com.datadog.featureflag.ExposureCache.Value"
14-
)
8+
description = "Java agent runtime for Feature Flagging configuration and telemetry"
159

1610
dependencies {
1711
api(libs.slf4j)
@@ -20,13 +14,10 @@ dependencies {
2014
api(project(":communication"))
2115
implementation(project(":internal-api"))
2216
api(project(":products:feature-flagging:feature-flagging-bootstrap"))
17+
implementation(project(":products:feature-flagging:feature-flagging-telemetry"))
2318
implementation(project(":utils:logging-utils"))
2419
api(project(":utils:queue-utils"))
2520

26-
compileOnly(project(":dd-trace-core")) // shading does not work with this one
27-
// Platform JSON writer for the ffe_* tag values.
28-
compileOnly(project(":components:json"))
29-
3021
testImplementation(libs.bundles.junit5)
3122
testImplementation(libs.bundles.mockito)
3223
testImplementation(project(":utils:test-utils"))

products/feature-flagging/feature-flagging-lib/gradle.lockfile renamed to products/feature-flagging/feature-flagging-agent-runtime/gradle.lockfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This is a Gradle generated file for dependency locking.
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
4-
# To regenerate this file, run: ./gradlew :products:feature-flagging:feature-flagging-lib:dependencies --write-locks
4+
# To regenerate this file, run: ./gradlew :products:feature-flagging:feature-flagging-agent-runtime:dependencies --write-locks
55
cafe.cryptography:curve25519-elisabeth:0.1.0=runtimeClasspath,testRuntimeClasspath
66
cafe.cryptography:ed25519-elisabeth:0.1.0=runtimeClasspath,testRuntimeClasspath
77
ch.qos.logback:logback-classic:1.2.13=testCompileClasspath,testRuntimeClasspath
@@ -92,7 +92,6 @@ org.junit.platform:junit-platform-launcher:1.14.1=testRuntimeClasspath
9292
org.junit.platform:junit-platform-runner:1.14.1=testRuntimeClasspath
9393
org.junit.platform:junit-platform-suite-api:1.14.1=testRuntimeClasspath
9494
org.junit.platform:junit-platform-suite-commons:1.14.1=testRuntimeClasspath
95-
org.junit:junit-bom:5.14.0=spotbugs
9695
org.junit:junit-bom:5.14.1=testCompileClasspath,testRuntimeClasspath
9796
org.mockito:mockito-core:4.4.0=testCompileClasspath,testRuntimeClasspath
9897
org.mockito:mockito-junit-jupiter:4.4.0=testCompileClasspath,testRuntimeClasspath

products/feature-flagging/feature-flagging-lib/src/main/java/com/datadog/featureflag/ConfigurationSourceService.java renamed to products/feature-flagging/feature-flagging-agent-runtime/src/main/java/com/datadog/featureflag/ConfigurationSourceService.java

File renamed without changes.

products/feature-flagging/feature-flagging-lib/src/main/java/com/datadog/featureflag/ExposureWriter.java renamed to products/feature-flagging/feature-flagging-agent-runtime/src/main/java/com/datadog/featureflag/ExposureWriter.java

File renamed without changes.

products/feature-flagging/feature-flagging-lib/src/main/java/com/datadog/featureflag/ExposureWriterImpl.java renamed to products/feature-flagging/feature-flagging-agent-runtime/src/main/java/com/datadog/featureflag/ExposureWriterImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import datadog.communication.BackendApi;
1212
import datadog.communication.BackendApiFactory;
1313
import datadog.communication.ddagent.SharedCommunicationObjects;
14+
import datadog.openfeature.internal.telemetry.ExposureDeduplicationCache;
1415
import datadog.trace.api.Config;
1516
import datadog.trace.api.featureflag.FeatureFlaggingGateway;
1617
import datadog.trace.api.featureflag.exposure.ExposureEvent;
@@ -105,7 +106,7 @@ private static class ExposureSerializingHandler implements Runnable {
105106
private BackendApi evp;
106107

107108
private final Map<String, String> context;
108-
private final ExposureCache cache;
109+
private final ExposureDeduplicationCache cache;
109110

110111
private final List<ExposureEvent> buffer = new ArrayList<>();
111112
private final Runnable errorCallback;
@@ -118,7 +119,7 @@ public ExposureSerializingHandler(
118119
final Map<String, String> context,
119120
final Runnable errorCallback) {
120121
this.queue = queue;
121-
this.cache = new LRUExposureCache(queue.capacity());
122+
this.cache = new ExposureDeduplicationCache(queue.capacity());
122123
this.jsonAdapter = new Moshi.Builder().build().adapter(ExposuresRequest.class);
123124
this.backendApiFactory = backendApiFactory;
124125
this.context = context;
@@ -166,7 +167,8 @@ private void consumeBatch() {
166167

167168
/** Adds an element to the buffer taking care of duplicated exposures thanks to the LRU cache */
168169
private boolean addToBuffer(final ExposureEvent event) {
169-
if (cache.add(event)) {
170+
if (cache.shouldEmit(
171+
event.flag.key, event.subject.id, event.variant.key, event.allocation.key)) {
170172
buffer.add(event);
171173
return true;
172174
}

products/feature-flagging/feature-flagging-lib/src/main/java/com/datadog/featureflag/RemoteConfigServiceImpl.java renamed to products/feature-flagging/feature-flagging-agent-runtime/src/main/java/com/datadog/featureflag/RemoteConfigServiceImpl.java

File renamed without changes.

products/feature-flagging/feature-flagging-lib/src/main/java/com/datadog/featureflag/SpanEnrichmentInterceptor.java renamed to products/feature-flagging/feature-flagging-agent-runtime/src/main/java/com/datadog/featureflag/SpanEnrichmentInterceptor.java

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

3+
import datadog.openfeature.internal.telemetry.SpanEnrichmentAccumulator;
34
import datadog.trace.api.interceptor.MutableSpan;
45
import datadog.trace.api.interceptor.TraceInterceptor;
56
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;

products/feature-flagging/feature-flagging-lib/src/main/java/com/datadog/featureflag/SpanEnrichmentStates.java renamed to products/feature-flagging/feature-flagging-agent-runtime/src/main/java/com/datadog/featureflag/SpanEnrichmentStates.java

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

3+
import datadog.openfeature.internal.telemetry.SpanEnrichmentAccumulator;
34
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
45
import java.util.Map;
56
import java.util.WeakHashMap;

products/feature-flagging/feature-flagging-lib/src/main/java/com/datadog/featureflag/SpanEnrichmentWriter.java renamed to products/feature-flagging/feature-flagging-agent-runtime/src/main/java/com/datadog/featureflag/SpanEnrichmentWriter.java

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

3+
import datadog.openfeature.internal.telemetry.SpanEnrichmentAccumulator;
34
import datadog.trace.api.GlobalTracer;
45
import datadog.trace.api.featureflag.FeatureFlaggingGateway;
56
import datadog.trace.api.featureflag.SpanEnrichmentEvent;

0 commit comments

Comments
 (0)