-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into joey/aws-sns
- Loading branch information
Showing
58 changed files
with
929 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/util/CircuitBreaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.datadog.debugger.util; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
// CircuitBreaker is a simple circuit breaker implementation that allows a certain number of trips | ||
// within a time window. If the number of trips exceeds the limit, the circuit breaker will trip and | ||
// return false until the time window has passed. | ||
public class CircuitBreaker { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(CircuitBreaker.class); | ||
|
||
private final int maxTrips; | ||
private final Duration timeWindow; | ||
private AtomicInteger count = new AtomicInteger(0); | ||
private volatile long lastResetTime = System.currentTimeMillis(); | ||
private volatile long lastLoggingTime = System.currentTimeMillis(); | ||
|
||
public CircuitBreaker(int maxTrips, Duration timeWindow) { | ||
this.maxTrips = maxTrips; | ||
this.timeWindow = timeWindow; | ||
} | ||
|
||
public boolean trip() { | ||
int localCount = count.incrementAndGet(); | ||
if (localCount > maxTrips) { | ||
long currentTime = System.currentTimeMillis(); | ||
if (currentTime - lastLoggingTime > Duration.ofMinutes(1).toMillis()) { | ||
lastLoggingTime = currentTime; | ||
LOGGER.debug("Circuit breaker opened"); | ||
} | ||
if (currentTime - lastResetTime > timeWindow.toMillis()) { | ||
lastResetTime = currentTime; | ||
localCount = 1; | ||
count.set(localCount); | ||
} | ||
} | ||
return localCount <= maxTrips; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/util/CircuitBreakerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.datadog.debugger.util; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.locks.LockSupport; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class CircuitBreakerTest { | ||
|
||
@Test | ||
void noBreaker() { | ||
CircuitBreaker cb = new CircuitBreaker(3, Duration.ofMillis(10)); | ||
for (int i = 0; i < 10; i++) { | ||
assertTrue(cb.trip()); | ||
LockSupport.parkNanos(Duration.ofMillis(50).toNanos()); | ||
} | ||
} | ||
|
||
@Test | ||
void breaker() { | ||
CircuitBreaker cb = new CircuitBreaker(3, Duration.ofMillis(200)); | ||
for (int i = 0; i < 3; i++) { | ||
assertTrue(cb.trip()); | ||
} | ||
for (int i = 0; i < 100; i++) { | ||
assertFalse(cb.trip()); | ||
} | ||
LockSupport.parkNanos(Duration.ofMillis(250).toNanos()); | ||
for (int i = 0; i < 3; i++) { | ||
assertTrue(cb.trip()); | ||
} | ||
for (int i = 0; i < 100; i++) { | ||
assertFalse(cb.trip()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
plugins { | ||
id "com.github.johnrengelman.shadow" | ||
} | ||
|
||
apply from: "$rootDir/gradle/java.gradle" | ||
apply plugin: 'instrument' | ||
|
||
configurations { | ||
embeddedClasspath { | ||
visible = false | ||
canBeConsumed = false | ||
canBeResolved = true | ||
} | ||
instrumentPluginClasspath { | ||
visible = false | ||
canBeConsumed = false | ||
canBeResolved = true | ||
} | ||
} | ||
|
||
instrument.plugins = ['datadog.opentelemetry.tooling.OtelShimGradlePlugin'] | ||
|
||
minimumInstructionCoverage = 0.0 | ||
minimumBranchCoverage = 0.0 | ||
|
||
forbiddenApis { | ||
ignoreFailures = true | ||
} | ||
spotbugs { | ||
onlyAnalyze = ['none'] | ||
} | ||
|
||
dependencies { | ||
// latest OpenTelemetry API for drop-in support; instrumented at build-time with our shim | ||
embeddedClasspath group: 'io.opentelemetry', name: 'opentelemetry-api', version: '1.38.0' | ||
|
||
implementation project(':dd-java-agent:agent-otel:otel-shim') | ||
|
||
instrumentPluginClasspath project(':dd-java-agent:agent-otel:otel-tooling') | ||
} | ||
|
||
// unpack embeddedClasspath to same path as compiled classes so it can get instrumented | ||
tasks.register('unpackJars', Copy) { | ||
dependsOn configurations.embeddedClasspath | ||
exclude 'META-INF/' | ||
from { | ||
configurations.embeddedClasspath.collect { zipTree(it) } | ||
} | ||
into compileJava.destinationDirectory | ||
} | ||
tasks.named('compileJava') { | ||
dependsOn 'unpackJars' | ||
} | ||
|
||
shadowJar { | ||
dependencies deps.excludeShared | ||
|
||
exclude 'io/opentelemetry/context/internal/shaded/**' | ||
|
||
relocate 'io.opentelemetry', 'datadog.trace.bootstrap.otel' | ||
relocate 'datadog.opentelemetry.shim', 'datadog.trace.bootstrap.otel.shim' | ||
} | ||
|
||
jar { | ||
archiveClassifier = 'unbundled' | ||
} |
1 change: 1 addition & 0 deletions
1
dd-java-agent/agent-otel/otel-bootstrap/src/main/java/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// placeholder to activate the compiler task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apply from: "$rootDir/gradle/java.gradle" | ||
|
||
minimumInstructionCoverage = 0.0 | ||
minimumBranchCoverage = 0.0 | ||
|
||
dependencies { | ||
// minimum OpenTelemetry API version this shim is compatible with | ||
compileOnly group: 'io.opentelemetry', name: 'opentelemetry-api', version: '1.4.0' | ||
|
||
implementation project(':internal-api') | ||
} |
Oops, something went wrong.