parent
40649151d0
commit
f872115512
5 changed files with 90 additions and 23 deletions
|
|
@ -114,6 +114,10 @@ akka {
|
|||
# Enable/disable info level logging of cluster events
|
||||
log-info = on
|
||||
|
||||
# Enable/disable verbose info-level logging of cluster events
|
||||
# for temporary troubleshooting. Defaults to 'off'.
|
||||
log-info-verbose = off
|
||||
|
||||
# Enable or disable JMX MBeans for management of the cluster
|
||||
jmx.enabled = on
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import akka.util.OptionVal
|
|||
* cluster events published on the event bus.
|
||||
*/
|
||||
private[akka] class ClusterReadView(cluster: Cluster) extends Closeable {
|
||||
import cluster.InfoLogger._
|
||||
|
||||
/**
|
||||
* Current state
|
||||
|
|
@ -98,6 +99,15 @@ private[akka] class ClusterReadView(cluster: Cluster) extends Closeable {
|
|||
}
|
||||
case _ ⇒
|
||||
}
|
||||
|
||||
// once captured, optional verbose logging of event
|
||||
e match {
|
||||
case _: SeenChanged ⇒ // ignore
|
||||
case event ⇒
|
||||
if (cluster.settings.LogInfoVerbose)
|
||||
logInfo(" - event {}", event)
|
||||
}
|
||||
|
||||
case s: CurrentClusterState ⇒ _state = s
|
||||
}
|
||||
}).withDispatcher(cluster.settings.UseDispatcher).withDeploy(Deploy.local), name = "clusterEventBusListener")
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ final class ClusterSettings(val config: Config, val systemName: String) {
|
|||
import ClusterSettings._
|
||||
private val cc = config.getConfig("akka.cluster")
|
||||
|
||||
val LogInfo: Boolean = cc.getBoolean("log-info")
|
||||
val LogInfoVerbose: Boolean = cc.getBoolean("log-info-verbose")
|
||||
val LogInfo: Boolean = LogInfoVerbose || cc.getBoolean("log-info")
|
||||
val FailureDetectorConfig: Config = cc.getConfig("failure-detector")
|
||||
val FailureDetectorImplementationClass: String = FailureDetectorConfig.getString("implementation-class")
|
||||
val HeartbeatInterval: FiniteDuration = {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
package akka.cluster
|
||||
|
||||
import akka.actor.{ Address, ExtendedActorSystem }
|
||||
import akka.cluster.InternalClusterAction.LeaderActionsTick
|
||||
import akka.testkit.{ AkkaSpec, EventFilter, ImplicitSender }
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
|
||||
object ClusterLogSpec {
|
||||
val config = """
|
||||
|
|
@ -25,33 +25,79 @@ object ClusterLogSpec {
|
|||
|
||||
}
|
||||
|
||||
class ClusterLogSpec extends AkkaSpec(ClusterLogSpec.config) with ImplicitSender {
|
||||
abstract class ClusterLogSpec(config: Config) extends AkkaSpec(config) with ImplicitSender {
|
||||
|
||||
val selfAddress: Address = system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
|
||||
def this(s: String) = this(ConfigFactory.parseString(s))
|
||||
|
||||
val cluster = Cluster(system)
|
||||
def clusterView: ClusterReadView = cluster.readView
|
||||
protected val selfAddress: Address = system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
|
||||
|
||||
"A Cluster" must {
|
||||
protected val upLogMessage = " - event MemberUp"
|
||||
|
||||
"Log a message when becoming and stopping being a leader" in {
|
||||
EventFilter
|
||||
.info(occurrences = 1, pattern = "is the new leader")
|
||||
.intercept {
|
||||
cluster.join(selfAddress)
|
||||
}
|
||||
protected val downLogMessage = " - event MemberDowned"
|
||||
|
||||
protected val cluster = Cluster(system)
|
||||
|
||||
protected def clusterView: ClusterReadView = cluster.readView
|
||||
|
||||
protected def awaitUp(): Unit = {
|
||||
awaitCond(clusterView.isSingletonCluster)
|
||||
clusterView.self.address should ===(selfAddress)
|
||||
clusterView.members.map(_.address) should ===(Set(selfAddress))
|
||||
awaitAssert(clusterView.status should ===(MemberStatus.Up))
|
||||
}
|
||||
|
||||
EventFilter
|
||||
.info(occurrences = 1, pattern = "is no longer the leader")
|
||||
.intercept {
|
||||
cluster.down(selfAddress)
|
||||
/** The expected log info pattern to intercept after a `cluster.join`. */
|
||||
protected def join(expected: String): Unit =
|
||||
EventFilter.
|
||||
info(occurrences = 1, pattern = expected).
|
||||
intercept(cluster.join(selfAddress))
|
||||
|
||||
/** The expected log info pattern to intercept after a `cluster.down`. */
|
||||
protected def down(expected: String): Unit =
|
||||
EventFilter.
|
||||
info(occurrences = 1, pattern = expected).
|
||||
intercept(cluster.down(selfAddress))
|
||||
}
|
||||
|
||||
class ClusterLogDefaultSpec extends ClusterLogSpec(ClusterLogSpec.config) {
|
||||
|
||||
"A Cluster" must {
|
||||
|
||||
"Log a message when becoming and stopping being a leader" in {
|
||||
cluster.settings.LogInfo should ===(true)
|
||||
cluster.settings.LogInfoVerbose should ===(false)
|
||||
join("is the new leader")
|
||||
awaitUp()
|
||||
down("is no longer the leader")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ClusterLogVerboseDefaultSpec extends ClusterLogSpec(
|
||||
ConfigFactory.parseString(ClusterLogSpec.config)) {
|
||||
|
||||
"A Cluster" must {
|
||||
|
||||
"not log verbose cluster events by default" in {
|
||||
cluster.settings.LogInfoVerbose should ===(false)
|
||||
intercept[AssertionError](join(upLogMessage))
|
||||
awaitUp()
|
||||
intercept[AssertionError](down(downLogMessage))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ClusterLogVerboseEnabledSpec extends ClusterLogSpec(
|
||||
ConfigFactory.parseString("akka.cluster.log-info-verbose = on").
|
||||
withFallback(ConfigFactory.parseString(ClusterLogSpec.config))) {
|
||||
|
||||
"A Cluster" must {
|
||||
|
||||
"log verbose cluster events when 'log-info-verbose = on'" in {
|
||||
cluster.settings.LogInfoVerbose should ===(true)
|
||||
join(upLogMessage)
|
||||
awaitUp()
|
||||
down(downLogMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -874,6 +874,12 @@ You can silence the logging of cluster events at info level with configuration p
|
|||
akka.cluster.log-info = off
|
||||
```
|
||||
|
||||
You can enable verbose logging of cluster events at info level, e.g. for temporary troubleshooting, with configuration property:
|
||||
|
||||
```
|
||||
akka.cluster.log-info-verbose = on
|
||||
```
|
||||
|
||||
<a id="cluster-dispatcher"></a>
|
||||
### Cluster Dispatcher
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue