Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace akka based names in logging code #197

Merged
merged 6 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import pekko.testkit.TestKit
if (event.message == null) "" else event.message

private def sourceOrEmpty(event: LoggingEvent): String =
event.mdc.getOrElse("akkaSource", "")
event.mdc.getOrElse("pekkoSource", "")

def apply(event: LoggingEvent): Boolean = {
if (matches(event)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ import pekko.annotation.DoNotInherit
def withLoggerName(newLoggerName: String): LoggingTestKit

/**
* Matching events that have "akkaSource" MDC value equal to the given value.
* "akkaSource" is typically the actor path.
* Matching events that have "pekkoSource" MDC value equal to the given value.
* "pekkoSource" is typically the actor path.
*/
def withSource(newSource: String): LoggingTestKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ import pekko.annotation.DoNotInherit
def withLoggerName(newLoggerName: String): LoggingTestKit

/**
* Matching events that have "akkaSource" MDC value equal to the given value.
* "akkaSource" is typically the actor path.
* Matching events that have "pekkoSource" MDC value equal to the given value.
* "pekkoSource" is typically the actor path.
*/
def withSource(newSource: String): LoggingTestKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LoggingTestKitSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike
timeStamp = System.currentTimeMillis(),
marker = None,
throwable = None,
mdc = Map("akkaSource" -> source))
mdc = Map("pekkoSource" -> source))

"The LoggingEventFilter.error" must {
"filter errors without cause" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
}
}
val actor =
LoggingTestKit.info("Starting up").withMdc(Map(ActorMdc.AkkaTagsKey -> "tag1,tag2")).expect {
LoggingTestKit.info("Starting up").withMdc(Map(ActorMdc.PekkoTagsKey -> "tag1,tag2")).expect {
spawn(behavior, ActorTags("tag1", "tag2"))
}

LoggingTestKit.info("Got message").withMdc(Map(ActorMdc.AkkaTagsKey -> "tag1,tag2")).expect {
LoggingTestKit.info("Got message").withMdc(Map(ActorMdc.PekkoTagsKey -> "tag1,tag2")).expect {
actor ! "ping"
}
}
Expand Down Expand Up @@ -357,10 +357,10 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
// mdc on defer is empty
val ref = LoggingTestKit
.info("Starting")
// not counting for example "akkaSource", but it shouldn't have any other entries
// not counting for example "pekkoSource", but it shouldn't have any other entries
.withCustom(logEvent =>
logEvent.mdc.keysIterator.forall(entry =>
entry.startsWith("akka") || entry == "sourceActorSystem" || entry == "static") &&
entry.startsWith("pekko") || entry == "sourceActorSystem" || entry == "static") &&
logEvent.mdc("static") == "1")
.expect {
spawn(behaviors)
Expand Down Expand Up @@ -499,8 +499,8 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
try {
event.mdc should contain allElementsOf (
Map(
ActorMdc.AkkaAddressKey -> system.classicSystem.asInstanceOf[ExtendedActorSystem].provider.addressString,
ActorMdc.AkkaSourceKey -> actorPath.get.toString,
ActorMdc.PekkoAddressKey -> system.classicSystem.asInstanceOf[ExtendedActorSystem].provider.addressString,
ActorMdc.PekkoSourceKey -> actorPath.get.toString,
ActorMdc.SourceActorSystemKey -> system.name))
true
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ import scala.util.Success
// on each log entry or message, so do that up front here
tags.mkString(",")

val akkaSource = ctx.self.path.toString
val pekkoSource = ctx.self.path.toString

val akkaAddress =
val pekkoAddress =
ctx.system match {
case adapter: ActorSystemAdapter[_] => adapter.provider.addressString
case _ => Address("akka", ctx.system.name).toString
}

val sourceActorSystem = ctx.system.name

new LoggingContext(logger, tagsString, akkaSource, sourceActorSystem, akkaAddress, hasCustomName = false)
new LoggingContext(logger, tagsString, pekkoSource, sourceActorSystem, pekkoAddress, hasCustomName = false)
}
}

