Skip to content

Commit 7e61707

Browse files
author
Aurélien Richez
committed
code review
1 parent 9f48d40 commit 7e61707

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

src/main/scala/io/iohk/ethereum/jsonrpc/JsonRpcHealthcheck.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import io.iohk.ethereum.healthcheck.HealthcheckResult
44
import monix.eval.Task
55

66
final case class JsonRpcHealthcheck[Response](
7-
description: String,
7+
name: String,
88
healthCheck: Either[String, Response],
99
info: Option[String] = None
1010
) {
1111

1212
def toResult: HealthcheckResult = {
1313
healthCheck
1414
.fold(
15-
HealthcheckResult.error(description, _),
16-
result => HealthcheckResult.ok(description, info)
15+
HealthcheckResult.error(name, _),
16+
result => HealthcheckResult.ok(name, info)
1717
)
1818
}
1919

@@ -22,7 +22,7 @@ final case class JsonRpcHealthcheck[Response](
2222

2323
def collect[T](message: String)(collectFn: PartialFunction[Response, T]): JsonRpcHealthcheck[T] =
2424
copy(
25-
description = description,
25+
name = name,
2626
healthCheck = healthCheck.flatMap(collectFn.lift(_).toRight(message))
2727
)
2828

src/main/scala/io/iohk/ethereum/jsonrpc/NodeJsonRpcHealthChecker.scala

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,57 +35,55 @@ class NodeJsonRpcHealthChecker(
3535

3636
private var previousBestFetchingBlock: Option[(Instant, BigInt)] = None
3737

38-
final val peerCountHC = JsonRpcHealthcheck
38+
private val peerCountHC = JsonRpcHealthcheck
3939
.fromServiceResponse("peerCount", netService.peerCount(PeerCountRequest()))
40-
.map(healthcheck => healthcheck.withInfo(_.value.toString).withPredicate("peer count is 0")(_.value > 0))
40+
.map(
41+
_.withInfo(_.value.toString)
42+
.withPredicate("peer count is 0")(_.value > 0)
43+
)
4144

42-
final val storedBlockHC = JsonRpcHealthcheck
45+
private val storedBlockHC = JsonRpcHealthcheck
4346
.fromServiceResponse(
4447
"bestStoredBlock",
4548
ethBlocksService.getBlockByNumber(BlockByNumberRequest(BlockParam.Latest, fullTxs = true))
4649
)
47-
.map(healthcheck =>
48-
healthcheck
49-
.collect("No block is currently stored") { case EthBlocksService.BlockByNumberResponse(Some(v)) => v }
50+
.map(
51+
_.collect("No block is currently stored") { case EthBlocksService.BlockByNumberResponse(Some(v)) => v }
5052
.withInfo(_.number.toString)
5153
)
5254

53-
final val bestKnownBlockHC = JsonRpcHealthcheck
55+
private val bestKnownBlockHC = JsonRpcHealthcheck
5456
.fromServiceResponse("bestKnownBlock", getBestKnownBlockTask)
55-
.map(healthcheck => healthcheck.withInfo(_.toString))
57+
.map(_.withInfo(_.toString))
5658

57-
final val fetchingBlockHC = JsonRpcHealthcheck
59+
private val fetchingBlockHC = JsonRpcHealthcheck
5860
.fromServiceResponse("bestFetchingBlock", getBestFetchingBlockTask)
59-
.map(healthcheck =>
60-
healthcheck
61-
.collect("no best fetching block") { case Some(v) => v }
61+
.map(
62+
_.collect("no best fetching block") { case Some(v) => v }
6263
.withInfo(_.toString)
6364
)
6465

65-
final val updateStatusHC = JsonRpcHealthcheck
66+
private val updateStatusHC = JsonRpcHealthcheck
6667
.fromServiceResponse("updateStatus", getBestFetchingBlockTask)
67-
.map(healthcheck =>
68-
healthcheck
69-
.collect("no best fetching block") { case Some(v) => v }
68+
.map(
69+
_.collect("no best fetching block") { case Some(v) => v }
7070
.withPredicate(s"block did not change for more than ${config.noUpdateDurationThreshold.getSeconds()} s")(
7171
blockNumberHasChanged
7272
)
7373
)
7474

75-
final val syncStatusHC =
75+
private val syncStatusHC =
7676
JsonRpcHealthcheck
7777
.fromTask("syncStatus", syncingController.askFor[SyncProtocol.Status](SyncProtocol.GetStatus))
78-
.map(healthcheck =>
79-
healthcheck.withInfo {
80-
case NotSyncing => "STARTING"
81-
case s: Syncing if isConsideredSyncing(s.blocksProgress) => "SYNCING"
82-
case _ => "SYNCED"
83-
}
84-
)
78+
.map(_.withInfo {
79+
case NotSyncing => "STARTING"
80+
case s: Syncing if isConsideredSyncing(s.blocksProgress) => "SYNCING"
81+
case _ => "SYNCED"
82+
})
8583

8684
override def healthCheck(): Task[HealthcheckResponse] = {
8785
val responseTask = Task
88-
.sequence(
86+
.parSequence(
8987
List(
9088
peerCountHC,
9189
storedBlockHC,

0 commit comments

Comments
 (0)