Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use service.name resource attribute instead of span name for service … #138

Merged
merged 1 commit into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private SamplingRuleApplier(
this.nextSnapshotTimeNanos = nextSnapshotTimeNanos;
}

boolean matches(String name, Attributes attributes, Resource resource) {
boolean matches(Attributes attributes, Resource resource) {
int matchedAttributes = 0;
String httpTarget = null;
String httpMethod = null;
Expand Down Expand Up @@ -175,7 +175,7 @@ boolean matches(String name, Attributes attributes, Resource resource) {
}

return urlPathMatcher.matches(httpTarget)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about updating this matcher to HTTP URL instead of target? Separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah separate PR

&& serviceNameMatcher.matches(name)
&& serviceNameMatcher.matches(resource.getAttribute(ResourceAttributes.SERVICE_NAME))
&& httpMethodMatcher.matches(httpMethod)
&& hostMatcher.matches(host)
&& serviceTypeMatcher.matches(getServiceType(resource))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public SamplingResult shouldSample(
Attributes attributes,
List<LinkData> parentLinks) {
for (SamplingRuleApplier applier : ruleAppliers) {
if (applier.matches(name, attributes, resource)) {
if (applier.matches(attributes, resource)) {
return applier.shouldSample(
parentContext, traceId, name, spanKind, attributes, parentLinks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.ByteStreams;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.HttpStatus;
import com.linecorp.armeria.common.MediaType;
import com.linecorp.armeria.server.ServerBuilder;
import com.linecorp.armeria.testing.junit5.server.ServerExtension;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.TraceId;
Expand All @@ -35,8 +35,6 @@

class AwsXrayRemoteSamplerTest {

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private static final byte[] RULE_RESPONSE_1;
private static final byte[] RULE_RESPONSE_2;
private static final byte[] TARGETS_RESPONE;
Expand Down Expand Up @@ -121,57 +119,18 @@ void tearDown() {
@Test
void getAndUpdate() throws Exception {
// Initial Sampler allows all.
assertThat(
sampler
.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);
assertThat(doSample(sampler, "cat-service")).isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
assertThat(doSample(sampler, "dog-service")).isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);

rulesResponse.set(RULE_RESPONSE_1);

// cat-service allowed, others dropped
await()
.untilAsserted(
() -> {
assertThat(
sampler
.shouldSample(
Context.root(),
TRACE_ID,
"cat-service",
SpanKind.SERVER,
Attributes.empty(),
Collections.emptyList())
.getDecision())
assertThat(doSample(sampler, "cat-service"))
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
assertThat(
sampler
.shouldSample(
Context.root(),
TRACE_ID,
"dog-service",
SpanKind.SERVER,
Attributes.empty(),
Collections.emptyList())
.getDecision())
.isEqualTo(SamplingDecision.DROP);
assertThat(doSample(sampler, "dog-service")).isEqualTo(SamplingDecision.DROP);
});

rulesResponse.set(RULE_RESPONSE_2);
Expand All @@ -180,27 +139,8 @@ void getAndUpdate() throws Exception {
await()
.untilAsserted(
() -> {
assertThat(
sampler
.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())
assertThat(doSample(sampler, "cat-service")).isEqualTo(SamplingDecision.DROP);
assertThat(doSample(sampler, "dog-service"))
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
});

Expand All @@ -210,27 +150,9 @@ void getAndUpdate() throws Exception {
await()
.untilAsserted(
() -> {
assertThat(
sampler
.shouldSample(
Context.root(),
TRACE_ID,
"cat-service",
SpanKind.SERVER,
Attributes.empty(),
Collections.emptyList())
.getDecision())
assertThat(doSample(sampler, "cat-service"))
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
assertThat(
sampler
.shouldSample(
Context.root(),
TRACE_ID,
"dog-service",
SpanKind.SERVER,
Attributes.empty(),
Collections.emptyList())
.getDecision())
assertThat(doSample(sampler, "dog-service"))
.isEqualTo(SamplingDecision.RECORD_AND_SAMPLE);
});
}
Expand All @@ -245,4 +167,16 @@ void defaultInitialSampler() {
+ "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();
}
}
Loading