Skip to content

Commit

Permalink
Merge pull request #6404 from DataDog/ban/patch-6385
Browse files Browse the repository at this point in the history
[🍒 6385] Rate limit Datadog tags decoding warnings
  • Loading branch information
bantonsson authored Dec 20, 2023
2 parents a6bb01b + 5c88d49 commit 60e0d4d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
import datadog.trace.core.propagation.PropagationTags;
import datadog.trace.core.propagation.ptags.PTagsFactory.PTags;
import datadog.trace.core.propagation.ptags.TagElement.Encoding;
import datadog.trace.relocate.api.RatelimitedLogger;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.IntPredicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Captures configuration required for PropagationTags logic */
final class DatadogPTagsCodec extends PTagsCodec {
private static final Logger log = LoggerFactory.getLogger(DatadogPTagsCodec.class);
private static final RatelimitedLogger log =
new RatelimitedLogger(LoggerFactory.getLogger(DatadogPTagsCodec.class), 5, TimeUnit.MINUTES);
private static final String PROPAGATION_ERROR_EXTRACT_MAX_SIZE = "extract_max_size";
private static final String PROPAGATION_ERROR_DECODING_ERROR = "decoding_error";
private static final char TAGS_SEPARATOR = ',';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import datadog.trace.core.propagation.PropagationTags;
import datadog.trace.core.propagation.ptags.PTagsFactory.PTags;
import datadog.trace.core.propagation.ptags.TagElement.Encoding;
import datadog.trace.relocate.api.RatelimitedLogger;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.IntPredicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class W3CPTagsCodec extends PTagsCodec {
private static final Logger log = LoggerFactory.getLogger(W3CPTagsCodec.class);
private static final RatelimitedLogger log =
new RatelimitedLogger(LoggerFactory.getLogger(W3CPTagsCodec.class), 5, TimeUnit.MINUTES);

private static final int MAX_HEADER_SIZE = 256;
private static final String DATADOG_MEMBER_KEY = "dd=";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public RatelimitedLogger(final Logger log, final int delay, final TimeUnit timeU
final Logger log, final int delay, final TimeUnit timeUnit, final TimeSource timeSource) {
this.log = log;
this.delayNanos = timeUnit.toNanos(delay);
this.noLogMessage = createNoLogMessage(" (Will not log errors for ", ")", delay, timeUnit);
this.noLogMessage = createNoLogMessage(" (Will not log warnings for ", ")", delay, timeUnit);
this.timeSource = timeSource;
nextLogNanos = new AtomicLong(timeSource.getNanoTicks());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RateLimitedLoggerTest extends DDSpecification {
def secondLog = defaultRateLimitedLog.warn("test {} {}", "message", exception)

then:
1 * log.warn("test {} {} (Will not log errors for 5 minutes)", "message", exception)
1 * log.warn("test {} {} (Will not log warnings for 5 minutes)", "message", exception)
firstLog
!secondLog
}
Expand All @@ -56,7 +56,7 @@ class RateLimitedLoggerTest extends DDSpecification {
def firstLog = rateLimitedLog.warn("test {} {}", "message", exception)

then:
1 * log.warn("test {} {} (Will not log errors for 1 minute)", "message", exception)
1 * log.warn("test {} {} (Will not log warnings for 1 minute)", "message", exception)
firstLog

when:
Expand All @@ -80,7 +80,7 @@ class RateLimitedLoggerTest extends DDSpecification {
def firstLog = rateLimitedLog.warn("test {} {}", "message", exception)

then:
1 * log.warn("test {} {} (Will not log errors for 5 nanoseconds)", "message", exception)
1 * log.warn("test {} {} (Will not log warnings for 5 nanoseconds)", "message", exception)
firstLog

when:
Expand All @@ -105,7 +105,7 @@ class RateLimitedLoggerTest extends DDSpecification {
def firstLog = rateLimitedLog.warn("test {} {}", "message", exception)

then:
1 * log.warn("test {} {} (Will not log errors for 5 nanoseconds)", "message", exception)
1 * log.warn("test {} {} (Will not log warnings for 5 nanoseconds)", "message", exception)
firstLog

when:
Expand All @@ -128,15 +128,15 @@ class RateLimitedLoggerTest extends DDSpecification {
def firstLog = rateLimitedLog.warn("test {} {}", "message", exception)

then:
1 * log.warn("test {} {} (Will not log errors for 7 nanoseconds)", "message", exception)
1 * log.warn("test {} {} (Will not log warnings for 7 nanoseconds)", "message", exception)
firstLog

when:
timeSource.advance(7)
def secondLog = rateLimitedLog.warn("test {} {}", "message", exception)

then:
1 * log.warn("test {} {} (Will not log errors for 7 nanoseconds)", "message", exception)
1 * log.warn("test {} {} (Will not log warnings for 7 nanoseconds)", "message", exception)
secondLog
}

Expand All @@ -152,6 +152,6 @@ class RateLimitedLoggerTest extends DDSpecification {
rateLimitedLog.warn("test")

then:
1 * log.warn("test (Will not log errors for 1 millisecond)")
1 * log.warn("test (Will not log warnings for 1 millisecond)")
}
}

0 comments on commit 60e0d4d

Please sign in to comment.