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
|
# Enable/disable info level logging of cluster events
|
||||||
log-info = on
|
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
|
# Enable or disable JMX MBeans for management of the cluster
|
||||||
jmx.enabled = on
|
jmx.enabled = on
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import akka.util.OptionVal
|
||||||
* cluster events published on the event bus.
|
* cluster events published on the event bus.
|
||||||
*/
|
*/
|
||||||
private[akka] class ClusterReadView(cluster: Cluster) extends Closeable {
|
private[akka] class ClusterReadView(cluster: Cluster) extends Closeable {
|
||||||
|
import cluster.InfoLogger._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current state
|
* Current state
|
||||||
|
|
@ -98,6 +99,15 @@ private[akka] class ClusterReadView(cluster: Cluster) extends Closeable {
|
||||||
}
|
}
|
||||||
case _ ⇒
|
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
|
case s: CurrentClusterState ⇒ _state = s
|
||||||
}
|
}
|
||||||
}).withDispatcher(cluster.settings.UseDispatcher).withDeploy(Deploy.local), name = "clusterEventBusListener")
|
}).withDispatcher(cluster.settings.UseDispatcher).withDeploy(Deploy.local), name = "clusterEventBusListener")
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ final class ClusterSettings(val config: Config, val systemName: String) {
|
||||||
import ClusterSettings._
|
import ClusterSettings._
|
||||||
private val cc = config.getConfig("akka.cluster")
|
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 FailureDetectorConfig: Config = cc.getConfig("failure-detector")
|
||||||
val FailureDetectorImplementationClass: String = FailureDetectorConfig.getString("implementation-class")
|
val FailureDetectorImplementationClass: String = FailureDetectorConfig.getString("implementation-class")
|
||||||
val HeartbeatInterval: FiniteDuration = {
|
val HeartbeatInterval: FiniteDuration = {
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
package akka.cluster
|
package akka.cluster
|
||||||
|
|
||||||
import akka.actor.{ Address, ExtendedActorSystem }
|
import akka.actor.{ Address, ExtendedActorSystem }
|
||||||
import akka.cluster.InternalClusterAction.LeaderActionsTick
|
|
||||||
import akka.testkit.{ AkkaSpec, EventFilter, ImplicitSender }
|
import akka.testkit.{ AkkaSpec, EventFilter, ImplicitSender }
|
||||||
|
import com.typesafe.config.{ Config, ConfigFactory }
|
||||||
|
|
||||||
object ClusterLogSpec {
|
object ClusterLogSpec {
|
||||||
val config = """
|
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)
|
protected val selfAddress: Address = system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
|
||||||
def clusterView: ClusterReadView = cluster.readView
|
|
||||||
|
protected val upLogMessage = " - event MemberUp"
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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 {
|
"A Cluster" must {
|
||||||
|
|
||||||
"Log a message when becoming and stopping being a leader" in {
|
"Log a message when becoming and stopping being a leader" in {
|
||||||
EventFilter
|
cluster.settings.LogInfo should ===(true)
|
||||||
.info(occurrences = 1, pattern = "is the new leader")
|
cluster.settings.LogInfoVerbose should ===(false)
|
||||||
.intercept {
|
join("is the new leader")
|
||||||
cluster.join(selfAddress)
|
awaitUp()
|
||||||
}
|
down("is no longer the leader")
|
||||||
|
}
|
||||||
awaitCond(clusterView.isSingletonCluster)
|
}
|
||||||
clusterView.self.address should ===(selfAddress)
|
}
|
||||||
clusterView.members.map(_.address) should ===(Set(selfAddress))
|
|
||||||
awaitAssert(clusterView.status should ===(MemberStatus.Up))
|
class ClusterLogVerboseDefaultSpec extends ClusterLogSpec(
|
||||||
|
ConfigFactory.parseString(ClusterLogSpec.config)) {
|
||||||
EventFilter
|
|
||||||
.info(occurrences = 1, pattern = "is no longer the leader")
|
"A Cluster" must {
|
||||||
.intercept {
|
|
||||||
cluster.down(selfAddress)
|
"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
|
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>
|
<a id="cluster-dispatcher"></a>
|
||||||
### Cluster Dispatcher
|
### Cluster Dispatcher
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue