Skip to content

Commit

Permalink
Merge pull request #377 from ScalaConsultants/372-fix-mailbox-intrume…
Browse files Browse the repository at this point in the history
…ntation

Fix mailbox instrumentation
  • Loading branch information
lgajowy authored Apr 13, 2022
2 parents 262d241 + 8486fcb commit 77a1c42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.scalac.mesmer.otelextension.instrumentations.akka.actor

import java.lang.{ Boolean => JBoolean }

import akka.MesmerMirrorTypes.ActorRefWithCell
import akka.MesmerMirrorTypes.Cell
import akka.actor.BoundedQueueProxy
Expand Down Expand Up @@ -31,7 +33,7 @@ object BoundedNodeMessageQueueAdvice {
case _: BoundedNodeMessageQueue =>
incDropped(
VirtualField
.find(classOf[AbstractBoundedNodeQueue[_]], classOf[Boolean])
.find(classOf[AbstractBoundedNodeQueue[_]], classOf[JBoolean])
.get(self.asInstanceOf[AbstractBoundedNodeQueue[_]]),
withCell.underlying
)
Expand All @@ -45,11 +47,10 @@ object BoundedNodeMessageQueueAdvice {

@inline
private def incDropped(result: Boolean, cell: Cell): Unit =
if (result && (cell ne null)) {
if (!result && (cell ne null)) {
val maybeActorMetrics = ActorCellDecorator.getMetrics(cell)
for {
actorMetrics <- maybeActorMetrics if actorMetrics.droppedMessages.isDefined

} actorMetrics.droppedMessages.get.inc()
}
}
Expand All @@ -59,7 +60,7 @@ object AbstractBoundedNodeQueueAdvice {
@OnMethodExit
def add(@Return result: Boolean, @Advice.This self: Object): Unit =
VirtualField
.find(classOf[AbstractBoundedNodeQueue[_]], classOf[Boolean])
.find(classOf[AbstractBoundedNodeQueue[_]], classOf[JBoolean])
.set(self.asInstanceOf[AbstractBoundedNodeQueue[_]], result)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,25 @@ class ActorMailboxTest
|
|bounded-node-queue {
| mailbox-type = "akka.dispatch.NonBlockingBoundedMailbox"
| mailbox-capacity = 5
| mailbox-capacity = 3
|}
|
|bounded-queue {
| mailbox-type = "akka.dispatch.BoundedMailbox"
| mailbox-push-timeout-time=0
| mailbox-capacity = 5
| mailbox-capacity = 3
|}
|
|bounded-priority-queue {
| mailbox-type = "io.scalac.mesmer.instrumentation.akka.actor.HashCodePriorityMailbox"
| mailbox-push-timeout-time=1
| mailbox-capacity = 5
| mailbox-capacity = 3
|}
|
|bounded-stable-priority-queue {
| mailbox-type = "io.scalac.mesmer.instrumentation.akka.actor.StableHashCodePriorityMailbox"
| mailbox-push-timeout-time=1
| mailbox-capacity = 5
| mailbox-capacity = 3
|}
|""".stripMargin
)
Expand Down Expand Up @@ -135,7 +135,7 @@ class ActorMailboxTest
(sut, context)
}

private def testWithProps(props: Props, amountOfMessages: Int = 10, expectedValue: Long = 5): Any = {
private def testWithProps(props: Props, amountOfMessages: Int = 10, expectedValue: Long = 7): Any = {

val (sut, context) = actorRefWithContext(props)

Expand Down

0 comments on commit 77a1c42

Please sign in to comment.