77import datadog .common .queue .MessagePassingBlockingQueue ;
88import datadog .common .queue .Queues ;
99import datadog .communication .BackendApi ;
10- import datadog .communication .BackendApiFactory ;
1110import datadog .communication .EvpProxy ;
1211import datadog .communication .ddagent .SharedCommunicationObjects ;
1312import datadog .trace .api .Config ;
1413import datadog .trace .api .featureflag .FeatureFlaggingGateway ;
1514import datadog .trace .api .featureflag .flagevaluation .FlagEvalEvent ;
1615import datadog .trace .api .featureflag .flagevaluation .FlagEvaluationWriter ;
17- import datadog .trace .api .intake .Intake ;
1816import datadog .trace .api .telemetry .CoreMetricCollector ;
1917import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
2018import java .util .ArrayList ;
3331 * EVP flagevaluation writer for Java.
3432 *
3533 * <p>Uses the same EVP publisher path as ExposureWriterImpl, with two-tier aggregation replacing
36- * the single-exposure buffer. Routes to the Agent-advertised EVP proxy endpoint for
37- * /api/v2/flagevaluation .
34+ * the single-exposure buffer. Uses a local EVP proxy when available. Agentless mode can use direct
35+ * intake when no compatible local route is available .
3836 *
3937 * <p>Two-tier aggregation contract: Full key: (flagKey, variant, allocationKey, runtimeDefault,
4038 * errorMessage, targetingKey, canonical-context-key). Degraded key: (flagKey, variant,
@@ -102,51 +100,15 @@ private static void countMetric(final String metricName, final long value, final
102100 new ConcurrentHashMap <>();
103101
104102 public FlagEvaluationWriterImpl (final SharedCommunicationObjects sco , final Config config ) {
105- this (DEFAULT_CAPACITY , FLUSH_INTERVAL_SECONDS , SECONDS , sco , config );
106- }
107-
108- FlagEvaluationWriterImpl (
109- final int capacity ,
110- final long flushInterval ,
111- final TimeUnit timeUnit ,
112- final SharedCommunicationObjects sco ,
113- final Config config ) {
114- this (
115- capacity ,
116- flushInterval ,
117- timeUnit ,
118- new FeatureFlagBackendApiFactory (config , sco , FeatureFlagEventType .FLAG_EVALUATION ),
119- config );
120- }
121-
122- /** Package-private constructor allowing a BackendApiFactory to be injected for tests. */
123- FlagEvaluationWriterImpl (
124- final int capacity ,
125- final long flushInterval ,
126- final TimeUnit timeUnit ,
127- final BackendApiFactory backendApiFactory ,
128- final Config config ) {
129103 this (
130- capacity ,
131- flushInterval ,
132- timeUnit ,
133- () ->
134- backendApiFactory .createBackendApi (
135- Intake .EVENT_PLATFORM ,
136- FeatureFlagEventType .FLAG_EVALUATION .responseCompressionEnabled ()),
104+ DEFAULT_CAPACITY ,
105+ FLUSH_INTERVAL_SECONDS ,
106+ SECONDS ,
107+ new FeatureFlagBackendApiFactory (config , sco , FeatureFlagEventType .FLAG_EVALUATION )::create ,
137108 config );
138109 }
139110
140111 FlagEvaluationWriterImpl (
141- final int capacity ,
142- final long flushInterval ,
143- final TimeUnit timeUnit ,
144- final FeatureFlagBackendApiFactory backendApiFactory ,
145- final Config config ) {
146- this (capacity , flushInterval , timeUnit , backendApiFactory ::create , config );
147- }
148-
149- private FlagEvaluationWriterImpl (
150112 final int capacity ,
151113 final long flushInterval ,
152114 final TimeUnit timeUnit ,
@@ -162,7 +124,8 @@ private FlagEvaluationWriterImpl(
162124 FeatureFlagEvpContext .from (config ),
163125 droppedQueueOverflow ,
164126 contextTruncatedCounts ,
165- this ::close );
127+ this ::close ,
128+ FLAG_EVALUATION_PAYLOAD_SIZE_LIMIT_BYTES );
166129 this .serializerThread = newAgentThread (FEATURE_FLAG_EVALUATION_PROCESSOR , serializer );
167130 }
168131
@@ -342,70 +305,6 @@ static class FlagEvaluationSerializingHandler implements Runnable {
342305 private final AtomicBoolean shutdownRequested = new AtomicBoolean (false );
343306 private final CountDownLatch finalFlushDone = new CountDownLatch (1 );
344307
345- FlagEvaluationSerializingHandler (
346- final BackendApiFactory backendApiFactory ,
347- final MessagePassingBlockingQueue <FlagEvalEvent > queue ,
348- final long flushInterval ,
349- final TimeUnit timeUnit ,
350- final Map <String , String > context ,
351- final AtomicLong droppedQueueOverflow ,
352- final ConcurrentHashMap <String , AtomicLong > contextTruncatedCounts ,
353- final Runnable errorCallback ) {
354- this (
355- () -> backendApiFactory .createBackendApi (Intake .EVENT_PLATFORM , false ),
356- queue ,
357- flushInterval ,
358- timeUnit ,
359- context ,
360- droppedQueueOverflow ,
361- contextTruncatedCounts ,
362- errorCallback ,
363- FLAG_EVALUATION_PAYLOAD_SIZE_LIMIT_BYTES );
364- }
365-
366- FlagEvaluationSerializingHandler (
367- final BackendApiFactory backendApiFactory ,
368- final MessagePassingBlockingQueue <FlagEvalEvent > queue ,
369- final long flushInterval ,
370- final TimeUnit timeUnit ,
371- final Map <String , String > context ,
372- final AtomicLong droppedQueueOverflow ,
373- final ConcurrentHashMap <String , AtomicLong > contextTruncatedCounts ,
374- final Runnable errorCallback ,
375- final int payloadSizeLimitBytes ) {
376- this (
377- () -> backendApiFactory .createBackendApi (Intake .EVENT_PLATFORM , false ),
378- queue ,
379- flushInterval ,
380- timeUnit ,
381- context ,
382- droppedQueueOverflow ,
383- contextTruncatedCounts ,
384- errorCallback ,
385- payloadSizeLimitBytes );
386- }
387-
388- FlagEvaluationSerializingHandler (
389- final Supplier <BackendApi > backendApiSupplier ,
390- final MessagePassingBlockingQueue <FlagEvalEvent > queue ,
391- final long flushInterval ,
392- final TimeUnit timeUnit ,
393- final Map <String , String > context ,
394- final AtomicLong droppedQueueOverflow ,
395- final ConcurrentHashMap <String , AtomicLong > contextTruncatedCounts ,
396- final Runnable errorCallback ) {
397- this (
398- backendApiSupplier ,
399- queue ,
400- flushInterval ,
401- timeUnit ,
402- context ,
403- droppedQueueOverflow ,
404- contextTruncatedCounts ,
405- errorCallback ,
406- FLAG_EVALUATION_PAYLOAD_SIZE_LIMIT_BYTES );
407- }
408-
409308 FlagEvaluationSerializingHandler (
410309 final Supplier <BackendApi > backendApiSupplier ,
411310 final MessagePassingBlockingQueue <FlagEvalEvent > queue ,
@@ -622,16 +521,17 @@ private boolean shouldFlush() {
622521 */
623522 static class SerializingHandlerForTest extends FlagEvaluationSerializingHandler {
624523
625- SerializingHandlerForTest (final BackendApiFactory factory , final Map <String , String > context ) {
626- this (factory , context , FLAG_EVALUATION_PAYLOAD_SIZE_LIMIT_BYTES );
524+ SerializingHandlerForTest (
525+ final Supplier <BackendApi > backendApiSupplier , final Map <String , String > context ) {
526+ this (backendApiSupplier , context , FLAG_EVALUATION_PAYLOAD_SIZE_LIMIT_BYTES );
627527 }
628528
629529 SerializingHandlerForTest (
630- final BackendApiFactory factory ,
530+ final Supplier < BackendApi > backendApiSupplier ,
631531 final Map <String , String > context ,
632532 final int payloadSizeLimitBytes ) {
633533 super (
634- factory ,
534+ backendApiSupplier ,
635535 Queues .mpscBlockingConsumerArrayQueue (DEFAULT_CAPACITY ),
636536 Long .MAX_VALUE , // effectively never auto-flush
637537 TimeUnit .NANOSECONDS ,
@@ -695,14 +595,14 @@ int fullTierSizeForTest() {
695595
696596 /** Factory method for test use - creates a SerializingHandlerForTest. */
697597 static SerializingHandlerForTest createHandlerForTest (
698- final BackendApiFactory factory , final Map <String , String > context ) {
699- return new SerializingHandlerForTest (factory , context );
598+ final Supplier < BackendApi > backendApiSupplier , final Map <String , String > context ) {
599+ return new SerializingHandlerForTest (backendApiSupplier , context );
700600 }
701601
702602 static SerializingHandlerForTest createHandlerForTest (
703- final BackendApiFactory factory ,
603+ final Supplier < BackendApi > backendApiSupplier ,
704604 final Map <String , String > context ,
705605 final int payloadSizeLimitBytes ) {
706- return new SerializingHandlerForTest (factory , context , payloadSizeLimitBytes );
606+ return new SerializingHandlerForTest (backendApiSupplier , context , payloadSizeLimitBytes );
707607 }
708608}
0 commit comments