Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kamon-io/Kamon into kamon-armeria…
Browse files Browse the repository at this point in the history
…-instrumentation
  • Loading branch information
lucasamoroso committed Sep 29, 2020
2 parents 82f9305 + 14bef34 commit 5efb8b5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Test all the things

on:
push:
on: [push, pull_request]


jobs:
ci:
Expand Down
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,29 +26,26 @@
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;
import java.util.Collections;
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 {

private static Map<MetricKey, Object> metrics = buildCache();

private static Map<MetricKey, Object> 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) {
Expand Down Expand Up @@ -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<MetricKey, Object> ExpirationListener() {
return (key, value) -> {
private static RemovalListener<MetricKey, Object> LogExpirationListener() {
return (key, value, cause) -> {
if(value instanceof Instrument) ((Instrument) value).remove();
Logger.debug(() -> "Expiring key: " + key + "with value" + value);
};
Expand Down
5 changes: 3 additions & 2 deletions instrumentation/kamon-play/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) =>
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 5efb8b5

Please sign in to comment.