From 4915fdc52e3e171a390a5df27e21d55d363f07b6 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Mon, 31 Aug 2020 17:05:47 +0200 Subject: [PATCH 1/6] remove the Akka gRPC dependecies from the kamon-play POM, fixes #844 --- instrumentation/kamon-play/build.sbt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 /** From c5d55bf5d99378ae59d6572828b16f9e303f0c3f Mon Sep 17 00:00:00 2001 From: "e.kholupko" Date: Thu, 3 Sep 2020 15:40:54 +0300 Subject: [PATCH 2/6] fix wrong response size --- .../prometheus/embeddedhttp/SunEmbeddedHttpServer.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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() } From cfc29d9d848b941abe8dfd8d9a07d66e19dbe650 Mon Sep 17 00:00:00 2001 From: Jarimatti Valkonen Date: Thu, 3 Sep 2020 22:37:09 +0100 Subject: [PATCH 3/6] = kamon-datadog: Improve filtering tests. The "filter other tags" test now tests metric tag filtering, not environment tag filtering. The code suggests that this is the intention. --- .../test/scala/kamon/datadog/DatadogMetricSenderSpec.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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( From f88156c75203fbd73895aad0d517d581e1ff3935 Mon Sep 17 00:00:00 2001 From: SimunKaracic Date: Tue, 8 Sep 2020 14:45:40 +0200 Subject: [PATCH 4/6] Trigger CI workflow on pull-request --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e6262589..69c77cd47 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: From 22045fad73950441fccf6bcc1f62da8e26386868 Mon Sep 17 00:00:00 2001 From: SimunKaracic Date: Tue, 8 Sep 2020 16:24:10 +0200 Subject: [PATCH 5/6] Name pull_request action correctly --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69c77cd47..06252ff1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: Test all the things -on: [push, pull-request] +on: [push, pull_request] jobs: From 14bef34b5830ee82e3521a5f6488c58f8a76c770 Mon Sep 17 00:00:00 2001 From: SimunKaracic Date: Tue, 29 Sep 2020 14:35:32 +0200 Subject: [PATCH 6/6] Replace expiringMap with caffeine (#862) * Replace expiringMap with caffeine * Use interface instead of implementation --- build.sbt | 4 +++- .../cache/AnnotationCache.java | 21 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/build.sbt b/build.sbt index ac33e64f9..8f7045aea 100644 --- a/build.sbt +++ b/build.sbt @@ -339,9 +339,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", @@ -637,4 +639,4 @@ val `kamon-bundle` = (project in file("bundle/kamon-bundle")) `kamon-akka-http` % "shaded", `kamon-play` % "shaded", `kamon-okhttp` % "shaded", - ) \ No newline at end of file + ) 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); };