Use service.name resource attribute instead of span name for service name matcher. (#138)
This commit is contained in:
parent
335c7730b3
commit
4775be2410
|
@ -144,7 +144,7 @@ final class SamplingRuleApplier {
|
||||||
this.nextSnapshotTimeNanos = nextSnapshotTimeNanos;
|
this.nextSnapshotTimeNanos = nextSnapshotTimeNanos;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean matches(String name, Attributes attributes, Resource resource) {
|
boolean matches(Attributes attributes, Resource resource) {
|
||||||
int matchedAttributes = 0;
|
int matchedAttributes = 0;
|
||||||
String httpTarget = null;
|
String httpTarget = null;
|
||||||
String httpMethod = null;
|
String httpMethod = null;
|
||||||
|
@ -175,7 +175,7 @@ final class SamplingRuleApplier {
|
||||||
}
|
}
|
||||||
|
|
||||||
return urlPathMatcher.matches(httpTarget)
|
return urlPathMatcher.matches(httpTarget)
|
||||||
&& serviceNameMatcher.matches(name)
|
&& serviceNameMatcher.matches(resource.getAttribute(ResourceAttributes.SERVICE_NAME))
|
||||||
&& httpMethodMatcher.matches(httpMethod)
|
&& httpMethodMatcher.matches(httpMethod)
|
||||||
&& hostMatcher.matches(host)
|
&& hostMatcher.matches(host)
|
||||||
&& serviceTypeMatcher.matches(getServiceType(resource))
|
&& serviceTypeMatcher.matches(getServiceType(resource))
|
||||||
|
|
|
@ -76,7 +76,7 @@ final class XrayRulesSampler implements Sampler {
|
||||||
Attributes attributes,
|
Attributes attributes,
|
||||||
List<LinkData> parentLinks) {
|
List<LinkData> parentLinks) {
|
||||||
for (SamplingRuleApplier applier : ruleAppliers) {
|
for (SamplingRuleApplier applier : ruleAppliers) {
|
||||||
if (applier.matches(name, attributes, resource)) {
|
if (applier.matches(attributes, resource)) {
|
||||||
return applier.shouldSample(
|
return applier.shouldSample(
|
||||||
parentContext, traceId, name, spanKind, attributes, parentLinks);
|
parentContext, traceId, name, spanKind, attributes, parentLinks);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@ import static java.util.Objects.requireNonNull;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.awaitility.Awaitility.await;
|
import static org.awaitility.Awaitility.await;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.linecorp.armeria.common.HttpResponse;
|
import com.linecorp.armeria.common.HttpResponse;
|
||||||
import com.linecorp.armeria.common.HttpStatus;
|
import com.linecorp.armeria.common.HttpStatus;
|
||||||
import com.linecorp.armeria.common.MediaType;
|
import com.linecorp.armeria.common.MediaType;
|
||||||
import com.linecorp.armeria.server.ServerBuilder;
|
import com.linecorp.armeria.server.ServerBuilder;
|
||||||
import com.linecorp.armeria.testing.junit5.server.ServerExtension;
|
import com.linecorp.armeria.testing.junit5.server.ServerExtension;
|
||||||
|
import io.opentelemetry.api.common.AttributeKey;
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.trace.SpanKind;
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
import io.opentelemetry.api.trace.TraceId;
|
import io.opentelemetry.api.trace.TraceId;
|
||||||
|
@ -35,8 +35,6 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
class AwsXrayRemoteSamplerTest {
|
class AwsXrayRemoteSamplerTest {
|
||||||
|
|
||||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
|
||||||
|
|
||||||
private static final byte[] RULE_RESPONSE_1;
|
private static final byte[] RULE_RESPONSE_1;
|
||||||
private static final byte[] RULE_RESPONSE_2;
|
private static final byte[] RULE_RESPONSE_2;
|
||||||
private static final byte[] TARGETS_RESPONE;
|
private static final byte[] TARGETS_RESPONE;
|
||||||
|
@ -121,28 +119,8 @@ class AwsXrayRemoteSamplerTest {
|
||||||
@Test
|
@Test
|
||||||
void getAndUpdate() throws Exception {
|
void getAndUpdate() throws Exception {
|
||||||
// Initial Sampler allows all.
|
// Initial Sampler allows all.
|
||||||
assertThat(
|
assertThat(doSample(sampler, "cat-service")).isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
||||||
sampler
|
assertThat(doSample(sampler, "dog-service")).isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
||||||
.shouldSample(
|
|
||||||
Context.root(),
|
|
||||||
TRACE_ID,
|
|
||||||
"cat-service",
|
|
||||||
SpanKind.SERVER,
|
|
||||||
Attributes.empty(),
|
|
||||||
Collections.emptyList())
|
|
||||||
.getDecision())
|
|
||||||
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
|
||||||
assertThat(
|
|
||||||
sampler
|
|
||||||
.shouldSample(
|
|
||||||
Context.root(),
|
|
||||||
TRACE_ID,
|
|
||||||
"dog-service",
|
|
||||||
SpanKind.SERVER,
|
|
||||||
Attributes.empty(),
|
|
||||||
Collections.emptyList())
|
|
||||||
.getDecision())
|
|
||||||
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
|
||||||
|
|
||||||
rulesResponse.set(RULE_RESPONSE_1);
|
rulesResponse.set(RULE_RESPONSE_1);
|
||||||
|
|
||||||
|
@ -150,28 +128,9 @@ class AwsXrayRemoteSamplerTest {
|
||||||
await()
|
await()
|
||||||
.untilAsserted(
|
.untilAsserted(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(
|
assertThat(doSample(sampler, "cat-service"))
|
||||||
sampler
|
|
||||||
.shouldSample(
|
|
||||||
Context.root(),
|
|
||||||
TRACE_ID,
|
|
||||||
"cat-service",
|
|
||||||
SpanKind.SERVER,
|
|
||||||
Attributes.empty(),
|
|
||||||
Collections.emptyList())
|
|
||||||
.getDecision())
|
|
||||||
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
||||||
assertThat(
|
assertThat(doSample(sampler, "dog-service")).isEqualTo(SamplingDecision.DROP);
|
||||||
sampler
|
|
||||||
.shouldSample(
|
|
||||||
Context.root(),
|
|
||||||
TRACE_ID,
|
|
||||||
"dog-service",
|
|
||||||
SpanKind.SERVER,
|
|
||||||
Attributes.empty(),
|
|
||||||
Collections.emptyList())
|
|
||||||
.getDecision())
|
|
||||||
.isEqualTo(SamplingDecision.DROP);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
rulesResponse.set(RULE_RESPONSE_2);
|
rulesResponse.set(RULE_RESPONSE_2);
|
||||||
|
@ -180,27 +139,8 @@ class AwsXrayRemoteSamplerTest {
|
||||||
await()
|
await()
|
||||||
.untilAsserted(
|
.untilAsserted(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(
|
assertThat(doSample(sampler, "cat-service")).isEqualTo(SamplingDecision.DROP);
|
||||||
sampler
|
assertThat(doSample(sampler, "dog-service"))
|
||||||
.shouldSample(
|
|
||||||
Context.root(),
|
|
||||||
TRACE_ID,
|
|
||||||
"cat-service",
|
|
||||||
SpanKind.SERVER,
|
|
||||||
Attributes.empty(),
|
|
||||||
Collections.emptyList())
|
|
||||||
.getDecision())
|
|
||||||
.isEqualTo(SamplingDecision.DROP);
|
|
||||||
assertThat(
|
|
||||||
sampler
|
|
||||||
.shouldSample(
|
|
||||||
Context.root(),
|
|
||||||
TRACE_ID,
|
|
||||||
"dog-service",
|
|
||||||
SpanKind.SERVER,
|
|
||||||
Attributes.empty(),
|
|
||||||
Collections.emptyList())
|
|
||||||
.getDecision())
|
|
||||||
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -210,27 +150,9 @@ class AwsXrayRemoteSamplerTest {
|
||||||
await()
|
await()
|
||||||
.untilAsserted(
|
.untilAsserted(
|
||||||
() -> {
|
() -> {
|
||||||
assertThat(
|
assertThat(doSample(sampler, "cat-service"))
|
||||||
sampler
|
|
||||||
.shouldSample(
|
|
||||||
Context.root(),
|
|
||||||
TRACE_ID,
|
|
||||||
"cat-service",
|
|
||||||
SpanKind.SERVER,
|
|
||||||
Attributes.empty(),
|
|
||||||
Collections.emptyList())
|
|
||||||
.getDecision())
|
|
||||||
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
||||||
assertThat(
|
assertThat(doSample(sampler, "dog-service"))
|
||||||
sampler
|
|
||||||
.shouldSample(
|
|
||||||
Context.root(),
|
|
||||||
TRACE_ID,
|
|
||||||
"dog-service",
|
|
||||||
SpanKind.SERVER,
|
|
||||||
Attributes.empty(),
|
|
||||||
Collections.emptyList())
|
|
||||||
.getDecision())
|
|
||||||
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -245,4 +167,16 @@ class AwsXrayRemoteSamplerTest {
|
||||||
+ "first:RateLimitingSampler{1}, second:TraceIdRatioBased{0.050000}");
|
+ "first:RateLimitingSampler{1}, second:TraceIdRatioBased{0.050000}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static SamplingDecision doSample(Sampler sampler, String name) {
|
||||||
|
return sampler
|
||||||
|
.shouldSample(
|
||||||
|
Context.root(),
|
||||||
|
TRACE_ID,
|
||||||
|
"span",
|
||||||
|
SpanKind.SERVER,
|
||||||
|
Attributes.of(AttributeKey.stringKey("test"), name),
|
||||||
|
Collections.emptyList())
|
||||||
|
.getDecision();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.contrib.awsxray;
|
package io.opentelemetry.contrib.awsxray;
|
||||||
|
|
||||||
|
import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.awaitility.Awaitility.await;
|
import static org.awaitility.Awaitility.await;
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ class SamplingRuleApplierTest {
|
||||||
|
|
||||||
private final Resource resource =
|
private final Resource resource =
|
||||||
Resource.builder()
|
Resource.builder()
|
||||||
|
.put(ResourceAttributes.SERVICE_NAME, "test-service-foo-bar")
|
||||||
.put(ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS)
|
.put(ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS)
|
||||||
.put(
|
.put(
|
||||||
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
||||||
|
@ -101,24 +103,28 @@ class SamplingRuleApplierTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void matches() {
|
void matches() {
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nameNotMatch() {
|
void serviceNameNotMatch() {
|
||||||
assertThat(applier.matches("test-service-foo-baz", attributes, resource)).isFalse();
|
assertThat(
|
||||||
|
applier.matches(
|
||||||
|
attributes,
|
||||||
|
resource.toBuilder().put(SERVICE_NAME, "test-service-foo-baz").build()))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullNotMatch() {
|
void serviceNameNullNotMatch() {
|
||||||
assertThat(applier.matches(null, attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, Resource.empty())).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void methodNotMatch() {
|
void methodNotMatch() {
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "POST").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "POST").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -127,7 +133,7 @@ class SamplingRuleApplierTest {
|
||||||
// wildcard.
|
// wildcard.
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentelemetryfio").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentelemetryfio").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -136,20 +142,20 @@ class SamplingRuleApplierTest {
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(SemanticAttributes.HTTP_TARGET, "/instrument-you")
|
.put(SemanticAttributes.HTTP_TARGET, "/instrument-you")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void attributeNotMatch() {
|
void attributeNotMatch() {
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
this.attributes.toBuilder().put(AttributeKey.stringKey("animal"), "dog").build();
|
this.attributes.toBuilder().put(AttributeKey.stringKey("animal"), "dog").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void attributeMissing() {
|
void attributeMissing() {
|
||||||
Attributes attributes = removeAttribute(this.attributes, AttributeKey.stringKey("animal"));
|
Attributes attributes = removeAttribute(this.attributes, AttributeKey.stringKey("animal"));
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -159,11 +165,11 @@ class SamplingRuleApplierTest {
|
||||||
.put(
|
.put(
|
||||||
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2)
|
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2)
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
resource =
|
resource =
|
||||||
Resource.create(
|
Resource.create(
|
||||||
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM));
|
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM));
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -174,7 +180,7 @@ class SamplingRuleApplierTest {
|
||||||
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
||||||
"arn:aws:xray:us-east-1:595986152929:my-service2")
|
"arn:aws:xray:us-east-1:595986152929:my-service2")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +194,7 @@ class SamplingRuleApplierTest {
|
||||||
|
|
||||||
private final Resource resource =
|
private final Resource resource =
|
||||||
Resource.builder()
|
Resource.builder()
|
||||||
|
.put(ResourceAttributes.SERVICE_NAME, "test-service-foo-bar")
|
||||||
.put(ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS)
|
.put(ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS)
|
||||||
.put(
|
.put(
|
||||||
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
||||||
|
@ -236,39 +243,57 @@ class SamplingRuleApplierTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nameMatches() {
|
void serviceNameMatches() {
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(
|
||||||
assertThat(applier.matches("test-service-foo-baz", attributes, resource)).isTrue();
|
applier.matches(
|
||||||
assertThat(applier.matches("test-service-foo-", attributes, resource)).isTrue();
|
attributes,
|
||||||
|
resource.toBuilder().put(SERVICE_NAME, "test-service-foo-bar").build()))
|
||||||
|
.isTrue();
|
||||||
|
assertThat(
|
||||||
|
applier.matches(
|
||||||
|
attributes,
|
||||||
|
resource.toBuilder().put(SERVICE_NAME, "test-service-foo-baz").build()))
|
||||||
|
.isTrue();
|
||||||
|
assertThat(
|
||||||
|
applier.matches(
|
||||||
|
attributes, resource.toBuilder().put(SERVICE_NAME, "test-service-foo-").build()))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nameNotMatch() {
|
void serviceNameNotMatch() {
|
||||||
assertThat(applier.matches("test-service-foo", attributes, resource)).isFalse();
|
assertThat(
|
||||||
assertThat(applier.matches("prod-service-foo-bar", attributes, resource)).isFalse();
|
applier.matches(
|
||||||
assertThat(applier.matches(null, attributes, resource)).isFalse();
|
attributes, resource.toBuilder().put(SERVICE_NAME, "test-service-foo").build()))
|
||||||
|
.isFalse();
|
||||||
|
assertThat(
|
||||||
|
applier.matches(
|
||||||
|
attributes,
|
||||||
|
resource.toBuilder().put(SERVICE_NAME, "prod-service-foo-bar").build()))
|
||||||
|
.isFalse();
|
||||||
|
assertThat(applier.matches(attributes, Resource.empty())).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void methodMatches() {
|
void methodMatches() {
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "BADGETGOOD").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "BADGETGOOD").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "BADGET").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "BADGET").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "GETGET").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "GETGET").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void methodNotMatch() {
|
void methodNotMatch() {
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "POST").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_METHOD, "POST").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
attributes = removeAttribute(this.attributes, SemanticAttributes.HTTP_METHOD);
|
attributes = removeAttribute(this.attributes, SemanticAttributes.HTTP_METHOD);
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -277,40 +302,40 @@ class SamplingRuleApplierTest {
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(SemanticAttributes.HTTP_HOST, "alpha.opentelemetry.io")
|
.put(SemanticAttributes.HTTP_HOST, "alpha.opentelemetry.io")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(SemanticAttributes.HTTP_HOST, "opfdnqtelemetry.io")
|
.put(SemanticAttributes.HTTP_HOST, "opfdnqtelemetry.io")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentglemetry.io").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentglemetry.io").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentglemry.io").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentglemry.io").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentglemrz.io").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentglemrz.io").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void hostNotMatch() {
|
void hostNotMatch() {
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentelemetryfio").build();
|
this.attributes.toBuilder().put(SemanticAttributes.HTTP_HOST, "opentelemetryfio").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(SemanticAttributes.HTTP_HOST, "opentgalemetry.io")
|
.put(SemanticAttributes.HTTP_HOST, "opentgalemetry.io")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(SemanticAttributes.HTTP_HOST, "alpha.oentelemetry.io")
|
.put(SemanticAttributes.HTTP_HOST, "alpha.oentelemetry.io")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
attributes = removeAttribute(this.attributes, SemanticAttributes.HTTP_HOST);
|
attributes = removeAttribute(this.attributes, SemanticAttributes.HTTP_HOST);
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -319,13 +344,13 @@ class SamplingRuleApplierTest {
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(SemanticAttributes.HTTP_TARGET, "/instrument-me?foo=bar&cat=")
|
.put(SemanticAttributes.HTTP_TARGET, "/instrument-me?foo=bar&cat=")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
// Deceptive question mark, it's actually a wildcard :-)
|
// Deceptive question mark, it's actually a wildcard :-)
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(SemanticAttributes.HTTP_TARGET, "/instrument-meafoo=bar&cat=")
|
.put(SemanticAttributes.HTTP_TARGET, "/instrument-meafoo=bar&cat=")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -334,41 +359,41 @@ class SamplingRuleApplierTest {
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(SemanticAttributes.HTTP_TARGET, "/instrument-mea?foo=bar&cat=")
|
.put(SemanticAttributes.HTTP_TARGET, "/instrument-mea?foo=bar&cat=")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(SemanticAttributes.HTTP_TARGET, "foo/instrument-meafoo=bar&cat=")
|
.put(SemanticAttributes.HTTP_TARGET, "foo/instrument-meafoo=bar&cat=")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
attributes = removeAttribute(this.attributes, SemanticAttributes.HTTP_TARGET);
|
attributes = removeAttribute(this.attributes, SemanticAttributes.HTTP_TARGET);
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void attributeMatches() {
|
void attributeMatches() {
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
this.attributes.toBuilder().put(AttributeKey.stringKey("animal"), "catman").build();
|
this.attributes.toBuilder().put(AttributeKey.stringKey("animal"), "catman").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
attributes = this.attributes.toBuilder().put(AttributeKey.longKey("speed"), 20).build();
|
attributes = this.attributes.toBuilder().put(AttributeKey.longKey("speed"), 20).build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void attributeNotMatch() {
|
void attributeNotMatch() {
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
this.attributes.toBuilder().put(AttributeKey.stringKey("animal"), "dog").build();
|
this.attributes.toBuilder().put(AttributeKey.stringKey("animal"), "dog").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
attributes =
|
attributes =
|
||||||
this.attributes.toBuilder().put(AttributeKey.stringKey("animal"), "mancat").build();
|
this.attributes.toBuilder().put(AttributeKey.stringKey("animal"), "mancat").build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
attributes = this.attributes.toBuilder().put(AttributeKey.longKey("speed"), 21).build();
|
attributes = this.attributes.toBuilder().put(AttributeKey.longKey("speed"), 21).build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void attributeMissing() {
|
void attributeMissing() {
|
||||||
Attributes attributes = removeAttribute(this.attributes, AttributeKey.stringKey("animal"));
|
Attributes attributes = removeAttribute(this.attributes, AttributeKey.stringKey("animal"));
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -378,12 +403,12 @@ class SamplingRuleApplierTest {
|
||||||
.put(
|
.put(
|
||||||
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2)
|
ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2)
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
resource =
|
resource =
|
||||||
Resource.create(
|
Resource.create(
|
||||||
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM));
|
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM));
|
||||||
// null matches for pattern '*'
|
// null matches for pattern '*'
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -394,7 +419,7 @@ class SamplingRuleApplierTest {
|
||||||
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
||||||
"arn:aws:opentelemetry:us-east-3:52929:my-service")
|
"arn:aws:opentelemetry:us-east-3:52929:my-service")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -405,19 +430,19 @@ class SamplingRuleApplierTest {
|
||||||
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
||||||
"arn:aws:xray:us-east-1:595986152929:my-service2")
|
"arn:aws:xray:us-east-1:595986152929:my-service2")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
resource =
|
resource =
|
||||||
this.resource.toBuilder()
|
this.resource.toBuilder()
|
||||||
.put(
|
.put(
|
||||||
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
ResourceAttributes.AWS_ECS_CONTAINER_ARN,
|
||||||
"frn:aws:xray:us-east-1:595986152929:my-service")
|
"frn:aws:xray:us-east-1:595986152929:my-service")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
resource =
|
resource =
|
||||||
Resource.create(
|
Resource.create(
|
||||||
removeAttribute(
|
removeAttribute(
|
||||||
this.resource.getAttributes(), ResourceAttributes.AWS_ECS_CONTAINER_ARN));
|
this.resource.getAttributes(), ResourceAttributes.AWS_ECS_CONTAINER_ARN));
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +473,7 @@ class SamplingRuleApplierTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resourceFaasIdMatches() {
|
void resourceFaasIdMatches() {
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -460,7 +485,7 @@ class SamplingRuleApplierTest {
|
||||||
this.attributes.toBuilder()
|
this.attributes.toBuilder()
|
||||||
.put(ResourceAttributes.FAAS_ID, "arn:aws:xray:us-east-1:595986152929:my-service")
|
.put(ResourceAttributes.FAAS_ID, "arn:aws:xray:us-east-1:595986152929:my-service")
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isTrue();
|
assertThat(applier.matches(attributes, resource)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -471,11 +496,11 @@ class SamplingRuleApplierTest {
|
||||||
ResourceAttributes.CLOUD_PLATFORM,
|
ResourceAttributes.CLOUD_PLATFORM,
|
||||||
ResourceAttributes.CloudPlatformValues.GCP_CLOUD_FUNCTIONS)
|
ResourceAttributes.CloudPlatformValues.GCP_CLOUD_FUNCTIONS)
|
||||||
.build();
|
.build();
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
resource =
|
resource =
|
||||||
Resource.create(
|
Resource.create(
|
||||||
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM));
|
removeAttribute(this.resource.getAttributes(), ResourceAttributes.CLOUD_PLATFORM));
|
||||||
assertThat(applier.matches("test-service-foo-bar", attributes, resource)).isFalse();
|
assertThat(applier.matches(attributes, resource)).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.contrib.awsxray;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.common.AttributeKey;
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.trace.SpanKind;
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
import io.opentelemetry.api.trace.TraceId;
|
import io.opentelemetry.api.trace.TraceId;
|
||||||
|
@ -36,7 +37,7 @@ class XrayRulesSamplerTest {
|
||||||
void updateTargets() {
|
void updateTargets() {
|
||||||
SamplingRule rule1 =
|
SamplingRule rule1 =
|
||||||
SamplingRule.create(
|
SamplingRule.create(
|
||||||
Collections.emptyMap(),
|
Collections.singletonMap("test", "cat-service"),
|
||||||
1.0,
|
1.0,
|
||||||
"*",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
|
@ -45,13 +46,13 @@ class XrayRulesSamplerTest {
|
||||||
"*",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
"cat-rule",
|
"cat-rule",
|
||||||
"cat-service",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
1);
|
1);
|
||||||
SamplingRule rule2 =
|
SamplingRule rule2 =
|
||||||
SamplingRule.create(
|
SamplingRule.create(
|
||||||
Collections.emptyMap(),
|
Collections.singletonMap("test", "dog-service"),
|
||||||
0.0,
|
0.0,
|
||||||
"*",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
|
@ -60,13 +61,13 @@ class XrayRulesSamplerTest {
|
||||||
"*",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
"dog-rule",
|
"dog-rule",
|
||||||
"dog-service",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
1);
|
1);
|
||||||
SamplingRule rule3 =
|
SamplingRule rule3 =
|
||||||
SamplingRule.create(
|
SamplingRule.create(
|
||||||
Collections.emptyMap(),
|
Collections.singletonMap("test", "*-service"),
|
||||||
1.0,
|
1.0,
|
||||||
"*",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
|
@ -75,7 +76,7 @@ class XrayRulesSamplerTest {
|
||||||
"*",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
"bat-rule",
|
"bat-rule",
|
||||||
"*-service",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
"*",
|
"*",
|
||||||
1);
|
1);
|
||||||
|
@ -174,7 +175,7 @@ class XrayRulesSamplerTest {
|
||||||
TraceId.fromLongs(1, 2),
|
TraceId.fromLongs(1, 2),
|
||||||
name,
|
name,
|
||||||
SpanKind.CLIENT,
|
SpanKind.CLIENT,
|
||||||
Attributes.empty(),
|
Attributes.of(AttributeKey.stringKey("test"), name),
|
||||||
Collections.emptyList());
|
Collections.emptyList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"Priority": 1,
|
"Priority": 1,
|
||||||
"FixedRate": 1.0,
|
"FixedRate": 1.0,
|
||||||
"ReservoirSize": 1000,
|
"ReservoirSize": 1000,
|
||||||
"ServiceName": "test-service-foo-bar",
|
"ServiceName": "*",
|
||||||
"ServiceType": "AWS::Lambda::Function",
|
"ServiceType": "AWS::Lambda::Function",
|
||||||
"Host": "opentelemetry.io",
|
"Host": "opentelemetry.io",
|
||||||
"HTTPMethod": "GET",
|
"HTTPMethod": "GET",
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
"Priority": 1,
|
"Priority": 1,
|
||||||
"FixedRate": 1.0,
|
"FixedRate": 1.0,
|
||||||
"ReservoirSize": 1,
|
"ReservoirSize": 1,
|
||||||
"ServiceName": "cat-service",
|
"ServiceName": "*",
|
||||||
"ServiceType": "*",
|
"ServiceType": "*",
|
||||||
"Host": "*",
|
"Host": "*",
|
||||||
"HTTPMethod": "*",
|
"HTTPMethod": "*",
|
||||||
"URLPath": "*",
|
"URLPath": "*",
|
||||||
"Version": 1,
|
"Version": 1,
|
||||||
"Attributes": {}
|
"Attributes": { "test": "cat-service" }
|
||||||
},
|
},
|
||||||
"CreatedAt": "2021-06-18T17:28:15+09:00",
|
"CreatedAt": "2021-06-18T17:28:15+09:00",
|
||||||
"ModifiedAt": "2021-06-18T17:28:15+09:00"
|
"ModifiedAt": "2021-06-18T17:28:15+09:00"
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
"Priority": 1,
|
"Priority": 1,
|
||||||
"FixedRate": 0.0,
|
"FixedRate": 0.0,
|
||||||
"ReservoirSize": 1,
|
"ReservoirSize": 1,
|
||||||
"ServiceName": "cat-service",
|
"ServiceName": "*",
|
||||||
"ServiceType": "*",
|
"ServiceType": "*",
|
||||||
"Host": "*",
|
"Host": "*",
|
||||||
"HTTPMethod": "*",
|
"HTTPMethod": "*",
|
||||||
"URLPath": "*",
|
"URLPath": "*",
|
||||||
"Version": 1,
|
"Version": 1,
|
||||||
"Attributes": {}
|
"Attributes": { "test": "cat-service" }
|
||||||
},
|
},
|
||||||
"CreatedAt": "2021-06-18T17:28:15+09:00",
|
"CreatedAt": "2021-06-18T17:28:15+09:00",
|
||||||
"ModifiedAt": "2021-06-18T17:28:15+09:00"
|
"ModifiedAt": "2021-06-18T17:28:15+09:00"
|
||||||
|
|
Loading…
Reference in New Issue