-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add module for monitoring akka-http client internals
- Loading branch information
Showing
6 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
description := "Kamon module for akka http client internals monitoring" |
12 changes: 12 additions & 0 deletions
12
ts-reaktive-kamon-akka-client/src/main/resources/META-INF/aop.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> | ||
|
||
<aspectj> | ||
<aspects> | ||
<aspect name="akka.http.impl.engine.client.PoolConductorMonitoring"/> | ||
<aspect name="akka.http.impl.engine.client.PoolInterfaceActorMonitoring"/> | ||
</aspects> | ||
|
||
<weaver> | ||
<include within="akka..*"/> | ||
</weaver> | ||
</aspectj> |
8 changes: 8 additions & 0 deletions
8
ts-reaktive-kamon-akka-client/src/main/resources/reference.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
kamon { | ||
modules { | ||
ts-akka-http-client { | ||
requires-aspectj = yes | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...mon-akka-client/src/main/scala/akka/http/impl/engine/client/PoolConductorMonitoring.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package akka.http.impl.engine.client | ||
|
||
import org.aspectj.lang.annotation.After | ||
import org.aspectj.lang.annotation.Aspect | ||
import org.aspectj.lang.annotation.Pointcut | ||
|
||
import akka.event.BusLogging | ||
import kamon.Kamon | ||
|
||
@Aspect | ||
class PoolConductorMonitoring { | ||
val slotStatesField = Class.forName("akka.http.impl.engine.client.PoolConductor$SlotSelector$$anon$1").getDeclaredField("slotStates") | ||
val slotSelectorField = Class.forName("akka.http.impl.engine.client.PoolConductor$SlotSelector$$anon$1").getDeclaredField("$outer") | ||
val logField = Class.forName("akka.http.impl.engine.client.PoolConductor$SlotSelector").getDeclaredField("log") | ||
|
||
@Pointcut("execution(akka.http.impl.engine.client.PoolConductor$SlotSelector$$anon$1.new(..)) && this(logic)") | ||
def newGraphStageLogic(logic: AnyRef): Unit = {} | ||
|
||
private val HOST = raw"//(.+):".r | ||
private val PORT = raw":([0-9]+)".r | ||
|
||
private def getTags(graphStageLogic: AnyRef): Map[String,String] = { | ||
slotSelectorField.setAccessible(true) | ||
val slotSelector = slotSelectorField.get(graphStageLogic) | ||
|
||
logField.setAccessible(true) | ||
val log = logField.get(slotSelector).asInstanceOf[BusLogging] | ||
val host = HOST.findFirstMatchIn(log.logSource).map(_.group(1)).getOrElse("unknown") | ||
val port = PORT.findAllMatchIn(log.logSource).toVector.lastOption.map(_.group(1)).getOrElse("80") | ||
|
||
Map("target_host" -> host, "target_port" -> port) | ||
} | ||
|
||
private val states: Map[String,Class[_]] = Map( | ||
"idle" -> Class.forName("akka.http.impl.engine.client.PoolConductor$Idle$"), | ||
"unconnected" -> Class.forName("akka.http.impl.engine.client.PoolConductor$Unconnected$"), | ||
"loaded" -> Class.forName("akka.http.impl.engine.client.PoolConductor$Loaded"), | ||
"busy" -> Class.forName("akka.http.impl.engine.client.PoolConductor$Busy")) | ||
|
||
@After("newGraphStageLogic(logic)") | ||
def afterNewGraphStageLogic(logic: AnyRef): Unit = { | ||
slotStatesField.setAccessible(true) | ||
val slotStates = slotStatesField.get(logic).asInstanceOf[Array[_]] | ||
|
||
val tags = getTags(logic) | ||
for ((name, stateClass) <- states) { | ||
// note: don't use "host" as a tag, since for Datadog, it will cause dogstatsd to swallow ALL _other_ default tags. | ||
Kamon.metrics.gauge(s"http-client.pool.connections.${name}", tags) { | ||
() => slotStates.count(s => s.getClass() eq stateClass).toLong | ||
} | ||
} | ||
} | ||
|
||
@Pointcut("execution(akka.http.impl.engine.client.PoolConductor$SlotSelector$$anon$1.postStop(..)) && this(logic)") | ||
def postStopGraphStageLogic(logic: AnyRef): Unit = {} | ||
|
||
@After("postStopGraphStageLogic(logic)") | ||
def afterPostStopGraphStageLogic(logic: AnyRef): Unit = { | ||
val tags = getTags(logic) | ||
for ((name, _) <- states) { | ||
Kamon.metrics.removeGauge(s"http-client.pool.connections.${name}", tags) | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...kka-client/src/main/scala/akka/http/impl/engine/client/PoolInterfaceActorMonitoring.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package akka.http.impl.engine.client | ||
|
||
import org.aspectj.lang.annotation.After | ||
import org.aspectj.lang.annotation.Aspect | ||
import org.aspectj.lang.annotation.Pointcut | ||
|
||
import akka.http.impl.engine.client.PoolInterfaceActor.PoolRequest | ||
import akka.http.impl.settings.HostConnectionPoolSetup | ||
import akka.stream.impl.Buffer | ||
import kamon.Kamon | ||
|
||
@Aspect | ||
class PoolInterfaceActorMonitoring { | ||
val inputBufferField = classOf[PoolInterfaceActor].getDeclaredField("akka$http$impl$engine$client$PoolInterfaceActor$$inputBuffer") | ||
val hcpsField = classOf[PoolInterfaceActor].getDeclaredField("akka$http$impl$engine$client$PoolInterfaceActor$$hcps") | ||
|
||
@Pointcut("execution(akka.http.impl.engine.client.PoolInterfaceActor.new(..)) && this(actor)") | ||
def create(actor: PoolInterfaceActor): Unit = {} | ||
|
||
@After("create(actor)") | ||
def afterCreate(actor: PoolInterfaceActor): Unit = { | ||
inputBufferField.setAccessible(true) | ||
val buffer = inputBufferField.get(actor).asInstanceOf[Buffer[PoolRequest]] | ||
hcpsField.setAccessible(true) | ||
val hcps = hcpsField.get(actor).asInstanceOf[HostConnectionPoolSetup] | ||
|
||
val tags = Map("target_host" -> hcps.host, "target_port" -> hcps.port.toString) | ||
Kamon.metrics.gauge("http-client.pool.queue.used", tags) { () => buffer.used.toLong } | ||
Kamon.metrics.gauge("http-client.pool.queue.capacity", tags) { () => buffer.capacity.toLong } | ||
} | ||
|
||
@Pointcut("execution(* akka.http.impl.engine.client.PoolInterfaceActor.afterStop(..)) && this(actor)") | ||
def stop(actor: PoolInterfaceActor): Unit = {} | ||
|
||
@After("stop(actor)") | ||
def afterStop(actor: PoolInterfaceActor): Unit = { | ||
hcpsField.setAccessible(true) | ||
val hcps = hcpsField.get(actor).asInstanceOf[HostConnectionPoolSetup] | ||
|
||
val tags = Map("target_host" -> hcps.host, "target_port" -> hcps.port.toString) | ||
Kamon.metrics.removeGauge("http-client.pool.queue.used", tags) | ||
Kamon.metrics.removeGauge("http-client.pool.queue.capacity", tags) | ||
} | ||
} |