final case class LoggingContext(
logger: Logger,
tagsString: String,
akkaSource: String,
pekkoSource: String,
sourceActorSystem: String,
akkaAddress: String,
pekkoAddress: String,
hasCustomName: Boolean) {
// toggled once per message if logging is used to avoid having to
// touch the mdc thread local for cleanup in the end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ import org.apache.pekko.annotation.InternalApi
*/
@InternalApi private[pekko] object ActorMdc {
val SourceActorSystemKey = "sourceActorSystem"
val AkkaSourceKey = "akkaSource"
val AkkaTagsKey = "akkaTags"
val AkkaAddressKey = "akkaAddress"
val PekkoSourceKey = "pekkoSource"
val PekkoTagsKey = "pekkoTags"
val PekkoAddressKey = "pekkoAddress"

def setMdc(context: ActorContextImpl.LoggingContext): Unit = {
// avoid access to MDC ThreadLocal if not needed, see details in LoggingContext
context.mdcUsed = true
MDC.put(AkkaSourceKey, context.akkaSource)
MDC.put(PekkoSourceKey, context.pekkoSource)
MDC.put(SourceActorSystemKey, context.sourceActorSystem)
MDC.put(AkkaAddressKey, context.akkaAddress)
MDC.put(PekkoAddressKey, context.pekkoAddress)
// empty string for no tags, a single tag or a comma separated list of tags
if (context.tagsString.nonEmpty)
MDC.put(AkkaTagsKey, context.tagsString)
MDC.put(PekkoTagsKey, context.tagsString)
}

// MDC is cleared (if used) from aroundReceive in ActorAdapter after processing each message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ trait ActorContext[T] extends TypedActorContext[T] with ClassicActorContextProvi

/**
* Replace the current logger (or initialize a new logger if the logger was not touched before) with one that
* has ghe given name as logger name. Logger source MDC entry "akkaSource" will be the actor path.
* has ghe given name as logger name. Logger source MDC entry "pekkoSource" will be the actor path.
*
* *Warning*: This method is not thread-safe and must not be accessed from threads other
* than the ordinary actor message processing thread, such as [[java.util.concurrent.CompletionStage]] callbacks.
Expand All @@ -98,7 +98,7 @@ trait ActorContext[T] extends TypedActorContext[T] with ClassicActorContextProvi

/**
* Replace the current logger (or initialize a new logger if the logger was not touched before) with one that
* has ghe given class name as logger name. Logger source MDC entry "akkaSource" will be the actor path.
* has ghe given class name as logger name. Logger source MDC entry "pekkoSource" will be the actor path.
*
* *Warning*: This method is not thread-safe and must not be accessed from threads other
* than the ordinary actor message processing thread, such as [[java.util.concurrent.CompletionStage]] callbacks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ trait ActorContext[T] extends TypedActorContext[T] with ClassicActorContextProvi

/**
* Replace the current logger (or initialize a new logger if the logger was not touched before) with one that
* has the given name as logger name. Logger source MDC entry "akkaSource" will be the actor path.
* has the given name as logger name. Logger source MDC entry "pekkoSource" will be the actor path.
*
* *Warning*: This method is not thread-safe and must not be accessed from threads other
* than the ordinary actor message processing thread, such as [[java.util.concurrent.CompletionStage]] callbacks.
Expand All @@ -98,7 +98,7 @@ trait ActorContext[T] extends TypedActorContext[T] with ClassicActorContextProvi

/**
* Replace the current logger (or initialize a new logger if the logger was not touched before) with one that
* has the given class name as logger name. Logger source MDC entry "akkaSource" will be the actor path.
* has the given class name as logger name. Logger source MDC entry "pekkoSource" will be the actor path.
*
* *Warning*: This method is not thread-safe and must not be accessed from threads other
* than the ordinary actor message processing thread, such as [[scala.concurrent.Future]] callbacks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,30 @@ object ShardingLogMarker {
* INTERNAL API
*/
@InternalApi private[pekko] object Properties {
val ShardTypeName = "akkaShardTypeName"
val ShardId = "akkaShardId"
val ShardTypeName = "pekkoShardTypeName"
val ShardId = "pekkoShardId"
}

/**
* Marker "akkaShardAllocated" of log event when `ShardCoordinator` allocates a shard to a region.
* @param shardTypeName The `typeName` of the shard. Included as property "akkaShardTypeName".
* @param shardId The id of the shard. Included as property "akkaShardId".
* @param node The address of the node where the shard is allocated. Included as property "akkaRemoteAddress".
* Marker "pekkoShardAllocated" of log event when `ShardCoordinator` allocates a shard to a region.
* @param shardTypeName The `typeName` of the shard. Included as property "pekkoShardTypeName".
* @param shardId The id of the shard. Included as property "pekkoShardId".
* @param node The address of the node where the shard is allocated. Included as property "pekkoRemoteAddress".
*/
def shardAllocated(shardTypeName: String, shardId: String, node: Address): LogMarker =
LogMarker(
"akkaShardAllocated",
"pekkoShardAllocated",
Map(
Properties.ShardTypeName -> shardTypeName,
Properties.ShardId -> shardId,
LogMarker.Properties.RemoteAddress -> node))

/**
* Marker "akkaShardStarted" of log event when `ShardRegion` starts a shard.
* @param shardTypeName The `typeName` of the shard. Included as property "akkaShardTypeName".
* @param shardId The id of the shard. Included as property "akkaShardId".
* Marker "pekkoShardStarted" of log event when `ShardRegion` starts a shard.
* @param shardTypeName The `typeName` of the shard. Included as property "pekkoShardTypeName".
* @param shardId The id of the shard. Included as property "pekkoShardId".
*/
def shardStarted(shardTypeName: String, shardId: String): LogMarker =
LogMarker("akkaShardStarted", Map(Properties.ShardTypeName -> shardTypeName, Properties.ShardId -> shardId))
LogMarker("pekkoShardStarted", Map(Properties.ShardTypeName -> shardTypeName, Properties.ShardId -> shardId))

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ClusterActorLoggingSpec
LoggingTestKit
.info("Starting")
.withCustom { event =>
event.mdc(ActorMdc.AkkaAddressKey) == addressString
event.mdc(ActorMdc.PekkoAddressKey) == addressString
}
.expect {
spawn(behavior)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,124 +32,124 @@ object ClusterLogMarker {
* INTERNAL API
*/
@InternalApi private[pekko] object Properties {
val MemberStatus = "akkaMemberStatus"
val SbrDecision = "akkaSbrDecision"
val MemberStatus = "pekkoMemberStatus"
val SbrDecision = "pekkoSbrDecision"
}

/**
* Marker "akkaUnreachable" of log event when a node is marked as unreachable based no failure detector observation.
* @param node The address of the node that is marked as unreachable. Included as property "akkaRemoteAddress".
* Marker "pekkoUnreachable" of log event when a node is marked as unreachable based no failure detector observation.
* @param node The address of the node that is marked as unreachable. Included as property "pekkoRemoteAddress".
*/
def unreachable(node: Address): LogMarker =
LogMarker("akkaUnreachable", Map(LogMarker.Properties.RemoteAddress -> node))
LogMarker("pekkoUnreachable", Map(LogMarker.Properties.RemoteAddress -> node))

/**
* Marker "akkaReachable" of log event when a node is marked as reachable again based no failure detector observation.
* @param node The address of the node that is marked as reachable. Included as property "akkaRemoteAddress".
* Marker "pekkoReachable" of log event when a node is marked as reachable again based no failure detector observation.
* @param node The address of the node that is marked as reachable. Included as property "pekkoRemoteAddress".
*/
def reachable(node: Address): LogMarker =
LogMarker("akkaReachable", Map(LogMarker.Properties.RemoteAddress -> node))
LogMarker("pekkoReachable", Map(LogMarker.Properties.RemoteAddress -> node))

/**
* Marker "akkaHeartbeatStarvation" of log event when scheduled heartbeat was delayed.
* Marker "pekkoHeartbeatStarvation" of log event when scheduled heartbeat was delayed.
*/
val heartbeatStarvation: LogMarker =
LogMarker("akkaHeartbeatStarvation")
LogMarker("pekkoHeartbeatStarvation")

/**
* Marker "akkaClusterLeaderIncapacitated" of log event when leader can't perform its duties.
* Marker "pekkoClusterLeaderIncapacitated" of log event when leader can't perform its duties.
* Typically because there are unreachable nodes that have not been downed.
*/
val leaderIncapacitated: LogMarker =
LogMarker("akkaClusterLeaderIncapacitated")
LogMarker("pekkoClusterLeaderIncapacitated")

/**
* Marker "akkaClusterLeaderRestored" of log event when leader can perform its duties again.
* Marker "pekkoClusterLeaderRestored" of log event when leader can perform its duties again.
*/
val leaderRestored: LogMarker =
LogMarker("akkaClusterLeaderRestored")
LogMarker("pekkoClusterLeaderRestored")

/**
* Marker "akkaJoinFailed" of log event when node couldn't join seed nodes.
* Marker "pekkoJoinFailed" of log event when node couldn't join seed nodes.
*/
val joinFailed: LogMarker =
LogMarker("akkaJoinFailed")
LogMarker("pekkoJoinFailed")

/**
* Marker "akkaMemberChanged" of log event when a member's status is changed by the leader.
* @param node The address of the node that is changed. Included as property "akkaRemoteAddress"
* and "akkaRemoteAddressUid".
* @param status New member status. Included as property "akkaMemberStatus".
* Marker "pekkoMemberChanged" of log event when a member's status is changed by the leader.
* @param node The address of the node that is changed. Included as property "pekkoRemoteAddress"
* and "pekkoRemoteAddressUid".
* @param status New member status. Included as property "pekkoMemberStatus".
*/
def memberChanged(node: UniqueAddress, status: MemberStatus): LogMarker =
LogMarker(
"akkaMemberChanged",
"pekkoMemberChanged",
Map(
LogMarker.Properties.RemoteAddress -> node.address,
LogMarker.Properties.RemoteAddressUid -> node.longUid,
Properties.MemberStatus -> status))

/**
* Marker "akkaClusterSingletonStarted" of log event when Cluster Singleton
* Marker "pekkoClusterSingletonStarted" of log event when Cluster Singleton
* instance has started.
*/
val singletonStarted: LogMarker =
LogMarker("akkaClusterSingletonStarted")
LogMarker("pekkoClusterSingletonStarted")

/**
* Marker "akkaClusterSingletonTerminated" of log event when Cluster Singleton
* Marker "pekkoClusterSingletonTerminated" of log event when Cluster Singleton
* instance has terminated.
*/
val singletonTerminated: LogMarker =
LogMarker("akkaClusterSingletonTerminated")
LogMarker("pekkoClusterSingletonTerminated")

/**
* Marker "akkaSbrDowning" of log event when Split Brain Resolver has made a downing decision. Followed
* Marker "pekkoSbrDowning" of log event when Split Brain Resolver has made a downing decision. Followed
* by [[ClusterLogMarker.sbrDowningNode]] for each node that is downed.
* @param decision The downing decision. Included as property "akkaSbrDecision".
* @param decision The downing decision. Included as property "pekkoSbrDecision".
*/
def sbrDowning(decision: DowningStrategy.Decision): LogMarker =
LogMarker("akkaSbrDowning", Map(Properties.SbrDecision -> decision))
LogMarker("pekkoSbrDowning", Map(Properties.SbrDecision -> decision))

/**
* Marker "akkaSbrDowningNode" of log event when a member is downed by Split Brain Resolver.
* @param node The address of the node that is downed. Included as property "akkaRemoteAddress"
* and "akkaRemoteAddressUid".
* @param decision The downing decision. Included as property "akkaSbrDecision".
* Marker "pekkoSbrDowningNode" of log event when a member is downed by Split Brain Resolver.
* @param node The address of the node that is downed. Included as property "pekkoRemoteAddress"
* and "pekkoRemoteAddressUid".
* @param decision The downing decision. Included as property "pekkoSbrDecision".
*/
def sbrDowningNode(node: UniqueAddress, decision: DowningStrategy.Decision): LogMarker =
LogMarker(
"akkaSbrDowningNode",
"pekkoSbrDowningNode",
Map(
LogMarker.Properties.RemoteAddress -> node.address,
LogMarker.Properties.RemoteAddressUid -> node.longUid,
Properties.SbrDecision -> decision))

/**
* Marker "akkaSbrInstability" of log event when Split Brain Resolver has detected too much instability
* Marker "pekkoSbrInstability" of log event when Split Brain Resolver has detected too much instability
* and will down all nodes.
*/
val sbrInstability: LogMarker =
LogMarker("akkaSbrInstability")
LogMarker("pekkoSbrInstability")

/**
* Marker "akkaSbrLeaseAcquired" of log event when Split Brain Resolver has acquired the lease.
* @param decision The downing decision. Included as property "akkaSbrDecision".
* Marker "pekkoSbrLeaseAcquired" of log event when Split Brain Resolver has acquired the lease.
* @param decision The downing decision. Included as property "pekkoSbrDecision".
*/
def sbrLeaseAcquired(decision: DowningStrategy.Decision): LogMarker =
LogMarker("akkaSbrLeaseAcquired", Map(Properties.SbrDecision -> decision))
LogMarker("pekkoSbrLeaseAcquired", Map(Properties.SbrDecision -> decision))

/**
* Marker "akkaSbrLeaseDenied" of log event when Split Brain Resolver has acquired the lease.
* @param reverseDecision The (reverse) downing decision. Included as property "akkaSbrDecision".
* Marker "pekkoSbrLeaseDenied" of log event when Split Brain Resolver has acquired the lease.
* @param reverseDecision The (reverse) downing decision. Included as property "pekkoSbrDecision".
*/
def sbrLeaseDenied(reverseDecision: DowningStrategy.Decision): LogMarker =
LogMarker("akkaSbrLeaseDenied", Map(Properties.SbrDecision -> reverseDecision))
LogMarker("pekkoSbrLeaseDenied", Map(Properties.SbrDecision -> reverseDecision))

/**
* Marker "akkaSbrLeaseReleased" of log event when Split Brain Resolver has released the lease.
* Marker "pekkoSbrLeaseReleased" of log event when Split Brain Resolver has released the lease.
*/
val sbrLeaseReleased: LogMarker =
LogMarker("akkaSbrLeaseReleased")
LogMarker("pekkoSbrLeaseReleased")

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{ISO8601} [%-5level] [%logger] [%marker] [%X{akkaSource}] [%X{persistencePhase}] [%X{persistenceId}] - %msg %n</pattern>
<pattern>%date{ISO8601} [%-5level] [%logger] [%marker] [%X{pekkoSource}] [%X{persistencePhase}] [%X{persistenceId}] - %msg %n</pattern>
</encoder>
</appender>

Expand Down
Loading