Skip to content

Commit 2beeac1

Browse files
author
Jaap van der Plas
authored
[ETCM-528] block creation metrics (#904)
1 parent d886a96 commit 2beeac1

File tree

10 files changed

+1780
-1355
lines changed

10 files changed

+1780
-1355
lines changed

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

Lines changed: 1739 additions & 1338 deletions
Large diffs are not rendered by default.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.iohk.ethereum.consensus
2+
3+
import io.iohk.ethereum.metrics.MetricsContainer
4+
5+
object ConsensusMetrics extends MetricsContainer {
6+
private final val blockGenTimer = "consensus.blocks.generate.timer"
7+
final val EthashBlockGeneratorTiming = metrics.timer(blockGenTimer, "class", "EthashBlockGenerator")
8+
final val RestrictedEthashBlockGeneratorTiming =
9+
metrics.timer(blockGenTimer, "class", "RestrictedEthashBlockGenerator")
10+
final val NoOmmersBlockGeneratorTiming = metrics.timer(blockGenTimer, "class", "NoOmmersBlockGenerator")
11+
}

src/main/scala/io/iohk/ethereum/consensus/blocks/NoOmmersBlockGenerator.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.iohk.ethereum.consensus.difficulty.DifficultyCalculator
55
import io.iohk.ethereum.domain._
66
import io.iohk.ethereum.ledger.{BlockPreparator, InMemoryWorldStateProxy}
77
import io.iohk.ethereum.utils.BlockchainConfig
8+
import io.iohk.ethereum.consensus.ConsensusMetrics
89

910
abstract class NoOmmersBlockGenerator(
1011
blockchain: Blockchain,
@@ -44,8 +45,7 @@ abstract class NoOmmersBlockGenerator(
4445
beneficiary: Address,
4546
x: Nil.type,
4647
initialWorldStateBeforeExecution: Option[InMemoryWorldStateProxy]
47-
): PendingBlockAndState = {
48-
48+
): PendingBlockAndState = ConsensusMetrics.NoOmmersBlockGeneratorTiming.record { () =>
4949
val pHeader = parent.header
5050
val blockNumber = pHeader.number + 1
5151

src/main/scala/io/iohk/ethereum/consensus/ethash/blocks/EthashBlockGenerator.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.iohk.ethereum.crypto.kec256
1010
import io.iohk.ethereum.domain._
1111
import io.iohk.ethereum.ledger.{BlockPreparator, InMemoryWorldStateProxy}
1212
import io.iohk.ethereum.utils.BlockchainConfig
13+
import io.iohk.ethereum.consensus.ConsensusMetrics
1314

1415
/** Internal API, used for testing (especially mocks) */
1516
trait EthashBlockGenerator extends TestBlockGenerator {
@@ -73,7 +74,7 @@ class EthashBlockGeneratorImpl(
7374
beneficiary: Address,
7475
x: Ommers,
7576
initialWorldStateBeforeExecution: Option[InMemoryWorldStateProxy]
76-
): PendingBlockAndState = {
77+
): PendingBlockAndState = ConsensusMetrics.EthashBlockGeneratorTiming.record { () =>
7778
val pHeader = parent.header
7879
val blockNumber = pHeader.number + 1
7980
val parentHash = pHeader.hash

src/main/scala/io/iohk/ethereum/consensus/ethash/blocks/RestrictedEthashBlockGeneratorImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.iohk.ethereum.domain.{Address, Block, Blockchain, SignedTransaction}
99
import io.iohk.ethereum.ledger.{BlockPreparator, InMemoryWorldStateProxy}
1010
import io.iohk.ethereum.utils.BlockchainConfig
1111
import org.bouncycastle.crypto.AsymmetricCipherKeyPair
12+
import io.iohk.ethereum.consensus.ConsensusMetrics
1213

1314
class RestrictedEthashBlockGeneratorImpl(
1415
validators: ValidatorsExecutor,
@@ -35,7 +36,7 @@ class RestrictedEthashBlockGeneratorImpl(
3536
beneficiary: Address,
3637
ommers: Ommers,
3738
initialWorldStateBeforeExecution: Option[InMemoryWorldStateProxy]
38-
): PendingBlockAndState = {
39+
): PendingBlockAndState = ConsensusMetrics.RestrictedEthashBlockGeneratorTiming.record { () =>
3940
val pHeader = parent.header
4041
val blockNumber = pHeader.number + 1
4142
val parentHash = pHeader.hash
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.iohk.ethereum.jsonrpc
22

33
import io.iohk.ethereum.metrics.MetricsContainer
4+
import java.util.concurrent.TimeUnit
5+
import java.time.Duration
46

57
case object JsonRpcControllerMetrics extends MetricsContainer {
68

@@ -9,10 +11,14 @@ case object JsonRpcControllerMetrics extends MetricsContainer {
911
*/
1012
final val NotFoundMethodsCounter = metrics.counter("json.rpc.notfound.calls.counter")
1113

12-
final val MethodsTimer = metrics.timer("json.rpc.methods.timer")
1314
final val MethodsSuccessCounter = metrics.counter("json.rpc.methods.success.counter")
1415
final val MethodsExceptionCounter = metrics.counter("json.rpc.methods.exception.counter")
1516
final val MethodsErrorCounter = metrics.counter("json.rpc.methods.error.counter")
1617

1718
final val HealhcheckErrorCounter = metrics.counter("json.rpc.healthcheck.error.counter")
19+
20+
final val MethodsTimerName = "json.rpc.methods.timer"
21+
22+
def recordMethodTime(method: String, time: Duration): Unit =
23+
metrics.timer("json.rpc.methods.timer", "method", method).record(time)
1824
}

src/main/scala/io/iohk/ethereum/jsonrpc/server/controllers/JsonRpcBaseController.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import org.json4s.{DefaultFormats, native}
1717
import scala.collection.immutable.ArraySeq
1818
import scala.concurrent.ExecutionContext
1919
import scala.concurrent.duration.FiniteDuration
20+
import io.micrometer.core.instrument.Timer
21+
import io.micrometer.core.annotation.Timed
22+
import java.time.Duration
2023

2124
trait ApisBase {
2225
def available: List[String]
@@ -67,9 +70,8 @@ trait JsonRpcBaseController {
6770
Task {
6871
JsonRpcControllerMetrics.MethodsSuccessCounter.increment()
6972

70-
val endTimeNanos = System.nanoTime()
71-
val dtNanos = endTimeNanos - startTimeNanos
72-
JsonRpcControllerMetrics.MethodsTimer.record(dtNanos, TimeUnit.NANOSECONDS)
73+
val time = Duration.ofNanos(System.nanoTime() - startTimeNanos)
74+
JsonRpcControllerMetrics.recordMethodTime(request.method, time)
7375
}
7476
}
7577
.onErrorRecoverWith { case t: Throwable =>

src/main/scala/io/iohk/ethereum/metrics/Metrics.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ case class Metrics(metricsPrefix: String, registry: MeterRegistry, serverPort: I
5454
/**
5555
* Returns a [[io.micrometer.core.instrument.Timer Timer]].
5656
*/
57-
def timer(name: String): Timer =
57+
def timer(name: String, tags: String*): Timer =
5858
Timer
5959
.builder(mkName(name))
60+
.tags(tags: _*)
6061
.register(registry)
6162

6263
/**

src/test/scala/io/iohk/ethereum/mpt/MerklePatriciaTrieSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ class MerklePatriciaTrieSuite extends AnyFunSuite with ScalaCheckPropertyChecks
625625
val keyToFind = x._1
626626
val proof = trie.getProof(keyToFind)
627627
assert(proof.isDefined)
628-
proof.map{ p =>
628+
proof.map { p =>
629629
assert(verifyProof[Array[Byte], Array[Byte]](trie.getRootHash, keyToFind, p) == ValidProof)
630630
}
631631
})

src/test/scala/io/iohk/ethereum/proof/MptProofVerifier.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object MptProofVerifier {
2323
)(implicit kSer: ByteArrayEncoder[K], vSer: ByteArraySerializable[V]): ProofVerifyResult = {
2424
val mptStore = mkStorage(proof)
2525
rebuildMpt(rootHash, mptStore)(kSer, vSer)
26-
.flatMap( trie => getKey(key, trie) )
26+
.flatMap(trie => getKey(key, trie))
2727
.fold(InvalidProof.apply, _ => ValidProof)
2828
}
2929

@@ -39,12 +39,14 @@ object MptProofVerifier {
3939
kSer: ByteArrayEncoder[K],
4040
vSer: ByteArraySerializable[V]
4141
): Either[MptProofError, MerklePatriciaTrie[K, V]] =
42-
Either.catchNonFatal {
43-
MerklePatriciaTrie[K, V](
44-
rootHash = rootHash,
45-
source = storage
46-
)
47-
}.leftMap(_ => MptProofError.UnableRebuildMpt)
42+
Either
43+
.catchNonFatal {
44+
MerklePatriciaTrie[K, V](
45+
rootHash = rootHash,
46+
source = storage
47+
)
48+
}
49+
.leftMap(_ => MptProofError.UnableRebuildMpt)
4850

4951
private def getKey[V, K](key: K, trie: MerklePatriciaTrie[K, V]): Either[MptProofError, Option[V]] =
5052
Either

0 commit comments

Comments
 (0)