Skip to content

Commit 86053a0

Browse files
author
Leonor Boga
authored
Merge pull request #919 from input-output-hk/feature/ETCM-573-measure-block-propagation
[ETCM-573] Add metrics on block imports
2 parents 4d04689 + bd60f20 commit 86053a0

File tree

8 files changed

+7232
-7011
lines changed

8 files changed

+7232
-7011
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: 48 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,6 +16,12 @@ 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)
@@ -20,12 +30,12 @@ class RegularSyncItSpec extends FreeSpecBase with Matchers with BeforeAndAfterAl
2030
"peer 2 should sync to the top of peer1 blockchain" - {
2131
"given a previously imported blockchain" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) {
2232
case (peer1, peer2) =>
23-
val blockNumer: Int = 2000
33+
val blockNumber: Int = 2000
2434
for {
25-
_ <- peer1.importBlocksUntil(blockNumer)(IdentityUpdate)
35+
_ <- peer1.importBlocksUntil(blockNumber)(IdentityUpdate)
2636
_ <- peer2.startRegularSync()
2737
_ <- peer2.connectToPeers(Set(peer1.node))
28-
_ <- peer2.waitForRegularSyncLoadLastBlock(blockNumer)
38+
_ <- peer2.waitForRegularSyncLoadLastBlock(blockNumber)
2939
} yield {
3040
assert(peer1.bl.getBestBlock().hash == peer2.bl.getBestBlock().hash)
3141
}
@@ -96,4 +106,39 @@ class RegularSyncItSpec extends FreeSpecBase with Matchers with BeforeAndAfterAl
96106
}
97107
}
98108

109+
"A metric about mining a new block should be available" in customTestCaseResourceM(
110+
FakePeer.start2FakePeersRes()
111+
) { case (peer1, peer2) =>
112+
import MantisRegistries._
113+
114+
val minedMetricBefore = sampleMetric(TimerCountMetric, MinedBlockPropagation)
115+
val defaultMetricBefore = sampleMetric(TimerCountMetric, DefaultBlockPropagation)
116+
117+
for {
118+
_ <- peer1.startRegularSync()
119+
_ <- peer1.mineNewBlocks(10.milliseconds, 1)(IdentityUpdate)
120+
_ <- peer1.waitForRegularSyncLoadLastBlock(1)
121+
_ <- peer2.startRegularSync()
122+
_ <- peer2.connectToPeers(Set(peer1.node))
123+
_ <- peer2.waitForRegularSyncLoadLastBlock(1)
124+
} yield {
125+
126+
val minedMetricAfter = sampleMetric(TimerCountMetric, MinedBlockPropagation).doubleValue()
127+
val defaultMetricAfter = sampleMetric(TimerCountMetric, DefaultBlockPropagation).doubleValue()
128+
129+
minedMetricAfter shouldBe minedMetricBefore + 1.0d
130+
defaultMetricAfter shouldBe defaultMetricBefore + 1.0d
131+
}
132+
}
133+
134+
object MantisRegistries {
135+
val TimerCountMetric = "app_regularsync_blocks_propagation_timer_seconds_count"
136+
val DefaultBlockPropagation = "DefaultBlockPropagation"
137+
val MinedBlockPropagation = "MinedBlockPropagation"
138+
def sampleMetric(metricName: String, blockType: String): Double = CollectorRegistry.defaultRegistry.getSampleValue(
139+
metricName,
140+
Array("blocktype"),
141+
Array(blockType)
142+
)
143+
}
99144
}

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
@@ -175,7 +175,7 @@ class FastSync(
175175

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

180180
requestedHeaders.get(peer).foreach { requestedNum =>
181181
removeRequestHandler(sender())
@@ -190,7 +190,7 @@ class FastSync(
190190

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

195195
val requestedBodies = requestedBlockBodies.getOrElse(sender(), Nil)
196196
requestedBlockBodies -= sender()
@@ -199,7 +199,7 @@ class FastSync(
199199

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

204204
val requestedHashes = requestedReceipts.getOrElse(sender(), Nil)
205205
requestedReceipts -= sender()
@@ -656,7 +656,7 @@ class FastSync(
656656
}
657657

658658
def processSyncing(): Unit = {
659-
SyncMetrics.measure(syncState)
659+
FastSyncMetrics.measure(syncState)
660660
if (fullySynced) {
661661
finish()
662662
} else {
@@ -676,7 +676,7 @@ class FastSync(
676676

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

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)