Skip to content

Commit 504cc2b

Browse files
author
Leonor Boga
committed
[ETCM-573] Add metrics on block imports
1 parent 427d8e8 commit 504cc2b

File tree

9 files changed

+7243
-7013
lines changed

9 files changed

+7243
-7013
lines changed

docker/mantis/grafana/provisioning/dashboards/mantis-dashboard.json

Lines changed: 7052 additions & 6929 deletions
Large diffs are not rendered by default.

src/it/scala/io/iohk/ethereum/sync/RegularSyncItSpec.scala

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.iohk.ethereum.sync
22

3+
import com.typesafe.config.ConfigValueFactory
34
import io.iohk.ethereum.FreeSpecBase
5+
import io.iohk.ethereum.metrics.{Metrics, MetricsConfig}
46
import io.iohk.ethereum.sync.util.RegularSyncItSpecUtils.FakePeer
57
import io.iohk.ethereum.sync.util.SyncCommonItSpec._
8+
import io.iohk.ethereum.utils.Config
9+
import io.prometheus.client.CollectorRegistry
610
import monix.execution.Scheduler
711
import org.scalatest.BeforeAndAfterAll
812
import org.scalatest.matchers.should.Matchers
@@ -12,20 +16,44 @@ import scala.concurrent.duration._
1216
class RegularSyncItSpec extends FreeSpecBase with Matchers with BeforeAndAfterAll {
1317
implicit val testScheduler = Scheduler.fixedPool("test", 16)
1418

19+
override def beforeAll(): Unit = {
20+
Metrics.configure(
21+
MetricsConfig(Config.config.withValue("metrics.enabled", ConfigValueFactory.fromAnyRef(true)))
22+
)
23+
}
24+
1525
override def afterAll(): Unit = {
1626
testScheduler.shutdown()
1727
testScheduler.awaitTermination(120.second)
1828
}
1929

30+
val getMinedBlockValue = CollectorRegistry.defaultRegistry.getSampleValue(
31+
_: String,
32+
Array("class"),
33+
Array("MinedBlockPropagation")
34+
)
35+
36+
val getNewBlockValue = CollectorRegistry.defaultRegistry.getSampleValue(
37+
_: String,
38+
Array("class"),
39+
Array("NewBlockPropagation")
40+
)
41+
42+
val getDefaultBlockValue = CollectorRegistry.defaultRegistry.getSampleValue(
43+
_: String,
44+
Array("class"),
45+
Array("DefaultBlockPropagation")
46+
)
47+
2048
"peer 2 should sync to the top of peer1 blockchain" - {
2149
"given a previously imported blockchain" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) {
2250
case (peer1, peer2) =>
23-
val blockNumer: Int = 2000
51+
val blockNumber: Int = 2000
2452
for {
25-
_ <- peer1.importBlocksUntil(blockNumer)(IdentityUpdate)
53+
_ <- peer1.importBlocksUntil(blockNumber)(IdentityUpdate)
2654
_ <- peer2.startRegularSync()
2755
_ <- peer2.connectToPeers(Set(peer1.node))
28-
_ <- peer2.waitForRegularSyncLoadLastBlock(blockNumer)
56+
_ <- peer2.waitForRegularSyncLoadLastBlock(blockNumber)
2957
} yield {
3058
assert(peer1.bl.getBestBlock().hash == peer2.bl.getBestBlock().hash)
3159
}
@@ -96,4 +124,27 @@ class RegularSyncItSpec extends FreeSpecBase with Matchers with BeforeAndAfterAl
96124
}
97125
}
98126

127+
"A metric about mining a new block should be available" in customTestCaseResourceM(
128+
FakePeer.start2FakePeersRes()
129+
) { case (peer1, peer2) =>
130+
val minedMetricBefore = getMinedBlockValue("app_regularsync_blocks_propagation_timer_seconds_count")
131+
val defaultMetricBefore = getDefaultBlockValue("app_regularsync_blocks_propagation_timer_seconds_count")
132+
133+
for {
134+
_ <- peer1.startRegularSync()
135+
_ <- peer1.mineNewBlocks(10.milliseconds, 1)(IdentityUpdate)
136+
_ <- peer1.waitForRegularSyncLoadLastBlock(1)
137+
_ <- peer2.startRegularSync()
138+
_ <- peer2.connectToPeers(Set(peer1.node))
139+
_ <- peer2.waitForRegularSyncLoadLastBlock(1)
140+
} yield {
141+
142+
val minedMetricAfter = getMinedBlockValue("app_regularsync_blocks_propagation_timer_seconds_count").doubleValue()
143+
val defaultMetricAfter =
144+
getDefaultBlockValue("app_regularsync_blocks_propagation_timer_seconds_count").doubleValue()
145+
146+
minedMetricAfter shouldBe minedMetricBefore + 1.0d
147+
defaultMetricAfter shouldBe defaultMetricBefore + 1.0d
148+
}
149+
}
99150
}

src/it/scala/io/iohk/ethereum/sync/util/RegularSyncItSpecUtils.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ object RegularSyncItSpecUtils {
105105
}
106106
}
107107

