Metrics via dagger (#5244)

* dagger component
* pushed up MetricsSystemModule
* passes around the BesuComponent as an interim application context till more things are managed by Dagger

---------

Signed-off-by: Justin Florentine <justin+github@florentine.us>
pull/5374/head
Justin Florentine 2 years ago committed by GitHub
parent 681f4a5116
commit 25ab21128e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      acceptance-tests/dsl/build.gradle
  2. 2
      besu/build.gradle
  3. 37
      besu/src/main/java/org/hyperledger/besu/Besu.java
  4. 37
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  5. 71
      besu/src/main/java/org/hyperledger/besu/components/BesuCommandModule.java
  6. 69
      besu/src/main/java/org/hyperledger/besu/components/BesuComponent.java
  7. 19
      besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
  8. 22
      besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java
  9. 2
      ethereum/core/build.gradle
  10. 31
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/cache/CachedMerkleTrieLoaderModule.java
  11. 1
      ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java
  12. 5
      ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolComponent.java
  13. 4
      metrics/core/build.gradle
  14. 16
      metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricsConfigurationModule.java
  15. 45
      metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricsSystemModule.java
  16. 2
      metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/MetricsConfiguration.java

@ -28,6 +28,8 @@ dependencies {
implementation 'com.github.tomakehurst:wiremock-jre8' implementation 'com.github.tomakehurst:wiremock-jre8'
implementation 'com.google.guava:guava' implementation 'com.google.guava:guava'
implementation 'com.google.dagger:dagger'
annotationProcessor 'com.google.dagger:dagger-compiler'
implementation 'com.squareup.okhttp3:okhttp' implementation 'com.squareup.okhttp3:okhttp'
implementation 'info.picocli:picocli' implementation 'info.picocli:picocli'
implementation 'io.reactivex.rxjava2:rxjava' implementation 'io.reactivex.rxjava2:rxjava'

@ -63,6 +63,7 @@ dependencies {
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
implementation 'com.github.oshi:oshi-core' implementation 'com.github.oshi:oshi-core'
implementation 'com.google.guava:guava' implementation 'com.google.guava:guava'
implementation 'com.google.dagger:dagger'
implementation 'com.graphql-java:graphql-java' implementation 'com.graphql-java:graphql-java'
implementation 'info.picocli:picocli' implementation 'info.picocli:picocli'
implementation 'io.vertx:vertx-core' implementation 'io.vertx:vertx-core'
@ -102,4 +103,5 @@ dependencies {
testImplementation 'tech.pegasys.discovery:discovery' testImplementation 'tech.pegasys.discovery:discovery'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
annotationProcessor 'com.google.dagger:dagger-compiler'
} }

@ -1,5 +1,5 @@
/* /*
* Copyright ConsenSys AG. * Copyright Hyperledger Besu Contributors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
@ -14,13 +14,9 @@
*/ */
package org.hyperledger.besu; package org.hyperledger.besu;
import org.hyperledger.besu.chainexport.RlpBlockExporter;
import org.hyperledger.besu.chainimport.JsonBlockImporter;
import org.hyperledger.besu.chainimport.RlpBlockImporter;
import org.hyperledger.besu.cli.BesuCommand; import org.hyperledger.besu.cli.BesuCommand;
import org.hyperledger.besu.cli.logging.BesuLoggingConfigurationFactory; import org.hyperledger.besu.cli.logging.BesuLoggingConfigurationFactory;
import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.components.DaggerBesuComponent;
import org.hyperledger.besu.services.BesuPluginContextImpl;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import io.netty.util.internal.logging.Log4J2LoggerFactory; import io.netty.util.internal.logging.Log4J2LoggerFactory;
@ -37,19 +33,8 @@ public final class Besu {
* @param args command line arguments. * @param args command line arguments.
*/ */
public static void main(final String... args) { public static void main(final String... args) {
final Logger logger = setupLogging(); setupLogging();
final BesuCommand besuCommand = DaggerBesuComponent.create().getBesuCommand();
final BesuCommand besuCommand =
new BesuCommand(
logger,
RlpBlockImporter::new,
JsonBlockImporter::new,
RlpBlockExporter::new,
new RunnerBuilder(),
new BesuController.Builder(),
new BesuPluginContextImpl(),
System.getenv());
int exitCode = int exitCode =
besuCommand.parse( besuCommand.parse(
new RunLast(), new RunLast(),
@ -61,7 +46,11 @@ public final class Besu {
System.exit(exitCode); System.exit(exitCode);
} }
private static Logger setupLogging() { /**
* a Logger setup for handling any exceptions during the bootstrap process, to indicate to users
* their CLI configuration had problems.
*/
public static void setupLogging() {
try { try {
InternalLoggerFactory.setDefaultFactory(Log4J2LoggerFactory.INSTANCE); InternalLoggerFactory.setDefaultFactory(Log4J2LoggerFactory.INSTANCE);
} catch (Throwable t) { } catch (Throwable t) {
@ -81,6 +70,14 @@ public final class Besu {
"Could not set logging system property: %s - %s%n", "Could not set logging system property: %s - %s%n",
t.getClass().getSimpleName(), t.getMessage()); t.getClass().getSimpleName(), t.getMessage());
} }
}
/**
* Returns the first logger to be created. This is used to set the default uncaught exception
*
* @return Logger
*/
public static Logger getFirstLogger() {
final Logger logger = LoggerFactory.getLogger(Besu.class); final Logger logger = LoggerFactory.getLogger(Besu.class);
Thread.setDefaultUncaughtExceptionHandler(slf4jExceptionHandler(logger)); Thread.setDefaultUncaughtExceptionHandler(slf4jExceptionHandler(logger));
Thread.currentThread().setUncaughtExceptionHandler(slf4jExceptionHandler(logger)); Thread.currentThread().setUncaughtExceptionHandler(slf4jExceptionHandler(logger));

@ -86,6 +86,7 @@ import org.hyperledger.besu.cli.util.BesuCommandCustomFactory;
import org.hyperledger.besu.cli.util.CommandLineUtils; import org.hyperledger.besu.cli.util.CommandLineUtils;
import org.hyperledger.besu.cli.util.ConfigOptionSearchAndRunHandler; import org.hyperledger.besu.cli.util.ConfigOptionSearchAndRunHandler;
import org.hyperledger.besu.cli.util.VersionProvider; import org.hyperledger.besu.cli.util.VersionProvider;
import org.hyperledger.besu.components.BesuComponent;
import org.hyperledger.besu.config.CheckpointConfigOptions; import org.hyperledger.besu.config.CheckpointConfigOptions;
import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.GenesisConfigOptions;
@ -1323,8 +1324,15 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
private Collection<EnodeURL> staticNodes; private Collection<EnodeURL> staticNodes;
private BesuController besuController; private BesuController besuController;
private BesuConfiguration pluginCommonConfiguration; private BesuConfiguration pluginCommonConfiguration;
private BesuComponent besuComponent;
private final Supplier<ObservableMetricsSystem> metricsSystem = private final Supplier<ObservableMetricsSystem> metricsSystem =
Suppliers.memoize(() -> MetricsSystemFactory.create(metricsConfiguration())); Suppliers.memoize(
() -> {
return besuComponent == null
? MetricsSystemFactory.create(metricsConfiguration())
: besuComponent.getObservableMetricsSystem();
});
private Vertx vertx; private Vertx vertx;
private EnodeDnsConfiguration enodeDnsConfiguration; private EnodeDnsConfiguration enodeDnsConfiguration;
private KeyValueStorageProvider keyValueStorageProvider; private KeyValueStorageProvider keyValueStorageProvider;
@ -1334,7 +1342,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
/** /**
* Besu command constructor. * Besu command constructor.
* *
* @param logger Logger instance * @param besuComponent BesuComponent which acts as our application context
* @param rlpBlockImporter RlpBlockImporter supplier * @param rlpBlockImporter RlpBlockImporter supplier
* @param jsonBlockImporterFactory instance of {@code Function<BesuController, JsonBlockImporter>} * @param jsonBlockImporterFactory instance of {@code Function<BesuController, JsonBlockImporter>}
* @param rlpBlockExporterFactory instance of {@code Function<Blockchain, RlpBlockExporter>} * @param rlpBlockExporterFactory instance of {@code Function<Blockchain, RlpBlockExporter>}
@ -1344,7 +1352,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
* @param environment Environment variables map * @param environment Environment variables map
*/ */
public BesuCommand( public BesuCommand(
final Logger logger, final BesuComponent besuComponent,
final Supplier<RlpBlockImporter> rlpBlockImporter, final Supplier<RlpBlockImporter> rlpBlockImporter,
final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory, final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory,
final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory, final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory,
@ -1353,7 +1361,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
final BesuPluginContextImpl besuPluginContext, final BesuPluginContextImpl besuPluginContext,
final Map<String, String> environment) { final Map<String, String> environment) {
this( this(
logger, besuComponent,
rlpBlockImporter, rlpBlockImporter,
jsonBlockImporterFactory, jsonBlockImporterFactory,
rlpBlockExporterFactory, rlpBlockExporterFactory,
@ -1372,7 +1380,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
/** /**
* Overloaded Besu command constructor visible for testing. * Overloaded Besu command constructor visible for testing.
* *
* @param logger Logger instance * @param besuComponent BesuComponent which acts as our application context
* @param rlpBlockImporter RlpBlockImporter supplier * @param rlpBlockImporter RlpBlockImporter supplier
* @param jsonBlockImporterFactory instance of {@code Function<BesuController, JsonBlockImporter>} * @param jsonBlockImporterFactory instance of {@code Function<BesuController, JsonBlockImporter>}
* @param rlpBlockExporterFactory instance of {@code Function<Blockchain, RlpBlockExporter>} * @param rlpBlockExporterFactory instance of {@code Function<Blockchain, RlpBlockExporter>}
@ -1389,7 +1397,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
*/ */
@VisibleForTesting @VisibleForTesting
protected BesuCommand( protected BesuCommand(
final Logger logger, final BesuComponent besuComponent,
final Supplier<RlpBlockImporter> rlpBlockImporter, final Supplier<RlpBlockImporter> rlpBlockImporter,
final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory, final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory,
final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory, final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory,
@ -1403,7 +1411,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
final PrivacyPluginServiceImpl privacyPluginService, final PrivacyPluginServiceImpl privacyPluginService,
final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider, final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider,
final RpcEndpointServiceImpl rpcEndpointServiceImpl) { final RpcEndpointServiceImpl rpcEndpointServiceImpl) {
this.logger = logger; this.logger = besuComponent.getBesuCommandLogger();
this.rlpBlockImporter = rlpBlockImporter; this.rlpBlockImporter = rlpBlockImporter;
this.rlpBlockExporterFactory = rlpBlockExporterFactory; this.rlpBlockExporterFactory = rlpBlockExporterFactory;
this.jsonBlockImporterFactory = jsonBlockImporterFactory; this.jsonBlockImporterFactory = jsonBlockImporterFactory;
@ -1438,9 +1446,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
final InputStream in, final InputStream in,
final String... args) { final String... args) {
commandLine = toCommandLine();
new CommandLine(this, new BesuCommandCustomFactory(besuPluginContext))
.setCaseInsensitiveEnumValuesAllowed(true);
handleStableOptions(); handleStableOptions();
addSubCommands(in); addSubCommands(in);
@ -1454,6 +1460,13 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
return exitCode; return exitCode;
} }
/** Used by Dagger to parse all options into a commandline instance. */
public void toCommandLine() {
commandLine =
new CommandLine(this, new BesuCommandCustomFactory(besuPluginContext))
.setCaseInsensitiveEnumValuesAllowed(true);
}
@Override @Override
public void run() { public void run() {
if (network != null && network.isDeprecated()) { if (network != null && network.isDeprecated()) {
@ -2206,7 +2219,9 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
*/ */
public BesuController buildController() { public BesuController buildController() {
try { try {
return getControllerBuilder().build(); return this.besuComponent == null
? getControllerBuilder().build()
: getControllerBuilder().besuComponent(this.besuComponent).build();
} catch (final Exception e) { } catch (final Exception e) {
throw new ExecutionException(this.commandLine, e.getMessage(), e); throw new ExecutionException(this.commandLine, e.getMessage(), e);
} }

@ -0,0 +1,71 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.components;
import org.hyperledger.besu.Besu;
import org.hyperledger.besu.RunnerBuilder;
import org.hyperledger.besu.chainexport.RlpBlockExporter;
import org.hyperledger.besu.chainimport.JsonBlockImporter;
import org.hyperledger.besu.chainimport.RlpBlockImporter;
import org.hyperledger.besu.cli.BesuCommand;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.services.BesuPluginContextImpl;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import org.slf4j.Logger;
/**
* A dagger module that know how to create the BesuCommand, which collects all configuration
* settings.
*/
@Module
public class BesuCommandModule {
@Provides
@Singleton
BesuCommand provideBesuCommand(final BesuComponent besuComponent) {
final BesuCommand besuCommand =
new BesuCommand(
besuComponent,
RlpBlockImporter::new,
JsonBlockImporter::new,
RlpBlockExporter::new,
new RunnerBuilder(),
new BesuController.Builder(),
new BesuPluginContextImpl(),
System.getenv());
besuCommand.toCommandLine();
return besuCommand;
}
@Provides
@Singleton
MetricsConfiguration provideMetricsConfiguration(final BesuCommand provideFrom) {
return provideFrom.metricsConfiguration();
}
@Provides
@Named("besuCommandLogger")
@Singleton
Logger provideBesuCommandLogger() {
return Besu.getFirstLogger();
}
}

@ -0,0 +1,69 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.components;
import org.hyperledger.besu.cli.BesuCommand;
import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.bonsai.cache.CachedMerkleTrieLoaderModule;
import org.hyperledger.besu.metrics.MetricsSystemModule;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Component;
import org.slf4j.Logger;
/** An application context that knows how to provide dependencies based on Dagger setup. */
@Singleton
@Component(
modules = {
BesuCommandModule.class,
MetricsSystemModule.class,
CachedMerkleTrieLoaderModule.class
})
public interface BesuComponent {
/**
* the configured and parsed representation of the user issued command to run Besu
*
* @return BesuCommand
*/
BesuCommand getBesuCommand();
/**
* a cached trie node loader
*
* @return CachedMerkleTrieLoader
*/
CachedMerkleTrieLoader getCachedMerkleTrieLoader();
/**
* a metrics system that is observable by a Prometheus or OTEL metrics collection subsystem
*
* @return ObservableMetricsSystem
*/
ObservableMetricsSystem getObservableMetricsSystem();
/**
* a Logger specifically configured to provide configuration feedback to users.
*
* @return Logger
*/
@Named("besuCommandLogger")
Logger getBesuCommandLogger();
}

@ -16,6 +16,7 @@ package org.hyperledger.besu.controller;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import org.hyperledger.besu.components.BesuComponent;
import org.hyperledger.besu.config.CheckpointConfigOptions; import org.hyperledger.besu.config.CheckpointConfigOptions;
import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.GenesisConfigOptions;
@ -178,6 +179,19 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
private NetworkingConfiguration networkingConfiguration; private NetworkingConfiguration networkingConfiguration;
private Boolean randomPeerPriority; private Boolean randomPeerPriority;
/** the Dagger configured context that can provide dependencies */
protected BesuComponent besuComponent = null;
/**
* Provide a BesuComponent which can be used to get other dependencies
*
* @param besuComponent application context that can be used to get other dependencies
* @return the besu controller builder
*/
public BesuControllerBuilder besuComponent(final BesuComponent besuComponent) {
this.besuComponent = besuComponent;
return this;
}
/** /**
* Storage provider besu controller builder. * Storage provider besu controller builder.
@ -547,7 +561,10 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
reorgLoggingThreshold, reorgLoggingThreshold,
dataDirectory.toString()); dataDirectory.toString());
final CachedMerkleTrieLoader cachedMerkleTrieLoader = new CachedMerkleTrieLoader(metricsSystem); final CachedMerkleTrieLoader cachedMerkleTrieLoader =
besuComponent == null
? new CachedMerkleTrieLoader(metricsSystem)
: besuComponent.getCachedMerkleTrieLoader();
final WorldStateArchive worldStateArchive = final WorldStateArchive worldStateArchive =
createWorldStateArchive(worldStateStorage, blockchain, cachedMerkleTrieLoader); createWorldStateArchive(worldStateStorage, blockchain, cachedMerkleTrieLoader);

@ -37,6 +37,7 @@ import org.hyperledger.besu.cli.options.unstable.MetricsCLIOptions;
import org.hyperledger.besu.cli.options.unstable.NetworkingOptions; import org.hyperledger.besu.cli.options.unstable.NetworkingOptions;
import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions; import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions;
import org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions; import org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions;
import org.hyperledger.besu.components.BesuComponent;
import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfiguration; import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfiguration;
import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfigurationProvider; import org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfigurationProvider;
import org.hyperledger.besu.controller.BesuController; import org.hyperledger.besu.controller.BesuController;
@ -166,6 +167,8 @@ public abstract class CommandTestAbstract {
@Mock @Mock
protected Logger mockLogger; protected Logger mockLogger;
@Mock protected BesuComponent mockBesuComponent;
@Mock protected PkiBlockCreationConfigurationProvider mockPkiBlockCreationConfigProvider; @Mock protected PkiBlockCreationConfigurationProvider mockPkiBlockCreationConfigProvider;
@Mock protected PkiBlockCreationConfiguration mockPkiBlockCreationConfiguration; @Mock protected PkiBlockCreationConfiguration mockPkiBlockCreationConfiguration;
@ -318,6 +321,7 @@ public abstract class CommandTestAbstract {
.doReturn(mockPkiBlockCreationConfiguration) .doReturn(mockPkiBlockCreationConfiguration)
.when(mockPkiBlockCreationConfigProvider) .when(mockPkiBlockCreationConfigProvider)
.load(pkiKeyStoreConfigurationArgumentCaptor.capture()); .load(pkiKeyStoreConfigurationArgumentCaptor.capture());
when(mockBesuComponent.getBesuCommandLogger()).thenReturn(mockLogger);
} }
@Before @Before
@ -402,7 +406,7 @@ public abstract class CommandTestAbstract {
switch (testType) { switch (testType) {
case REQUIRED_OPTION: case REQUIRED_OPTION:
return new TestBesuCommandWithRequiredOption( return new TestBesuCommandWithRequiredOption(
mockLogger, mockBesuComponent,
() -> rlpBlockImporter, () -> rlpBlockImporter,
this::jsonBlockImporterFactory, this::jsonBlockImporterFactory,
(blockchain) -> rlpBlockExporter, (blockchain) -> rlpBlockExporter,
@ -416,7 +420,7 @@ public abstract class CommandTestAbstract {
privacyPluginService); privacyPluginService);
case PORT_CHECK: case PORT_CHECK:
return new TestBesuCommand( return new TestBesuCommand(
mockLogger, mockBesuComponent,
() -> rlpBlockImporter, () -> rlpBlockImporter,
this::jsonBlockImporterFactory, this::jsonBlockImporterFactory,
(blockchain) -> rlpBlockExporter, (blockchain) -> rlpBlockExporter,
@ -430,7 +434,7 @@ public abstract class CommandTestAbstract {
privacyPluginService); privacyPluginService);
default: default:
return new TestBesuCommandWithoutPortCheck( return new TestBesuCommandWithoutPortCheck(
mockLogger, mockBesuComponent,
() -> rlpBlockImporter, () -> rlpBlockImporter,
this::jsonBlockImporterFactory, this::jsonBlockImporterFactory,
(blockchain) -> rlpBlockExporter, (blockchain) -> rlpBlockExporter,
@ -452,7 +456,7 @@ public abstract class CommandTestAbstract {
private Vertx vertx; private Vertx vertx;
TestBesuCommand( TestBesuCommand(
final Logger mockLogger, final BesuComponent besuComponent,
final Supplier<RlpBlockImporter> mockBlockImporter, final Supplier<RlpBlockImporter> mockBlockImporter,
final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory, final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory,
final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory, final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory,
@ -465,7 +469,7 @@ public abstract class CommandTestAbstract {
final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider, final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider,
final PrivacyPluginServiceImpl privacyPluginService) { final PrivacyPluginServiceImpl privacyPluginService) {
super( super(
mockLogger, besuComponent,
mockBlockImporter, mockBlockImporter,
jsonBlockImporterFactory, jsonBlockImporterFactory,
rlpBlockExporterFactory, rlpBlockExporterFactory,
@ -536,7 +540,7 @@ public abstract class CommandTestAbstract {
private final Boolean acceptTermsAndConditions = false; private final Boolean acceptTermsAndConditions = false;
TestBesuCommandWithRequiredOption( TestBesuCommandWithRequiredOption(
final Logger mockLogger, final BesuComponent besuComponent,
final Supplier<RlpBlockImporter> mockBlockImporter, final Supplier<RlpBlockImporter> mockBlockImporter,
final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory, final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory,
final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory, final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory,
@ -549,7 +553,7 @@ public abstract class CommandTestAbstract {
final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider, final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider,
final PrivacyPluginServiceImpl privacyPluginService) { final PrivacyPluginServiceImpl privacyPluginService) {
super( super(
mockLogger, besuComponent,
mockBlockImporter, mockBlockImporter,
jsonBlockImporterFactory, jsonBlockImporterFactory,
rlpBlockExporterFactory, rlpBlockExporterFactory,
@ -572,7 +576,7 @@ public abstract class CommandTestAbstract {
public static class TestBesuCommandWithoutPortCheck extends TestBesuCommand { public static class TestBesuCommandWithoutPortCheck extends TestBesuCommand {
TestBesuCommandWithoutPortCheck( TestBesuCommandWithoutPortCheck(
final Logger mockLogger, final BesuComponent context,
final Supplier<RlpBlockImporter> mockBlockImporter, final Supplier<RlpBlockImporter> mockBlockImporter,
final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory, final Function<BesuController, JsonBlockImporter> jsonBlockImporterFactory,
final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory, final Function<Blockchain, RlpBlockExporter> rlpBlockExporterFactory,
@ -585,7 +589,7 @@ public abstract class CommandTestAbstract {
final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider, final PkiBlockCreationConfigurationProvider pkiBlockCreationConfigProvider,
final PrivacyPluginServiceImpl privacyPluginService) { final PrivacyPluginServiceImpl privacyPluginService) {
super( super(
mockLogger, context,
mockBlockImporter, mockBlockImporter,
jsonBlockImporterFactory, jsonBlockImporterFactory,
rlpBlockExporterFactory, rlpBlockExporterFactory,

@ -46,6 +46,8 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava' implementation 'com.google.guava:guava'
implementation 'com.google.dagger:dagger'
annotationProcessor 'com.google.dagger:dagger-compiler'
implementation 'io.opentelemetry:opentelemetry-api' implementation 'io.opentelemetry:opentelemetry-api'
implementation 'io.vertx:vertx-core' implementation 'io.vertx:vertx-core'
implementation 'net.java.dev.jna:jna' implementation 'net.java.dev.jna:jna'

@ -0,0 +1,31 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.bonsai.cache;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import dagger.Module;
import dagger.Provides;
@Module
public class CachedMerkleTrieLoaderModule {
@Provides
CachedMerkleTrieLoader provideCachedMerkleTrieLoaderModule(
final ObservableMetricsSystem metricsSystem) {
return new CachedMerkleTrieLoader(metricsSystem);
}
}

@ -41,6 +41,7 @@ import org.hyperledger.besu.evm.tracing.OperationTracer;
import org.hyperledger.besu.evm.tracing.StandardJsonTracer; import org.hyperledger.besu.evm.tracing.StandardJsonTracer;
import org.hyperledger.besu.evm.worldstate.WorldState; import org.hyperledger.besu.evm.worldstate.WorldState;
import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.metrics.MetricsSystemModule;
import org.hyperledger.besu.util.LogConfigurator; import org.hyperledger.besu.util.LogConfigurator;
import java.io.BufferedWriter; import java.io.BufferedWriter;

@ -1,5 +1,5 @@
/* /*
* Copyright ConsenSys AG. * Copyright Hyperledger Besu Contributors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
@ -20,6 +20,8 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.metrics.MetricsConfigurationModule;
import org.hyperledger.besu.metrics.MetricsSystemModule;
import java.util.function.Function; import java.util.function.Function;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -34,6 +36,7 @@ import dagger.Component;
DataStoreModule.class, DataStoreModule.class,
BlockchainModule.class, BlockchainModule.class,
EvmToolCommandOptionsModule.class, EvmToolCommandOptionsModule.class,
MetricsConfigurationModule.class,
MetricsSystemModule.class, MetricsSystemModule.class,
}) })
public interface EvmToolComponent { public interface EvmToolComponent {

@ -39,6 +39,8 @@ dependencies {
api 'org.slf4j:slf4j-api' api 'org.slf4j:slf4j-api'
implementation 'com.google.guava:guava' implementation 'com.google.guava:guava'
implementation 'com.google.dagger:dagger'
implementation 'info.picocli:picocli'
implementation 'io.grpc:grpc-netty' implementation 'io.grpc:grpc-netty'
implementation 'io.grpc:grpc-core' implementation 'io.grpc:grpc-core'
implementation 'io.netty:netty-tcnative-boringssl-static' implementation 'io.netty:netty-tcnative-boringssl-static'
@ -71,6 +73,8 @@ dependencies {
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
testSupportImplementation 'org.mockito:mockito-core' testSupportImplementation 'org.mockito:mockito-core'
annotationProcessor 'com.google.dagger:dagger-compiler'
} }

@ -1,5 +1,5 @@
/* /*
* Copyright ConsenSys AG. * Copyright Hyperledger Besu Contributors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
@ -11,27 +11,23 @@
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*
*/ */
package org.hyperledger.besu.evmtool; package org.hyperledger.besu.metrics;
import org.hyperledger.besu.metrics.MetricsSystemFactory;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
@SuppressWarnings("WeakerAccess") /** Dagger module for providing the {@link MetricsConfiguration} instance. */
@Module @Module
public class MetricsSystemModule { public class MetricsConfigurationModule {
@Provides @Provides
@Singleton @Singleton
MetricsSystem getMetricsSystem() { MetricsConfiguration provideMetricsConfiguration() {
return MetricsSystemFactory.create(MetricsConfiguration.builder().build()); return MetricsConfiguration.builder().build();
} }
} }

@ -0,0 +1,45 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu.metrics;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for providing the {@link MetricsSystem} and {@link ObservableMetricsSystem}
* instances.
*/
@Module
public class MetricsSystemModule {
@Provides
@Singleton
MetricsSystem provideMetricsSystem(final MetricsConfiguration metricsConfig) {
return MetricsSystemFactory.create(metricsConfig);
}
@Provides
@Singleton
ObservableMetricsSystem provideObservableMetricsSystem(final MetricsConfiguration metricsConfig) {
return MetricsSystemFactory.create(metricsConfig);
}
}

@ -1,5 +1,5 @@
/* /*
* Copyright ConsenSys AG. * Copyright Hyperledger Besu Contributors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at

Loading…
Cancel
Save