diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e6262589..06252ff1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: Test all the things -on: - push: +on: [push, pull_request] + jobs: ci: diff --git a/build.sbt b/build.sbt index 8e0803b3e..929434e48 100644 --- a/build.sbt +++ b/build.sbt @@ -340,9 +340,11 @@ lazy val `kamon-annotation` = (project in file("instrumentation/kamon-annotation assemblyShadeRules in assembly := Seq( ShadeRule.rename("javax.el.**" -> "kamon.lib.@0").inAll, ShadeRule.rename("com.sun.el.**" -> "kamon.lib.@0").inAll, + ShadeRule.rename("com.github.ben-manes.**" -> "kamon.lib.@0").inAll, ), libraryDependencies ++= Seq( kanelaAgent % "provided", + "com.github.ben-manes.caffeine" % "caffeine" % "2.8.5" % "provided,shaded", // provided? no? "org.glassfish" % "javax.el" % "3.0.1-b11" % "provided,shaded", scalatest % "test", logbackClassic % "test", diff --git a/instrumentation/kamon-annotation/src/main/java/kamon/annotation/instrumentation/cache/AnnotationCache.java b/instrumentation/kamon-annotation/src/main/java/kamon/annotation/instrumentation/cache/AnnotationCache.java index 66d273ec8..668ff4e4a 100644 --- a/instrumentation/kamon-annotation/src/main/java/kamon/annotation/instrumentation/cache/AnnotationCache.java +++ b/instrumentation/kamon-annotation/src/main/java/kamon/annotation/instrumentation/cache/AnnotationCache.java @@ -16,6 +16,8 @@ package kamon.annotation.instrumentation.cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.RemovalListener; import kamon.Kamon; import kamon.annotation.api.Time; import kamon.annotation.api.TrackConcurrency; @@ -24,9 +26,6 @@ import kamon.metric.*; import kamon.tag.TagSet; import kamon.trace.SpanBuilder; -import kanela.agent.libs.net.jodah.expiringmap.ExpirationListener; -import kanela.agent.libs.net.jodah.expiringmap.ExpirationPolicy; -import kanela.agent.libs.net.jodah.expiringmap.ExpiringMap; import kanela.agent.util.log.Logger; import java.lang.reflect.Method; @@ -34,6 +33,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; public final class AnnotationCache { @@ -41,12 +41,11 @@ public final class AnnotationCache { private static Map metrics = buildCache(); private static Map buildCache() { - return ExpiringMap - .builder() - .expiration(1, TimeUnit.MINUTES) - .expirationPolicy(ExpirationPolicy.ACCESSED) - .asyncExpirationListener(ExpirationListener()) - .build(); + return Caffeine.newBuilder() + .expireAfterAccess(1, TimeUnit.MINUTES) + .removalListener(LogExpirationListener()) + .build() + .asMap(); } public static Gauge getGauge(Method method, Object obj, Class clazz, String className, String methodName) { @@ -193,8 +192,8 @@ private static String getOperationName(String name, Object obj, Class clazz, return (evaluatedString.isEmpty() || evaluatedString.equals("unknown")) ? className + "." + methodName: evaluatedString; } - private static ExpirationListener ExpirationListener() { - return (key, value) -> { + private static RemovalListener LogExpirationListener() { + return (key, value, cause) -> { if(value instanceof Instrument) ((Instrument) value).remove(); Logger.debug(() -> "Expiring key: " + key + "with value" + value); }; diff --git a/instrumentation/kamon-play/build.sbt b/instrumentation/kamon-play/build.sbt index bc2663c8e..aae46459b 100644 --- a/instrumentation/kamon-play/build.sbt +++ b/instrumentation/kamon-play/build.sbt @@ -56,8 +56,9 @@ libraryDependencies ++= { if(scalaBinaryVersion.value == "2.11") Seq.empty else "com.typesafe.play" %% "play-logback" % `Play-2.8-version` % "test-play-2.8", )} -// We are explicitly removing the gRPC-related dependencies because they are not published for Scala 2.11. -PB.additionalDependencies := { if(scalaBinaryVersion.value == "2.11") Seq.empty else PB.additionalDependencies.value } +// We are explicitly removing the gRPC-related dependencies because the are manually added +// on the Test configuration for Play 2.8. +PB.additionalDependencies := Seq.empty /** diff --git a/reporters/kamon-datadog/src/test/scala/kamon/datadog/DatadogMetricSenderSpec.scala b/reporters/kamon-datadog/src/test/scala/kamon/datadog/DatadogMetricSenderSpec.scala index fb40669ca..01b93969e 100644 --- a/reporters/kamon-datadog/src/test/scala/kamon/datadog/DatadogMetricSenderSpec.scala +++ b/reporters/kamon-datadog/src/test/scala/kamon/datadog/DatadogMetricSenderSpec.scala @@ -67,7 +67,7 @@ class DatadogMetricSenderSpec extends WordSpec with Matchers with Reconfigure { buffer.lst should contain("test.counter" -> "0|c|#service:kamon-application,env:staging,tag1:value1") } - "filter out blacklisted tags" in AgentReporter(new TestBuffer(), ConfigFactory.parseString( + "filter out environment tags" in AgentReporter(new TestBuffer(), ConfigFactory.parseString( """ |kamon.datadog.environment-tags.exclude = [env] |kamon.environment.tags.env = staging @@ -97,7 +97,8 @@ class DatadogMetricSenderSpec extends WordSpec with Matchers with Reconfigure { "filter other tags" in AgentReporter(new TestBuffer(), ConfigFactory.parseString( """ - |kamon.datadog.environment-tags.exclude = [ "tag*" ] + |kamon.datadog.environment-tags.exclude = [] + |kamon.datadog.environment-tags.filter.excludes = [ "tag*" ] |kamon.environment.tags.env = staging |""".stripMargin).withFallback(Kamon.config())) { case (buffer, reporter) => @@ -120,7 +121,7 @@ class DatadogMetricSenderSpec extends WordSpec with Matchers with Reconfigure { ) buffer.lst should have size 1 - buffer.lst should contain("test.counter" -> "0|c|#service:kamon-application,env:staging,tag1:value1,tag2:value2,otherTag:otherValue") + buffer.lst should contain("test.counter" -> "0|c|#service:kamon-application,env:staging,otherTag:otherValue") } "append no tags" in AgentReporter(new TestBuffer(), ConfigFactory.parseString( diff --git a/reporters/kamon-prometheus/src/main/scala/kamon/prometheus/embeddedhttp/SunEmbeddedHttpServer.scala b/reporters/kamon-prometheus/src/main/scala/kamon/prometheus/embeddedhttp/SunEmbeddedHttpServer.scala index 14d15c69e..e3637930e 100644 --- a/reporters/kamon-prometheus/src/main/scala/kamon/prometheus/embeddedhttp/SunEmbeddedHttpServer.scala +++ b/reporters/kamon-prometheus/src/main/scala/kamon/prometheus/embeddedhttp/SunEmbeddedHttpServer.scala @@ -14,10 +14,12 @@ class SunEmbeddedHttpServer(hostname: String, port: Int, scrapeSource: ScrapeSou val handler = new HttpHandler { override def handle(httpExchange: HttpExchange): Unit = { val data = scrapeSource.scrapeData() - httpExchange.sendResponseHeaders(200, data.length) + val bytes = data.getBytes(StandardCharsets.UTF_8) + httpExchange.sendResponseHeaders(200, bytes.length) val os = httpExchange.getResponseBody - try - os.write(data.getBytes(StandardCharsets.UTF_8)) + try { + os.write(bytes) + } finally os.close() }