108-
def waitForRegularSyncLoadLastBlock(blockNumer: BigInt): Task[Boolean] = {
109-
retryUntilWithDelay(Task(bl.getBestBlockNumber() == blockNumer), 1.second, 90) { isDone => isDone }
108+
def waitForRegularSyncLoadLastBlock(blockNumber: BigInt): Task[Boolean] = {
109+
retryUntilWithDelay(Task(bl.getBestBlockNumber() == blockNumber), 1.second, 90) { isDone => isDone }
110110
}
111111

112112
def mineNewBlock(
@@ -116,9 +116,9 @@ object RegularSyncItSpecUtils {
116116
val currentWeight = bl
117117
.getChainWeightByHash(block.hash)
118118
.getOrElse(throw new RuntimeException(s"ChainWeight by hash: ${block.hash} doesn't exist"))
119-
val currentWolrd = getMptForBlock(block)
119+
val currentWorld = getMptForBlock(block)
120120
val (newBlock, _, _) =
121-
createChildBlock(block, currentWeight, currentWolrd, plusDifficulty)(updateWorldForBlock)
121+
createChildBlock(block, currentWeight, currentWorld, plusDifficulty)(updateWorldForBlock)
122122
regularSync ! SyncProtocol.MinedBlock(newBlock)
123123
}
124124

src/main/scala/io/iohk/ethereum/blockchain/sync/fast/FastSync.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class FastSync(
174174

175175
case ResponseReceived(peer, BlockHeaders(blockHeaders), timeTaken) =>
176176
log.info("*** Received {} block headers in {} ms ***", blockHeaders.size, timeTaken)
177-
SyncMetrics.setBlockHeadersDownloadTime(timeTaken)
177+
FastSyncMetrics.setBlockHeadersDownloadTime(timeTaken)
178178

179179
requestedHeaders.get(peer).foreach { requestedNum =>
180180
removeRequestHandler(sender())
@@ -189,7 +189,7 @@ class FastSync(
189189

190190
case ResponseReceived(peer, BlockBodies(blockBodies), timeTaken) =>
191191
log.info("Received {} block bodies in {} ms", blockBodies.size, timeTaken)
192-
SyncMetrics.setBlockBodiesDownloadTime(timeTaken)
192+
FastSyncMetrics.setBlockBodiesDownloadTime(timeTaken)
193193

194194
val requestedBodies = requestedBlockBodies.getOrElse(sender(), Nil)
195195
requestedBlockBodies -= sender()
@@ -198,7 +198,7 @@ class FastSync(
198198

199199
case ResponseReceived(peer, Receipts(receipts), timeTaken) =>
200200
log.info("Received {} receipts in {} ms", receipts.size, timeTaken)
201-
SyncMetrics.setBlockReceiptsDownloadTime(timeTaken)
201+
FastSyncMetrics.setBlockReceiptsDownloadTime(timeTaken)
202202

203203
val requestedHashes = requestedReceipts.getOrElse(sender(), Nil)
204204
requestedReceipts -= sender()
@@ -654,7 +654,7 @@ class FastSync(
654654
}
655655

656656
def processSyncing(): Unit = {
657-
SyncMetrics.measure(syncState)
657+
FastSyncMetrics.measure(syncState)
658658
if (fullySynced) {
659659
finish()
660660
} else {
@@ -674,7 +674,7 @@ class FastSync(
674674

675675
def finish(): Unit = {
676676
val totalTime = totalMinutesTaken()
677-
SyncMetrics.setFastSyncTotalTimeGauge(totalTime.toDouble)
677+
FastSyncMetrics.setFastSyncTotalTimeGauge(totalTime.toDouble)
678678
log.info("Total time taken for FastSync was {} minutes", totalTime)
679679
log.info("Block synchronization in fast mode finished, switching to regular mode")
680680

src/main/scala/io/iohk/ethereum/blockchain/sync/fast/SyncMetrics.scala renamed to src/main/scala/io/iohk/ethereum/blockchain/sync/fast/FastSyncMetrics.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.iohk.ethereum.blockchain.sync.fast
22

3-
import java.util.concurrent.atomic.AtomicLong
43
import com.google.common.util.concurrent.AtomicDouble
54
import io.iohk.ethereum.blockchain.sync.fast.FastSync.SyncState
65
import io.iohk.ethereum.metrics.MetricsContainer
76

7+
import java.util.concurrent.atomic.AtomicLong
88
import scala.concurrent.duration.MILLISECONDS
99

10-
object SyncMetrics extends MetricsContainer {
10+
object FastSyncMetrics extends MetricsContainer {
1111

1212
private final val PivotBlockNumberGauge =
1313
metrics.registry.gauge("fastsync.block.pivotBlock.number.gauge", new AtomicDouble(0d))

src/main/scala/io/iohk/ethereum/blockchain/sync/fast/SyncStateSchedulerActor.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import io.iohk.ethereum.utils.ByteStringUtils
2121
import io.iohk.ethereum.utils.Config.SyncConfig
2222
import monix.eval.Task
2323
import monix.execution.Scheduler
24+
2425
import scala.concurrent.duration._
2526

2627
class SyncStateSchedulerActor(
@@ -64,7 +65,7 @@ class SyncStateSchedulerActor(
6465
def handleRequestResults: Receive = {
6566
case ResponseReceived(peer, nodeData: NodeData, timeTaken) =>
6667
log.info("Received {} state nodes in {} ms", nodeData.values.size, timeTaken)
67-
SyncMetrics.setMptStateDownloadTime(timeTaken)
68+
FastSyncMetrics.setMptStateDownloadTime(timeTaken)
6869

6970
context unwatch (sender())
7071
self ! RequestData(nodeData, peer)

0 commit comments

Comments
 (0)