From 97472930d06856d9a3374eafce61911adfa0ab01 Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Sat, 28 Sep 2019 09:50:42 -0500 Subject: [PATCH] 2019 09 27 logging refactor pt2 (#765) * Remove AKKA_CONFIG that was preventing sane logging for akka, move db-commons reference.conf to testkit so we can control testkit applications, and then rename app/server/.../application.conf to reference.conf like good libraries should do * Update contributing.md * update a few more links inside of contributing.md * Run scalafmt --- .../{application.conf => reference.conf} | 0 docs/contributing.md | 12 ++++--- .../eclair/rpc/EclairRpcClientTest.scala | 2 +- .../eclair/rpc/EclairRpcTestUtilTest.scala | 2 +- .../bitcoins/node/networking/P2PClient.scala | 8 ++--- .../src/main/resources/reference.conf | 33 +++++++++++++++++++ .../testkit/rpc/BitcoindRpcTestUtil.scala | 2 -- .../testkit/util/BitcoindRpcTest.scala | 2 +- 8 files changed, 46 insertions(+), 15 deletions(-) rename app/server/src/main/resources/{application.conf => reference.conf} (100%) rename {db-commons => testkit}/src/main/resources/reference.conf (60%) diff --git a/app/server/src/main/resources/application.conf b/app/server/src/main/resources/reference.conf similarity index 100% rename from app/server/src/main/resources/application.conf rename to app/server/src/main/resources/reference.conf diff --git a/docs/contributing.md b/docs/contributing.md index f7cd67a8c8..c2208c1fbf 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -19,7 +19,7 @@ Bitcoin-S includes a couple of applications that can be run as standalone execut This includes the node, wallet and (partial) blockchain verification modules, as well as the server that bundles these three together and the CLI used to communicate with the server. These applications are configured with HOCON files. The file -[`reference.conf`](https://github.com/bitcoin-s/bitcoin-s/blob/master/db-commons/src/main/resources/reference.conf) +[`reference.conf`](../testkit/src/main/resources/reference.conf) is the basis configuration file, and every option read by Bitcoin-S should be present in this file. This means that you can copy sections from this file and edit them, to tune how the application runs on your machine. @@ -46,8 +46,10 @@ file you should edit would be `$HOME/.bitcoin-s/bitcoin-s.conf`. ### Running tests for the applications -You can place configuration files in the data directory that tests are being run in, -but you can also edit [`reference.conf`](https://github.com/bitcoin-s/bitcoin-s/blob/master/db-commons/src/main/resources/reference.conf). +You can place a `logback-test.xml` file in the `src/test/resources/` directory in the same project that tests are being run in. + +If the test suite depends on `testkit`, you can modify [`reference.conf`](../testkit/src/main/resources/reference.conf) +that is built into the testkit to control logging. ## Logging when working on Bitcoin-S tests @@ -66,13 +68,13 @@ pretty quickly. There's two way of doing this: ### Akka logging -The test logging for akka is controled by the [`akka.conf`](../testkit/src/main/resources/akka.conf) file inside of testkit. +The test logging for akka is controlled by the [`reference.conf`](../testkit/src/main/resources/reference.conf) file inside of testkit. This allows you to debug what is happening in our actors inside of bitcoin-s easier. For examples of what you can enable for akka to log, please look at their [logging documentation](https://doc.akka.io/docs/akka/current/logging.html#auxiliary-logging-options) The easiest thing to do to enable akka logging is to adjust the `loglevel` and `stdout-loglevel` from `OFF` to `DEBUG`. -If you want to enable this when you are running a bitcoin-s application, you will need to modify the [`application.conf`](../app/server/src/main/resources/application.conf) file +If you want to enable this when you are running a bitcoin-s application, you will need to modify the [`reference.conf`](../app/server/src/main/resources/reference.conf) file ## Developer productivity diff --git a/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala b/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala index 6239e34bb2..6794488107 100644 --- a/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala +++ b/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala @@ -60,7 +60,7 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll { } implicit val system: ActorSystem = - ActorSystem("EclairRpcClient", BitcoindRpcTestUtil.AKKA_CONFIG) + ActorSystem("EclairRpcClient") implicit val m: ActorMaterializer = ActorMaterializer.create(system) implicit val ec: ExecutionContext = m.executionContext implicit val bitcoinNp: RegTest.type = EclairRpcTestUtil.network diff --git a/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcTestUtilTest.scala b/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcTestUtilTest.scala index 2906fe9e6c..02b5d83081 100644 --- a/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcTestUtilTest.scala +++ b/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcTestUtilTest.scala @@ -10,7 +10,7 @@ import akka.stream.StreamTcpException class EclairRpcTestUtilTest extends AsyncFlatSpec with BeforeAndAfterAll { implicit private val actorSystem: ActorSystem = - ActorSystem("EclairRpcTestUtilTest", BitcoindRpcTestUtil.AKKA_CONFIG) + ActorSystem("EclairRpcTestUtilTest") private lazy val bitcoindRpcF = for { diff --git a/node/src/main/scala/org/bitcoins/node/networking/P2PClient.scala b/node/src/main/scala/org/bitcoins/node/networking/P2PClient.scala index 41dd1c3bdb..e35976e2db 100644 --- a/node/src/main/scala/org/bitcoins/node/networking/P2PClient.scala +++ b/node/src/main/scala/org/bitcoins/node/networking/P2PClient.scala @@ -57,8 +57,6 @@ case class P2PClientActor( extends Actor with P2PLogger { - - private var currentPeerMsgHandlerRecv = initPeerMsgHandlerReceiver /** @@ -107,9 +105,9 @@ case class P2PClientActor( handleCommand(cmd, peerOpt = None) case connected: Tcp.Connected => - val _ = Await.result( - handleEvent(connected, unalignedBytes = ByteVector.empty), - timeout) + val _ = + Await.result(handleEvent(connected, unalignedBytes = ByteVector.empty), + timeout) case msg: NetworkMessage => self.forward(msg.payload) case payload: NetworkPayload => diff --git a/db-commons/src/main/resources/reference.conf b/testkit/src/main/resources/reference.conf similarity index 60% rename from db-commons/src/main/resources/reference.conf rename to testkit/src/main/resources/reference.conf index 554cf38b1f..566acb5360 100644 --- a/db-commons/src/main/resources/reference.conf +++ b/testkit/src/main/resources/reference.conf @@ -54,4 +54,37 @@ bitcoin-s { bloomFalsePositiveRate = 0.0001 # percentage } +} + + +akka { + loglevel = "OFF" + stdout-loglevel = "OFF" + http { + client { + # The time after which an idle connection will be automatically closed. + # Set to `infinite` to completely disable idle connection timeouts. + + # some requests potentially take a long time, like generate and prune + idle-timeout = 5 minutes + } + } + + + actor { + debug { + # enable DEBUG logging of all AutoReceiveMessages (Kill, PoisonPill etc.) + autoreceive= off + # enable function of LoggingReceive, which is to log any received message at + # DEBUG level + receive = on + # enable DEBUG logging of unhandled messages + unhandled = off + + # enable DEBUG logging of actor lifecycle changes + lifecycle = off + + event-stream=off + } + } } \ No newline at end of file diff --git a/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala b/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala index 667baf15c8..270a4d2a9c 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala @@ -64,8 +64,6 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger { type RpcClientAccum = mutable.Builder[BitcoindRpcClient, Vector[BitcoindRpcClient]] - val AKKA_CONFIG: Config = ConfigFactory.load("akka.conf").resolve() - @tailrec private def randomDirName: String = { val dirname = 0.until(5).map(_ => Random.alphanumeric.head).mkString diff --git a/testkit/src/main/scala/org/bitcoins/testkit/util/BitcoindRpcTest.scala b/testkit/src/main/scala/org/bitcoins/testkit/util/BitcoindRpcTest.scala index 7e60ca7b51..df65857718 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/util/BitcoindRpcTest.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/util/BitcoindRpcTest.scala @@ -35,7 +35,7 @@ abstract class BitcoindRpcTest extends AsyncFlatSpec with BeforeAndAfterAll { protected val logger: Logger = LoggerFactory.getLogger(getClass) implicit val system: ActorSystem = - ActorSystem(getClass.getSimpleName, BitcoindRpcTestUtil.AKKA_CONFIG) + ActorSystem(getClass.getSimpleName) implicit val ec: ExecutionContext = system.dispatcher implicit val networkParam: NetworkParameters = BitcoindRpcTestUtil.network