Skip to content

Commit

Permalink
Remove Guava dependencies
Browse files Browse the repository at this point in the history
This is a re-application of wavefrontHQ/wavefront-spring-boot@3e57b88 since it seems when this file was copied here, an older version was used, I assume this version was used wavefrontHQ/wavefront-spring-boot@5d0414f but I'm not 100% sure that this assumption is correct.
  • Loading branch information
jonatan-ivanov committed Oct 5, 2022
1 parent 090cfda commit 1247db3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
1 change: 0 additions & 1 deletion config/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress files=".*Slf4j.*" checks="SLF4JIllegalImportCheck"/>
<suppress files=".*WavefrontSpanHandler.*" checks="IllegalImportCheck"/>
</suppressions>
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- Imports -->
<module name="IllegalImportCheck" >
<property name="id" value="GeneralIllegalImportCheck"/>
<property name="illegalPkgs" value="com.google.common.(?!cache).*,org.apache.commons.text.*,org.jetbrains.*,jdk.internal.jline.internal.*,reactor.util.annotation.*,org.checkerframework.checker.*,javax.ws.*"/>
<property name="illegalPkgs" value="com.google.common.*,org.apache.commons.text.*,org.jetbrains.*,jdk.internal.jline.internal.*,reactor.util.annotation.*,org.checkerframework.checker.*,javax.ws.*"/>
<property name="illegalClasses" value="org\.assertj\.core\.api\.Java6Assertions\..*,javax.annotation.Nullable"/>
<property name="regexp" value="true"/>
</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.micrometer.tracing.reporter.wavefront;

import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;
import com.wavefront.internal.reporter.WavefrontInternalReporter;
import com.wavefront.sdk.common.NamedThreadFactory;
import com.wavefront.sdk.common.Pair;
Expand All @@ -34,10 +32,7 @@
import java.io.IOException;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -138,7 +133,7 @@ public WavefrontSpanHandler(int maxQueueSize, WavefrontSender wavefrontSender, S
String source, ApplicationTags applicationTags, Set<String> redMetricsCustomTagKeys) {
this.wavefrontSender = wavefrontSender;
this.applicationTags = applicationTags;
this.discoveredHeartbeatMetrics = Sets.newConcurrentHashSet();
this.discoveredHeartbeatMetrics = ConcurrentHashMap.newKeySet();
this.spanMetrics = spanMetrics;

this.heartbeatMetricsScheduledExecutorService = Executors.newScheduledThreadPool(1,
Expand Down Expand Up @@ -216,7 +211,7 @@ static List<SpanLog> convertAnnotationsToSpanLogs(FinishedSpan span) {
}
List<SpanLog> spanLogs = new ArrayList<>(annotationCount);
for (int i = 0; i < annotationCount; i++) {
Map.Entry<Long, String> entry = Iterators.get(span.getEvents().iterator(), i);
Map.Entry<Long, String> entry = getAt(span.getEvents().iterator(), i);
long epochMicros = entry.getKey();
String value = entry.getValue();
spanLogs.add(new SpanLog(epochMicros, Collections.singletonMap("annotation", value)));
Expand All @@ -239,6 +234,33 @@ static List<Pair<String, String>> createDefaultTags(ApplicationTags applicationT
return result;
}

// Mostly from Guava
private static <T> T getAt(Iterator<T> iterator, int position) {
Objects.requireNonNull(iterator);
if (position < 0) {
throw new IndexOutOfBoundsException("position (" + position + ") must not be negative");
}

int skipped = advance(iterator, position);
if (!iterator.hasNext()) {
throw new IndexOutOfBoundsException("position (" + position
+ ") must be less than the number of elements that remained (" + skipped + ")");
}
else {
return iterator.next();
}
}

// From Guava
private static int advance(Iterator<?> iterator, int numberToAdvance) {
int i;
for (i = 0; i < numberToAdvance && iterator.hasNext(); ++i) {
iterator.next();
}

return i;
}

/**
* Exact same behavior as WavefrontSpanReporter.
* https://github.com/wavefrontHQ/wavefront-opentracing-sdk-java/blob/f1f08d8daf7b692b9b61dcd5bc24ca6befa8e710/src/main/java/com/wavefront/opentracing/reporting/WavefrontSpanReporter.java#L163-L179
Expand Down Expand Up @@ -466,8 +488,8 @@ static final class TagList extends ArrayList<Pair<String, String>> {
int tagCount = span.getTags().size();
addAll(defaultTags);
for (int i = 0; i < tagCount; i++) {
String tagKey = Iterators.get(span.getTags().keySet().iterator(), i);
String tagValue = Iterators.get(span.getTags().values().iterator(), i);
String tagKey = getAt(span.getTags().keySet().iterator(), i);
String tagValue = getAt(span.getTags().values().iterator(), i);
String key = tagKey;
String value = tagValue;
String lcKey = key.toLowerCase(Locale.ROOT);
Expand Down

0 comments on commit 1247db3

Please sign in to comment.