diff --git a/build.gradle b/build.gradle index 12fca768..9c97544e 100755 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,6 @@ */ plugins { - id 'me.champeau.jmh' version '0.6.8' id "com.github.spotbugs" version "5.0.13" apply false id 'com.netflix.nebula.dependency-recommender' version '12.0.0' id 'com.netflix.nebula.netflixoss' version '11.1.1' @@ -28,7 +27,6 @@ ext { allprojects { apply plugin: 'com.netflix.nebula.dependency-recommender' apply plugin: 'com.netflix.nebula.netflixoss' - apply plugin: 'me.champeau.jmh' } subprojects { @@ -68,20 +66,11 @@ subprojects { dependencies { api 'org.slf4j:slf4j-api' - api 'com.google.guava:guava' + implementation 'com.github.ben-manes.caffeine:caffeine:2.9.2' api 'com.netflix.spectator:spectator-api' testImplementation 'org.testng:testng:6.1.1' testImplementation 'org.slf4j:slf4j-log4j12' testImplementation 'log4j:log4j:1.2.17' - jmh 'org.slf4j:slf4j-simple' - } - - jmh { - warmupIterations = 2 - iterations = 10 - fork = 5 - profilers = ['STACK'] - includes = ['.*'] } checkstyle { @@ -97,7 +86,6 @@ subprojects { ignoreFailures = false spotbugsMain.enabled = true spotbugsTest.enabled = false - spotbugsJmh.enabled = false } spotbugsMain { reports { diff --git a/dependencies.properties b/dependencies.properties index 39e8dffa..f17a1f95 100644 --- a/dependencies.properties +++ b/dependencies.properties @@ -6,7 +6,7 @@ com.fasterxml.jackson.core:jackson-annotations = 2.12.1 com.fasterxml.jackson.core:jackson-core = 2.12.1 com.fasterxml.jackson.core:jackson-databind = 2.12.1 com.fasterxml.jackson.dataformat:jackson-dataformat-smile = 2.12.1 -com.google.guava:guava = 19.0 +com.google.guava:guava = 32.1.3-jre com.netflix.archaius:archaius2-api = 2.3.16 com.netflix.archaius:archaius2-core = 2.3.16 com.netflix.awsobjectmapper:awsobjectmapper = 1.11.965 diff --git a/servo-atlas/build.gradle b/servo-atlas/build.gradle index 1c44a04d..b0a84352 100644 --- a/servo-atlas/build.gradle +++ b/servo-atlas/build.gradle @@ -8,7 +8,6 @@ dependencies { api 'io.netty:netty-buffer' api 'io.netty:netty-codec-http' api 'io.reactivex:rxjava' - jmh project(':servo-core') } jar { diff --git a/servo-core/src/main/java/com/netflix/servo/monitor/AbstractContextualMonitor.java b/servo-core/src/main/java/com/netflix/servo/monitor/AbstractContextualMonitor.java index 3960f57d..2cce05bd 100644 --- a/servo-core/src/main/java/com/netflix/servo/monitor/AbstractContextualMonitor.java +++ b/servo-core/src/main/java/com/netflix/servo/monitor/AbstractContextualMonitor.java @@ -15,7 +15,6 @@ */ package com.netflix.servo.monitor; -import com.google.common.base.Function; import com.netflix.servo.tag.BasicTagList; import com.netflix.servo.tag.TagList; import com.netflix.servo.tag.TaggingContext; @@ -24,6 +23,7 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.function.Function; /** * Base class used to simplify creation of contextual monitors. diff --git a/servo-core/src/main/java/com/netflix/servo/monitor/ContextualCounter.java b/servo-core/src/main/java/com/netflix/servo/monitor/ContextualCounter.java index 22bc494f..ebecafeb 100644 --- a/servo-core/src/main/java/com/netflix/servo/monitor/ContextualCounter.java +++ b/servo-core/src/main/java/com/netflix/servo/monitor/ContextualCounter.java @@ -15,9 +15,10 @@ */ package com.netflix.servo.monitor; -import com.google.common.base.Function; import com.netflix.servo.tag.TaggingContext; +import java.util.function.Function; + /** * Composite that maintains separate simple counters for each distinct set of tags returned by the * tagging context. diff --git a/servo-core/src/main/java/com/netflix/servo/monitor/ContextualTimer.java b/servo-core/src/main/java/com/netflix/servo/monitor/ContextualTimer.java index 8d17a3a2..c4e4092f 100644 --- a/servo-core/src/main/java/com/netflix/servo/monitor/ContextualTimer.java +++ b/servo-core/src/main/java/com/netflix/servo/monitor/ContextualTimer.java @@ -15,10 +15,10 @@ */ package com.netflix.servo.monitor; -import com.google.common.base.Function; import com.netflix.servo.tag.TaggingContext; import java.util.concurrent.TimeUnit; +import java.util.function.Function; /** * Composite that maintains separate simple timers for each distinct set of tags returned by the diff --git a/servo-core/src/main/java/com/netflix/servo/monitor/DoubleGauge.java b/servo-core/src/main/java/com/netflix/servo/monitor/DoubleGauge.java index 642ddc7c..0df98d37 100644 --- a/servo-core/src/main/java/com/netflix/servo/monitor/DoubleGauge.java +++ b/servo-core/src/main/java/com/netflix/servo/monitor/DoubleGauge.java @@ -15,11 +15,11 @@ */ package com.netflix.servo.monitor; -import com.google.common.util.concurrent.AtomicDouble; import com.netflix.servo.SpectatorContext; import com.netflix.servo.annotations.DataSourceType; import com.netflix.servo.tag.TagList; import com.netflix.spectator.api.Id; +import java.util.concurrent.atomic.AtomicReference; /** * A {@link Gauge} that reports a double value. @@ -28,7 +28,7 @@ public class DoubleGauge extends AbstractMonitor implements Gauge, SpectatorMonitor { private final MonitorConfig baseConfig; - private final AtomicDouble number; + private final AtomicReference number; private final SpectatorContext.LazyGauge spectatorGauge; /** @@ -39,7 +39,7 @@ public class DoubleGauge extends AbstractMonitor public DoubleGauge(MonitorConfig config) { super(config.withAdditionalTag(DataSourceType.GAUGE)); baseConfig = config; - number = new AtomicDouble(0.0); + number = new AtomicReference<>(0.0); spectatorGauge = SpectatorContext.gauge(config); } @@ -52,9 +52,9 @@ public void set(Double n) { } /** - * Returns a reference to the {@link com.google.common.util.concurrent.AtomicDouble}. + * Returns a reference to the {@link AtomicReference}. */ - public AtomicDouble getNumber() { + public AtomicReference getNumber() { return number; } @@ -92,7 +92,7 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = config.hashCode(); - final int n = Double.valueOf(number.get()).hashCode(); + final int n = number.get().hashCode(); result = 31 * result + n; return result; } diff --git a/servo-core/src/main/java/com/netflix/servo/monitor/DynamicGauge.java b/servo-core/src/main/java/com/netflix/servo/monitor/DynamicGauge.java index 931f0092..7b13a7fc 100644 --- a/servo-core/src/main/java/com/netflix/servo/monitor/DynamicGauge.java +++ b/servo-core/src/main/java/com/netflix/servo/monitor/DynamicGauge.java @@ -15,19 +15,15 @@ */ package com.netflix.servo.monitor; -import com.google.common.base.Throwables; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.ImmutableList; +import com.github.benmanes.caffeine.cache.Caffeine; import com.netflix.servo.DefaultMonitorRegistry; +import com.github.benmanes.caffeine.cache.LoadingCache; import com.netflix.servo.tag.TagList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; /** @@ -36,7 +32,7 @@ * Gauges are automatically expired after 15 minutes of inactivity. */ public final class DynamicGauge implements CompositeMonitor, SpectatorMonitor { - private static final Logger LOGGER = LoggerFactory.getLogger(DynamicGauge.class); + private static final String DEFAULT_EXPIRATION = "15"; private static final String DEFAULT_EXPIRATION_UNIT = "MINUTES"; private static final String CLASS_NAME = DynamicGauge.class.getCanonicalName(); @@ -49,7 +45,6 @@ public final class DynamicGauge implements CompositeMonitor, SpectatorMoni private static final DynamicGauge INSTANCE = new DynamicGauge(); private final LoadingCache gauges; - private final CompositeMonitor cacheMonitor; private DynamicGauge() { final String expiration = System.getProperty(EXPIRATION_PROP, DEFAULT_EXPIRATION); @@ -57,15 +52,10 @@ private DynamicGauge() { final long expirationValue = Long.parseLong(expiration); final TimeUnit expirationUnitValue = TimeUnit.valueOf(expirationUnit); - gauges = CacheBuilder.newBuilder() + gauges = Caffeine.newBuilder() .expireAfterAccess(expirationValue, expirationUnitValue) - .build(new CacheLoader() { - @Override - public DoubleGauge load(final MonitorConfig config) throws Exception { - return new DoubleGauge(config); - } - }); - cacheMonitor = Monitors.newCacheMonitor(CACHE_MONITOR_ID, gauges); + .build(DoubleGauge::new); + Monitors.newCacheMonitor(CACHE_MONITOR_ID, gauges); DefaultMonitorRegistry.getInstance().register(this); } @@ -102,12 +92,7 @@ public static void set(String name, TagList list, double value) { } private DoubleGauge get(MonitorConfig config) { - try { - return gauges.get(config); - } catch (ExecutionException e) { - LOGGER.error("Failed to get a gauge for {}: {}", config, e.getMessage()); - throw Throwables.propagate(e); - } + return gauges.get(config); } /** @@ -116,7 +101,7 @@ private DoubleGauge get(MonitorConfig config) { @Override public List> getMonitors() { final ConcurrentMap gaugesMap = gauges.asMap(); - return ImmutableList.copyOf(gaugesMap.values()); + return Collections.unmodifiableList(new ArrayList<>(gaugesMap.values())); } /** diff --git a/servo-core/src/main/java/com/netflix/servo/monitor/MonitoredCache.java b/servo-core/src/main/java/com/netflix/servo/monitor/MonitoredCache.java index fc2804f8..dacfef32 100644 --- a/servo-core/src/main/java/com/netflix/servo/monitor/MonitoredCache.java +++ b/servo-core/src/main/java/com/netflix/servo/monitor/MonitoredCache.java @@ -15,8 +15,8 @@ */ package com.netflix.servo.monitor; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheStats; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.stats.CacheStats; import com.netflix.servo.util.Memoizer; import java.util.concurrent.Callable; @@ -65,11 +65,6 @@ long loadCount() { return memoStats.get().loadCount(); } - @com.netflix.servo.annotations.Monitor(name = "loadExceptionCount", type = COUNTER) - long loadExceptionCount() { - return memoStats.get().loadExceptionCount(); - } - @com.netflix.servo.annotations.Monitor(name = "loadSuccessCount", type = COUNTER) long loadSuccessCount() { return memoStats.get().loadSuccessCount(); diff --git a/servo-core/src/main/java/com/netflix/servo/monitor/Monitors.java b/servo-core/src/main/java/com/netflix/servo/monitor/Monitors.java index a7709f47..0d567f7b 100644 --- a/servo-core/src/main/java/com/netflix/servo/monitor/Monitors.java +++ b/servo-core/src/main/java/com/netflix/servo/monitor/Monitors.java @@ -15,8 +15,7 @@ */ package com.netflix.servo.monitor; -import com.google.common.base.Function; -import com.google.common.cache.Cache; +import com.github.benmanes.caffeine.cache.Cache; import com.netflix.servo.DefaultMonitorRegistry; import com.netflix.servo.annotations.DataSourceType; import com.netflix.servo.annotations.MonitorTags; @@ -33,6 +32,7 @@ import java.util.Set; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import static com.netflix.servo.util.Reflection.getFieldsAnnotatedBy; import static com.netflix.servo.util.Reflection.getMethodsAnnotatedBy; diff --git a/servo-core/src/main/java/com/netflix/servo/publish/MetricTransformObserver.java b/servo-core/src/main/java/com/netflix/servo/publish/MetricTransformObserver.java index eaee0572..6881badb 100644 --- a/servo-core/src/main/java/com/netflix/servo/publish/MetricTransformObserver.java +++ b/servo-core/src/main/java/com/netflix/servo/publish/MetricTransformObserver.java @@ -15,10 +15,10 @@ */ package com.netflix.servo.publish; -import com.google.common.base.Function; import com.netflix.servo.Metric; import java.util.List; +import java.util.function.Function; import java.util.stream.Collectors; /** diff --git a/servo-core/src/main/java/com/netflix/servo/tag/Tags.java b/servo-core/src/main/java/com/netflix/servo/tag/Tags.java index 17f2ecd7..e6a4a4f1 100644 --- a/servo-core/src/main/java/com/netflix/servo/tag/Tags.java +++ b/servo-core/src/main/java/com/netflix/servo/tag/Tags.java @@ -15,37 +15,10 @@ */ package com.netflix.servo.tag; -import com.google.common.collect.Interner; -import com.google.common.collect.Interners; - /** * Helper functions for working with tags and tag lists. */ public final class Tags { - /** - * Keep track of the strings that have been used for keys and values. - */ - private static final Interner STR_CACHE = Interners.newWeakInterner(); - - /** - * Keep track of tags that have been seen before and reuse. - */ - private static final Interner TAG_CACHE = Interners.newWeakInterner(); - - /** - * Intern strings used for tag keys or values. - */ - public static String intern(String v) { - return STR_CACHE.intern(v); - } - - /** - * Returns the canonical representation of a tag. - */ - public static Tag intern(Tag t) { - return TAG_CACHE.intern(t); - } - /** * Interns custom tag types, assumes that basic tags are already interned. This is used to * ensure that we have a common view of tags internally. In particular, different subclasses of @@ -60,8 +33,7 @@ static Tag internCustom(Tag t) { * Create a new tag instance. */ public static Tag newTag(String key, String value) { - Tag newTag = new BasicTag(intern(key), intern(value)); - return intern(newTag); + return new BasicTag(key, value); } /** diff --git a/servo-example/build.gradle b/servo-example/build.gradle index bed109cb..015f6f82 100644 --- a/servo-example/build.gradle +++ b/servo-example/build.gradle @@ -2,6 +2,7 @@ dependencies { api project(':servo-core') api project(':servo-atlas') api project(':servo-graphite') + api "com.google.guava:guava:32.1.3-jre" } task(run, dependsOn: 'classes', type: JavaExec) {