Don't use static client ID to allow multiple xray samplers in same process, usually for testing. (#57)
This commit is contained in:
parent
84bef289f1
commit
ed31fbaac9
|
|
@ -10,6 +10,8 @@ import io.opentelemetry.context.Context;
|
|||
import io.opentelemetry.contrib.awsxray.AwsXrayRemoteSampler;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import io.opentelemetry.sdk.trace.IdGenerator;
|
||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
||||
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -49,7 +51,14 @@ class AwsXrayRemoteSamplerIntegrationTest {
|
|||
|
||||
@Test
|
||||
void keepSampling() throws Exception {
|
||||
AwsXrayRemoteSampler sampler =
|
||||
// Initialize two samplers to try to see centralized reservoir behavior.
|
||||
AwsXrayRemoteSampler sampler1 =
|
||||
AwsXrayRemoteSampler.newBuilder(Resource.getDefault())
|
||||
.setEndpoint("http://localhost:" + otelCollector.getMappedPort(2000))
|
||||
.setPollingInterval(Duration.ofSeconds(5))
|
||||
.build();
|
||||
|
||||
AwsXrayRemoteSampler sampler2 =
|
||||
AwsXrayRemoteSampler.newBuilder(Resource.getDefault())
|
||||
.setEndpoint("http://localhost:" + otelCollector.getMappedPort(2000))
|
||||
.setPollingInterval(Duration.ofSeconds(5))
|
||||
|
|
@ -57,21 +66,23 @@ class AwsXrayRemoteSamplerIntegrationTest {
|
|||
|
||||
try {
|
||||
while (true) {
|
||||
logger.info(
|
||||
"Sampling Decision: {}",
|
||||
sampler
|
||||
.shouldSample(
|
||||
Context.root(),
|
||||
IdGenerator.random().generateTraceId(),
|
||||
"cat-service",
|
||||
SpanKind.SERVER,
|
||||
Attributes.empty(),
|
||||
Collections.emptyList())
|
||||
.getDecision());
|
||||
logger.info("[Sampler 1] Sampling Decision: {}", doSample(sampler1).getDecision());
|
||||
logger.info("[Sampler 2] Sampling Decision: {}", doSample(sampler2).getDecision());
|
||||
Thread.sleep(500);
|
||||
}
|
||||
} finally {
|
||||
sampler.close();
|
||||
sampler1.close();
|
||||
sampler2.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static SamplingResult doSample(Sampler sampler) {
|
||||
return sampler.shouldSample(
|
||||
Context.root(),
|
||||
IdGenerator.random().generateTraceId(),
|
||||
"cat-service",
|
||||
SpanKind.SERVER,
|
||||
Attributes.empty(),
|
||||
Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,14 +40,13 @@ public final class AwsXrayRemoteSampler implements Sampler, Closeable {
|
|||
private static final Random RANDOM = new Random();
|
||||
private static final Logger logger = Logger.getLogger(AwsXrayRemoteSampler.class.getName());
|
||||
|
||||
// Unique per-process client ID, generated as a random string.
|
||||
private static final String CLIENT_ID = generateClientId();
|
||||
|
||||
private final Resource resource;
|
||||
private final Clock clock;
|
||||
private final Sampler initialSampler;
|
||||
private final XraySamplerClient client;
|
||||
private final ScheduledExecutorService executor;
|
||||
// Unique per-sampler client ID, generated as a random string.
|
||||
private final String clientId;
|
||||
private final long pollingIntervalNanos;
|
||||
private final int jitterNanos;
|
||||
|
||||
|
|
@ -89,6 +88,8 @@ public final class AwsXrayRemoteSampler implements Sampler, Closeable {
|
|||
return t;
|
||||
});
|
||||
|
||||
clientId = generateClientId();
|
||||
|
||||
sampler = initialSampler;
|
||||
|
||||
this.pollingIntervalNanos = pollingIntervalNanos;
|
||||
|
|
@ -123,7 +124,7 @@ public final class AwsXrayRemoteSampler implements Sampler, Closeable {
|
|||
if (!response.equals(previousRulesResponse)) {
|
||||
sampler =
|
||||
new XrayRulesSampler(
|
||||
CLIENT_ID,
|
||||
clientId,
|
||||
resource,
|
||||
clock,
|
||||
initialSampler,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
package io.opentelemetry.contrib.awsxray;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.google.auto.value.AutoValue;
|
||||
|
|
@ -47,10 +46,6 @@ abstract class GetSamplingTargetsRequest {
|
|||
abstract long getSampledCount();
|
||||
|
||||
@JsonProperty("Timestamp")
|
||||
@JsonFormat(
|
||||
shape = JsonFormat.Shape.STRING,
|
||||
pattern = "yyyy-MM-dd'T'HH:mm:ss",
|
||||
timezone = "UTC")
|
||||
abstract Date getTimestamp();
|
||||
|
||||
@AutoValue.Builder
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ final class JdkHttpClient {
|
|||
if (responseCode != 200) {
|
||||
logger.log(
|
||||
Level.FINE,
|
||||
"Error reponse from "
|
||||
"Error response from "
|
||||
+ urlStr
|
||||
+ " code ("
|
||||
+ responseCode
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
{
|
||||
"RuleName":"Test",
|
||||
"ClientID":"ABCDEF1234567890ABCDEF10",
|
||||
"Timestamp":"2021-06-21T06:46:07",
|
||||
"Timestamp":1624257967000,
|
||||
"RequestCount":110,
|
||||
"SampledCount":30,
|
||||
"BorrowCount":20
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
{
|
||||
"RuleName":"polling-scorekeep",
|
||||
"ClientID":"ABCDEF1234567890ABCDEF11",
|
||||
"Timestamp":"2018-07-07T00:20:06",
|
||||
"Timestamp":1530922806000,
|
||||
"RequestCount":10500,
|
||||
"SampledCount":31,
|
||||
"BorrowCount":0
|
||||
|
|
|
|||
Loading…
Reference in New Issue