44import static datadog .trace .util .AgentThreadFactory .AgentThread .FEATURE_FLAG_CONFIGURATION_POLLER ;
55
66import datadog .communication .http .OkHttpUtils ;
7+ import datadog .logging .RatelimitedLogger ;
78import datadog .trace .api .Config ;
89import datadog .trace .api .featureflag .FeatureFlaggingGateway ;
910import datadog .trace .api .featureflag .ufc .v1 .ServerConfiguration ;
@@ -38,6 +39,7 @@ final class AgentlessConfigurationSource implements ConfigurationSourceService {
3839 private static final String DATADOG_API_SERVER_DISTRIBUTION_PATH =
3940 "/api/v2/feature-flagging/config/server-distribution" ;
4041 private static final int MAX_ATTEMPTS = 3 ;
42+ private static final int MINUTES_BETWEEN_AUTH_WARNINGS = 5 ;
4143 private static final long FIRST_RETRY_MIN_MILLIS = 2_000 ;
4244 private static final long FIRST_RETRY_MAX_MILLIS = 10_000 ;
4345 private static final long SECOND_RETRY_MIN_MILLIS = 5_000 ;
@@ -51,6 +53,7 @@ final class AgentlessConfigurationSource implements ConfigurationSourceService {
5153 private final ScheduledExecutorService executor ;
5254 private final RetrySleeper retrySleeper ;
5355 private final DoubleSupplier jitter ;
56+ private final RatelimitedLogger ratelimitedLogger ;
5457 private final Object lifecycleLock = new Object ();
5558 private final AtomicBoolean polling = new AtomicBoolean ();
5659 private volatile boolean closed ;
@@ -73,7 +76,8 @@ private AgentlessConfigurationSource(final Config config, final HttpUrl endpoint
7376 Executors .newSingleThreadScheduledExecutor (
7477 new AgentThreadFactory (FEATURE_FLAG_CONFIGURATION_POLLER )),
7578 TimeUnit .MILLISECONDS ::sleep ,
76- () -> ThreadLocalRandom .current ().nextDouble (1 - RETRY_JITTER , 1 + RETRY_JITTER ));
79+ () -> ThreadLocalRandom .current ().nextDouble (1 - RETRY_JITTER , 1 + RETRY_JITTER ),
80+ new RatelimitedLogger (LOGGER , MINUTES_BETWEEN_AUTH_WARNINGS , TimeUnit .MINUTES ));
7781 }
7882
7983 AgentlessConfigurationSource (
@@ -89,7 +93,8 @@ private AgentlessConfigurationSource(final Config config, final HttpUrl endpoint
8993 client ,
9094 executor ,
9195 TimeUnit .MILLISECONDS ::sleep ,
92- () -> 1.0 );
96+ () -> 1.0 ,
97+ new RatelimitedLogger (LOGGER , MINUTES_BETWEEN_AUTH_WARNINGS , TimeUnit .MINUTES ));
9398 }
9499
95100 AgentlessConfigurationSource (
@@ -100,13 +105,34 @@ private AgentlessConfigurationSource(final Config config, final HttpUrl endpoint
100105 final ScheduledExecutorService executor ,
101106 final RetrySleeper retrySleeper ,
102107 final DoubleSupplier jitter ) {
108+ this (
109+ endpoint ,
110+ config ,
111+ pollIntervalMillis ,
112+ client ,
113+ executor ,
114+ retrySleeper ,
115+ jitter ,
116+ new RatelimitedLogger (LOGGER , MINUTES_BETWEEN_AUTH_WARNINGS , TimeUnit .MINUTES ));
117+ }
118+
119+ AgentlessConfigurationSource (
120+ final HttpUrl endpoint ,
121+ final Config config ,
122+ final long pollIntervalMillis ,
123+ final UfcHttpClient client ,
124+ final ScheduledExecutorService executor ,
125+ final RetrySleeper retrySleeper ,
126+ final DoubleSupplier jitter ,
127+ final RatelimitedLogger ratelimitedLogger ) {
103128 this .endpoint = endpoint ;
104129 this .config = config ;
105130 this .pollIntervalMillis = pollIntervalMillis ;
106131 this .client = client ;
107132 this .executor = executor ;
108133 this .retrySleeper = retrySleeper ;
109134 this .jitter = jitter ;
135+ this .ratelimitedLogger = ratelimitedLogger ;
110136 }
111137
112138 @ Override
@@ -207,9 +233,13 @@ private boolean apply(final UfcHttpResponse response) {
207233 return true ;
208234 }
209235 if (response .status == HttpURLConnection .HTTP_UNAUTHORIZED
210- || response .status == HttpURLConnection .HTTP_FORBIDDEN
211- || response .status != HttpURLConnection .HTTP_OK
212- || response .body == null ) {
236+ || response .status == HttpURLConnection .HTTP_FORBIDDEN ) {
237+ ratelimitedLogger .warn (
238+ "Feature Flagging agentless endpoint returned HTTP {}; verify DD_API_KEY is configured and valid" ,
239+ response .status );
240+ return false ;
241+ }
242+ if (response .status != HttpURLConnection .HTTP_OK || response .body == null ) {
213243 return false ;
214244 }
215245 final ServerConfiguration configuration ;
0 commit comments