-
Notifications
You must be signed in to change notification settings - Fork 75
[ETCM-573] Add metrics on block imports #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package io.iohk.ethereum.sync | ||
|
||
import com.typesafe.config.ConfigValueFactory | ||
import io.iohk.ethereum.FreeSpecBase | ||
import io.iohk.ethereum.metrics.{Metrics, MetricsConfig} | ||
import io.iohk.ethereum.sync.util.RegularSyncItSpecUtils.FakePeer | ||
import io.iohk.ethereum.sync.util.SyncCommonItSpec._ | ||
import io.iohk.ethereum.utils.Config | ||
import io.prometheus.client.CollectorRegistry | ||
import monix.execution.Scheduler | ||
import org.scalatest.BeforeAndAfterAll | ||
import org.scalatest.matchers.should.Matchers | ||
|
@@ -12,6 +16,12 @@ import scala.concurrent.duration._ | |
class RegularSyncItSpec extends FreeSpecBase with Matchers with BeforeAndAfterAll { | ||
implicit val testScheduler = Scheduler.fixedPool("test", 16) | ||
|
||
override def beforeAll(): Unit = { | ||
Metrics.configure( | ||
MetricsConfig(Config.config.withValue("metrics.enabled", ConfigValueFactory.fromAnyRef(true))) | ||
) | ||
} | ||
|
||
override def afterAll(): Unit = { | ||
testScheduler.shutdown() | ||
testScheduler.awaitTermination(120.second) | ||
|
@@ -20,12 +30,12 @@ class RegularSyncItSpec extends FreeSpecBase with Matchers with BeforeAndAfterAl | |
"peer 2 should sync to the top of peer1 blockchain" - { | ||
"given a previously imported blockchain" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) { | ||
case (peer1, peer2) => | ||
val blockNumer: Int = 2000 | ||
val blockNumber: Int = 2000 | ||
for { | ||
_ <- peer1.importBlocksUntil(blockNumer)(IdentityUpdate) | ||
_ <- peer1.importBlocksUntil(blockNumber)(IdentityUpdate) | ||
_ <- peer2.startRegularSync() | ||
_ <- peer2.connectToPeers(Set(peer1.node)) | ||
_ <- peer2.waitForRegularSyncLoadLastBlock(blockNumer) | ||
_ <- peer2.waitForRegularSyncLoadLastBlock(blockNumber) | ||
} yield { | ||
assert(peer1.bl.getBestBlock().hash == peer2.bl.getBestBlock().hash) | ||
} | ||
|
@@ -96,4 +106,39 @@ class RegularSyncItSpec extends FreeSpecBase with Matchers with BeforeAndAfterAl | |
} | ||
} | ||
|
||
"A metric about mining a new block should be available" in customTestCaseResourceM( | ||
FakePeer.start2FakePeersRes() | ||
) { case (peer1, peer2) => | ||
import MantisRegistries._ | ||
|
||
val minedMetricBefore = sampleMetric(TimerCountMetric, MinedBlockPropagation) | ||
val defaultMetricBefore = sampleMetric(TimerCountMetric, DefaultBlockPropagation) | ||
|
||
for { | ||
_ <- peer1.startRegularSync() | ||
_ <- peer1.mineNewBlocks(10.milliseconds, 1)(IdentityUpdate) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that it may be nice to create a value class for number of blocks: case class NumBlocks(val underlying: Int) extends AnyVal This would help make invocations like this a little clearer (at present, the only way to figure out way this Of course there is a tiny bit of extra code for this and whether it's worth paying that cost depends on how central the concept is in the codebase. Just using a regular (Same thinking applies to block number in |
||
_ <- peer1.waitForRegularSyncLoadLastBlock(1) | ||
_ <- peer2.startRegularSync() | ||
_ <- peer2.connectToPeers(Set(peer1.node)) | ||
_ <- peer2.waitForRegularSyncLoadLastBlock(1) | ||
} yield { | ||
|
||
val minedMetricAfter = sampleMetric(TimerCountMetric, MinedBlockPropagation).doubleValue() | ||
val defaultMetricAfter = sampleMetric(TimerCountMetric, DefaultBlockPropagation).doubleValue() | ||
|
||
minedMetricAfter shouldBe minedMetricBefore + 1.0d | ||
defaultMetricAfter shouldBe defaultMetricBefore + 1.0d | ||
} | ||
} | ||
|
||
object MantisRegistries { | ||
val TimerCountMetric = "app_regularsync_blocks_propagation_timer_seconds_count" | ||
val DefaultBlockPropagation = "DefaultBlockPropagation" | ||
val MinedBlockPropagation = "MinedBlockPropagation" | ||
def sampleMetric(metricName: String, blockType: String): Double = CollectorRegistry.defaultRegistry.getSampleValue( | ||
metricName, | ||
Array("blocktype"), | ||
Array(blockType) | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,8 +105,8 @@ object RegularSyncItSpecUtils { | |
} | ||
} | ||
|
||
def waitForRegularSyncLoadLastBlock(blockNumer: BigInt): Task[Boolean] = { | ||
retryUntilWithDelay(Task(bl.getBestBlockNumber() == blockNumer), 1.second, 90) { isDone => isDone } | ||
def waitForRegularSyncLoadLastBlock(blockNumber: BigInt): Task[Boolean] = { | ||
retryUntilWithDelay(Task(bl.getBestBlockNumber() == blockNumber), 1.second, 90) { isDone => isDone } | ||
} | ||
|
||
def mineNewBlock( | ||
|
@@ -116,9 +116,9 @@ object RegularSyncItSpecUtils { | |
val currentWeight = bl | ||
.getChainWeightByHash(block.hash) | ||
.getOrElse(throw new RuntimeException(s"ChainWeight by hash: ${block.hash} doesn't exist")) | ||
val currentWolrd = getMptForBlock(block) | ||
val currentWorld = getMptForBlock(block) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
val (newBlock, _, _) = | ||
createChildBlock(block, currentWeight, currentWolrd, plusDifficulty)(updateWorldForBlock) | ||
createChildBlock(block, currentWeight, currentWorld, plusDifficulty)(updateWorldForBlock) | ||
regularSync ! SyncProtocol.MinedBlock(newBlock) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice that you tested the metric 👍 (Though this was perhaps also out of necessity?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was. I need to understand better what was happening. I started by modifying an existing test and then created this one that is a bit more specific. I also found a bit weird that there are no tests on metrics at all