Skip to content

Commit

Permalink
Use an HashSet contract for DropTargetsSamplerTest
Browse files Browse the repository at this point in the history
It's a detail but it's the contract we want and matching will be faster.
  • Loading branch information
gsmet committed Jan 17, 2025
1 parent 7c3e93a commit 9cd2b13
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -171,7 +172,7 @@ public Sampler apply(Sampler existingSampler, ConfigProperties configProperties)
.orElse(existingSampler);

//collect default filtering targets (Needed for all samplers)
List<String> dropTargets = new ArrayList<>();
Set<String> dropTargets = new HashSet<>();
if (oTelRuntimeConfig.traces().suppressNonApplicationUris()) {//default is true
dropTargets.addAll(TracerRecorder.dropNonApplicationUriTargets);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static io.opentelemetry.semconv.UrlAttributes.URL_QUERY;

import java.util.List;
import java.util.Set;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
Expand All @@ -14,10 +15,10 @@

public class DropTargetsSampler implements Sampler {
private final Sampler sampler;
private final List<String> dropTargets;
private final Set<String> dropTargets;

public DropTargetsSampler(final Sampler sampler,
final List<String> dropTargets) {
final Set<String> dropTargets) {
this.sampler = sampler;
this.dropTargets = dropTargets;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.quarkus.opentelemetry.runtime.tracing;

import static io.opentelemetry.semconv.UrlAttributes.URL_PATH;
import static io.quarkus.opentelemetry.runtime.OpenTelemetryUtil.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;

import org.junit.jupiter.api.Test;
Expand All @@ -21,7 +21,7 @@ class DropTargetsSamplerTest {
@Test
void testDropTargets() {
CountingSampler countingSampler = new CountingSampler();
var sut = new DropTargetsSampler(countingSampler, List.of("/q/swagger-ui", "/q/swagger-ui*"));
var sut = new DropTargetsSampler(countingSampler, Set.of("/q/swagger-ui", "/q/swagger-ui*"));

assertEquals(SamplingResult.recordAndSample(), getShouldSample(sut, "/other"));
assertEquals(1, countingSampler.count.get());
Expand Down

0 comments on commit 9cd2b13

Please sign in to comment.