Skip to content

Commit

Permalink
Pass metrics facade
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbown committed Oct 29, 2024
1 parent 9a81cd9 commit e8c9bdc
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ class CoordinatorApp(private val configs: CoordinatorConfig) {
Vertx.vertx(vertxConfig)
}
private val meterRegistry: MeterRegistry = BackendRegistries.getDefaultNow()
private val micrometerMetricsFacade = MicrometerMetricsFacade(meterRegistry, "linea")
private val httpJsonRpcClientFactory = VertxHttpJsonRpcClientFactory(
vertx,
meterRegistry,
micrometerMetricsFacade,
requestResponseLogLevel = Level.TRACE,
failuresLogLevel = Level.WARN
)
Expand Down Expand Up @@ -121,8 +122,6 @@ class CoordinatorApp(private val configs: CoordinatorConfig) {
)
)

private val micrometerMetricsFacade = MicrometerMetricsFacade(meterRegistry, "linea")

private val l1FeeHistoriesRepository =
FeeHistoriesRepositoryImpl(
FeeHistoriesRepositoryImpl.Config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import net.consensys.linea.BlockNumberAndHash
import net.consensys.linea.async.get
import net.consensys.linea.jsonrpc.client.JsonRpcClient
import net.consensys.linea.jsonrpc.client.VertxHttpJsonRpcClientFactory
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
Expand All @@ -35,9 +37,10 @@ class ShomeiClientTest {
wiremock = WireMockServer(WireMockConfiguration.options().dynamicPort())
wiremock.start()
meterRegistry = SimpleMeterRegistry()

val metricsFacade: MetricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
fakeShomeiServerURI = URI("http://127.0.0.1:" + wiremock.port()).toURL()
val rpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, meterRegistry)

val rpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, metricsFacade)
jsonRpcClient = rpcClientFactory.create(fakeShomeiServerURI)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import net.consensys.linea.errors.ErrorResponse
import net.consensys.linea.jsonrpc.client.JsonRpcClient
import net.consensys.linea.jsonrpc.client.RequestRetryConfig
import net.consensys.linea.jsonrpc.client.VertxHttpJsonRpcClientFactory
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import net.consensys.linea.traces.TracesCountersV1
import net.consensys.linea.traces.TracingModuleV1
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -71,7 +73,8 @@ class TracesGeneratorJsonRpcClientV1Test {

fakeTracesServerUri = URI("http://127.0.0.1:" + wiremock.port()).toURL()
meterRegistry = SimpleMeterRegistry()
val rpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, meterRegistry)
val metricsFacade: MetricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
val rpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, metricsFacade)
vertxHttpJsonRpcClient = rpcClientFactory.createWithRetries(
fakeTracesServerUri,
methodsToRetry = TracesGeneratorJsonRpcClientV1.retryableMethods,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import net.consensys.linea.errors.ErrorResponse
import net.consensys.linea.jsonrpc.client.JsonRpcClient
import net.consensys.linea.jsonrpc.client.RequestRetryConfig
import net.consensys.linea.jsonrpc.client.VertxHttpJsonRpcClientFactory
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import net.consensys.linea.traces.TracesCountersV2
import net.consensys.linea.traces.TracingModuleV2
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -66,7 +68,8 @@ class TracesGeneratorJsonRpcClientV2Test {

fakeTracesServerUri = URI("http://127.0.0.1:" + wiremock.port()).toURL()
meterRegistry = SimpleMeterRegistry()
val rpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, meterRegistry)
val metricsFacade: MetricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
val rpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, metricsFacade)
vertxHttpJsonRpcClient = rpcClientFactory.createWithRetries(
fakeTracesServerUri,
methodsToRetry = TracesGeneratorJsonRpcClientV2.retryableMethods,
Expand Down
1 change: 1 addition & 0 deletions coordinator/ethereum/gas-pricing/static-cap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {

testImplementation("io.vertx:vertx-junit5")
testImplementation "com.github.tomakehurst:wiremock-jre8:${libs.versions.wiremock.get()}"
testImplementation project(':jvm-libs:linea:metrics:micrometer')

testImplementation project(':coordinator:clients:smart-contract-client')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import net.consensys.linea.ethereum.gaspricing.staticcap.GasUsageRatioWeightedAv
import net.consensys.linea.ethereum.gaspricing.staticcap.MinMineableFeesPricerService
import net.consensys.linea.jsonrpc.client.RequestRetryConfig
import net.consensys.linea.jsonrpc.client.VertxHttpJsonRpcClientFactory
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import net.consensys.linea.web3j.Web3jBlobExtended
import net.consensys.toHexString
import net.consensys.toULong
Expand Down Expand Up @@ -53,6 +55,7 @@ import kotlin.time.Duration.Companion.seconds
@Disabled("Disable this test for now as causes issues with other tests because of price updates")
class MinMineableFeesPricerServiceIntegrationTest {
private val meterRegistry = SimpleMeterRegistry()
private val metricsFacade: MetricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
private val pollingInterval = 2.seconds
private val feeHistoryBlockCount = 10u
private val feeHistoryRewardPercentile = 15.0
Expand Down Expand Up @@ -362,7 +365,7 @@ class MinMineableFeesPricerServiceIntegrationTest {
}

private fun createGasPriceUpdater(vertx: Vertx) = GasPriceUpdaterImpl(
VertxHttpJsonRpcClientFactory(vertx, meterRegistry),
VertxHttpJsonRpcClientFactory(vertx, metricsFacade),
GasPriceUpdaterImpl.Config(
gethEndpoints = gethRecipients.map { URI(it).toURL() },
besuEndPoints = besuRecipients.map { URI(it).toURL() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import io.vertx.junit5.VertxTestContext
import net.consensys.linea.ethereum.gaspricing.MinerExtraDataV1
import net.consensys.linea.jsonrpc.client.RequestRetryConfig
import net.consensys.linea.jsonrpc.client.VertxHttpJsonRpcClientFactory
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -64,7 +66,9 @@ class ExtraDataV1UpdaterImplTest {
wiremock = WireMockServer(wireMockConfig().dynamicPort())
wiremock.start()
sequencerEndpoint = URI("http://localhost:${wiremock.port()}/sequencer/").toURL()
jsonRpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, SimpleMeterRegistry())
val meterRegistry = SimpleMeterRegistry()
val metricsFacade: MetricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
jsonRpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, metricsFacade)
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import io.vertx.junit5.VertxExtension
import io.vertx.junit5.VertxTestContext
import net.consensys.linea.jsonrpc.client.RequestRetryConfig
import net.consensys.linea.jsonrpc.client.VertxHttpJsonRpcClientFactory
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
Expand Down Expand Up @@ -72,9 +74,11 @@ class GasPriceUpdaterImplTest {
URI("http://localhost:${wiremock.port()}/besu-2/").toURL(),
URI("http://localhost:${wiremock.port()}/besu-3/").toURL()
)
val meterRegistry = SimpleMeterRegistry()
val metricsFacade: MetricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
jsonRpcClientFactory = VertxHttpJsonRpcClientFactory(
vertx,
SimpleMeterRegistry()
metricsFacade
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package net.consensys.linea.jsonrpc.client
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.michaelbull.result.Err
import com.github.michaelbull.result.Result
import io.micrometer.core.instrument.MeterRegistry
import io.vertx.core.Vertx
import io.vertx.core.http.HttpClientOptions
import io.vertx.core.http.HttpVersion
import net.consensys.linea.metrics.MetricsFacade
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
Expand Down Expand Up @@ -36,7 +36,7 @@ interface JsonRpcClientFactory {

class VertxHttpJsonRpcClientFactory(
private val vertx: Vertx,
private val meterRegistry: MeterRegistry,
private val metricsFacade: MetricsFacade,
private val requestResponseLogLevel: Level = Level.TRACE,
private val failuresLogLevel: Level = Level.DEBUG,
private val requestIdSupplier: Supplier<Any> = SequentialIdSupplier.singleton
Expand All @@ -62,7 +62,7 @@ class VertxHttpJsonRpcClientFactory(
return VertxHttpJsonRpcClient(
httpClient,
endpoint,
meterRegistry,
metricsFacade,
log = log,
requestParamsObjectMapper = requestObjectMapper,
responseObjectMapper = responseObjectMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import io.vertx.core.json.JsonObject
import io.vertx.ext.auth.User
import io.vertx.junit5.VertxExtension
import io.vertx.junit5.VertxTestContext
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -21,6 +23,7 @@ private fun <T> Future<T>.get() = this.toCompletionStage().toCompletableFuture()
class JsonRpcMessageProcessorTest {
private lateinit var processor: JsonRpcMessageProcessor
private lateinit var meterRegistry: SimpleMeterRegistry
private lateinit var metricsFacade: MetricsFacade

@BeforeEach
fun setUp() {
Expand All @@ -29,7 +32,8 @@ class JsonRpcMessageProcessorTest {
Future.succeededFuture(Ok(JsonRpcSuccessResponse(jsonRpcRequest.id, JsonObject())))
}
meterRegistry = SimpleMeterRegistry()
processor = JsonRpcMessageProcessor(fakeRequestHandlerAlwaysSuccess, meterRegistry)
metricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
processor = JsonRpcMessageProcessor(fakeRequestHandlerAlwaysSuccess, metricsFacade, meterRegistry)
}

@Test
Expand All @@ -39,6 +43,7 @@ class JsonRpcMessageProcessorTest {
val request = buildJsonRpcRequest(method = "eth_blockNumber")
val processor = JsonRpcMessageProcessor(
{ _, _, _ -> throw RuntimeException("Something went wrong") },
metricsFacade,
meterRegistry
)
processor(null, request.toString())
Expand Down Expand Up @@ -182,7 +187,7 @@ class JsonRpcMessageProcessorTest {

val jsonStr = Json.encode(JsonArray(requests))

processor = JsonRpcMessageProcessor(fakeRequestHandlerWithSomeFailures, meterRegistry)
processor = JsonRpcMessageProcessor(fakeRequestHandlerWithSomeFailures, metricsFacade, meterRegistry)

processor(null, jsonStr)
.onComplete(
Expand Down Expand Up @@ -232,7 +237,7 @@ class JsonRpcMessageProcessorTest {
)
val singleAsBulk = listOf(buildJsonRpcRequest(id = 10, "read_value"))

processor = JsonRpcMessageProcessor(fakeRequestHandlerWithSomeFailures, meterRegistry)
processor = JsonRpcMessageProcessor(fakeRequestHandlerWithSomeFailures, metricsFacade, meterRegistry)
processor(null, Json.encode(request1)).get()
processor(null, Json.encode(request2)).get()
processor(null, Json.encode(request3)).get()
Expand Down Expand Up @@ -276,10 +281,10 @@ class JsonRpcMessageProcessorTest {
)
.isEqualTo(3.0)

assertThat(meterRegistry.timer("jsonrpc.processing.logic", "method", "read_value").count())
assertThat(meterRegistry.timer("linea.jsonrpc.processing.logic", "method", "read_value").count())
.isEqualTo(6)

assertThat(meterRegistry.timer("jsonrpc.processing.logic", "method", "update_value").count())
assertThat(meterRegistry.timer("linea.jsonrpc.processing.logic", "method", "update_value").count())
.isEqualTo(8)

assertThat(meterRegistry.timer("jsonrpc.serialization.request", "method", "read_value").count())
Expand All @@ -289,15 +294,15 @@ class JsonRpcMessageProcessorTest {
)
.isEqualTo(8)
assertThat(
meterRegistry.timer("jsonrpc.serialization.response", "method", "read_value").count()
meterRegistry.timer("linea.jsonrpc.serialization.response", "method", "read_value").count()
)
.isEqualTo(6)
assertThat(
meterRegistry.timer("jsonrpc.serialization.response", "method", "update_value").count()
meterRegistry.timer("linea.jsonrpc.serialization.response", "method", "update_value").count()
)
.isEqualTo(8)

assertThat(meterRegistry.timer("jsonrpc.serialization.response.bulk").count()).isEqualTo(2)
assertThat(meterRegistry.timer("linea.jsonrpc.serialization.response.bulk").count()).isEqualTo(2)
}

private fun buildJsonRpcRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import io.vertx.core.json.JsonObject
import io.vertx.junit5.VertxExtension
import net.consensys.decodeHex
import net.consensys.linea.jsonrpc.JsonRpcErrorResponseException
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
Expand Down Expand Up @@ -97,7 +99,8 @@ class JsonRpcV2ClientImplTest {
fun beforeEach(vertx: Vertx) {
this.vertx = vertx
this.meterRegistry = SimpleMeterRegistry()
this.factory = VertxHttpJsonRpcClientFactory(vertx, meterRegistry)
val metricsFacade: MetricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
this.factory = VertxHttpJsonRpcClientFactory(vertx, metricsFacade)
this.client = createClientAndSetupWireMockServer()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import net.consensys.linea.jsonrpc.JsonRpcError
import net.consensys.linea.jsonrpc.JsonRpcErrorResponse
import net.consensys.linea.jsonrpc.JsonRpcRequestListParams
import net.consensys.linea.jsonrpc.JsonRpcSuccessResponse
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
Expand All @@ -49,6 +51,7 @@ class VertxHttpJsonRpcClientTest {
private lateinit var wiremock: WireMockServer
private val path = "/api/v1?appKey=1234"
private lateinit var meterRegistry: SimpleMeterRegistry
private lateinit var metricsFacade: MetricsFacade
private val clientOptions =
HttpClientOptions()
.setKeepAlive(true)
Expand All @@ -63,7 +66,8 @@ class VertxHttpJsonRpcClientTest {
wiremock.start()
endpoint = URI(wiremock.baseUrl() + path).toURL()
meterRegistry = SimpleMeterRegistry()
client = VertxHttpJsonRpcClient(vertx.createHttpClient(clientOptions), endpoint, meterRegistry)
metricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
client = VertxHttpJsonRpcClient(vertx.createHttpClient(clientOptions), endpoint, metricsFacade)
}

@AfterEach
Expand Down Expand Up @@ -294,7 +298,7 @@ class VertxHttpJsonRpcClientTest {
client = VertxHttpJsonRpcClient(
vertx.createHttpClient(clientOptions),
endpoint,
meterRegistry,
metricsFacade,
log = log
)

Expand Down Expand Up @@ -322,7 +326,7 @@ class VertxHttpJsonRpcClientTest {
client = VertxHttpJsonRpcClient(
vertx.createHttpClient(clientOptions),
endpoint,
meterRegistry,
metricsFacade,
log = log
)

Expand Down Expand Up @@ -352,7 +356,7 @@ class VertxHttpJsonRpcClientTest {

val timer =
meterRegistry.timer(
"jsonrpc.request",
"linea.jsonrpc.request",
listOf(Tag.of("method", "randomNumber"), Tag.of("endpoint", "localhost"))
)

Expand Down
1 change: 1 addition & 0 deletions jvm-libs/linea/clients/linea-state-manager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:${libs.versions.jackson.get()}"

testImplementation(project(":jvm-libs:linea:testing:file-system"))
testImplementation project(':jvm-libs:linea:metrics:micrometer')
testImplementation "io.vertx:vertx-junit5"
testImplementation "com.github.tomakehurst:wiremock-jre8:${libs.versions.wiremock.get()}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import net.consensys.linea.async.get
import net.consensys.linea.errors.ErrorResponse
import net.consensys.linea.jsonrpc.client.RequestRetryConfig
import net.consensys.linea.jsonrpc.client.VertxHttpJsonRpcClientFactory
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import net.consensys.linea.testing.filesystem.findPathTo
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
Expand Down Expand Up @@ -54,8 +56,9 @@ class StateManagerV1JsonRpcClientTest {
wiremock = WireMockServer(options().dynamicPort())
wiremock.start()
meterRegistry = SimpleMeterRegistry()
val metricsFacade: MetricsFacade = MicrometerMetricsFacade(registry = meterRegistry, "linea")
stateManagerClient = StateManagerV1JsonRpcClient.create(
rpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, meterRegistry),
rpcClientFactory = VertxHttpJsonRpcClientFactory(vertx, metricsFacade),
endpoints = listOf(URI(wiremock.baseUrl())),
maxInflightRequestsPerClient = 1u,
requestRetry = RequestRetryConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ dependencies {
implementation(project(':state-recover:appcore:clients-interfaces'))
implementation(project(':state-recover:appcore:domain-models'))


testImplementation project(':jvm-libs:linea:core:metrics')
testImplementation project(':jvm-libs:linea:metrics:micrometer')
testImplementation "com.github.tomakehurst:wiremock-jre8:${libs.versions.wiremock.get()}"
testImplementation "net.javacrumbs.json-unit:json-unit-assertj:${libs.versions.jsonUnit.get()}"
}
Loading

0 comments on commit e8c9bdc

Please sign in to comment.