use of org.hyperledger.besu.metrics.ObservableMetricsSystem in project besu by hyperledger.
the class BesuCommand method synchronize.
// Blockchain synchronization from peers.
private Runner synchronize(final BesuController controller, final boolean p2pEnabled, final Optional<TLSConfiguration> p2pTLSConfiguration, final boolean peerDiscoveryEnabled, final EthNetworkConfig ethNetworkConfig, final int maxPeers, final String p2pAdvertisedHost, final String p2pListenInterface, final int p2pListenPort, final GraphQLConfiguration graphQLConfiguration, final JsonRpcConfiguration jsonRpcConfiguration, final JsonRpcConfiguration engineJsonRpcConfiguration, final WebSocketConfiguration webSocketConfiguration, final WebSocketConfiguration engineWebSocketConfiguration, final ApiConfiguration apiConfiguration, final MetricsConfiguration metricsConfiguration, final Optional<PermissioningConfiguration> permissioningConfiguration, final Collection<EnodeURL> staticNodes, final Path pidPath) {
checkNotNull(runnerBuilder);
p2pTLSConfiguration.ifPresent(runnerBuilder::p2pTLSConfiguration);
final ObservableMetricsSystem metricsSystem = this.metricsSystem.get();
final Runner runner = runnerBuilder.vertx(vertx).besuController(controller).p2pEnabled(p2pEnabled).natMethod(natMethod).natManagerServiceName(unstableNatOptions.getNatManagerServiceName()).natMethodFallbackEnabled(unstableNatOptions.getNatMethodFallbackEnabled()).discovery(peerDiscoveryEnabled).ethNetworkConfig(ethNetworkConfig).permissioningConfiguration(permissioningConfiguration).p2pAdvertisedHost(p2pAdvertisedHost).p2pListenInterface(p2pListenInterface).p2pListenPort(p2pListenPort).maxPeers(maxPeers).limitRemoteWireConnectionsEnabled(isLimitRemoteWireConnectionsEnabled).fractionRemoteConnectionsAllowed(Fraction.fromPercentage(maxRemoteConnectionsPercentage).getValue()).randomPeerPriority(randomPeerPriority).networkingConfiguration(unstableNetworkingOptions.toDomainObject()).graphQLConfiguration(graphQLConfiguration).jsonRpcConfiguration(jsonRpcConfiguration).engineJsonRpcConfiguration(engineJsonRpcConfiguration).webSocketConfiguration(webSocketConfiguration).engineWebSocketConfiguration(engineWebSocketConfiguration).apiConfiguration(apiConfiguration).pidPath(pidPath).dataDir(dataDir()).bannedNodeIds(bannedNodeIds).metricsSystem(metricsSystem).permissioningService(permissioningService).metricsConfiguration(metricsConfiguration).staticNodes(staticNodes).identityString(identityString).besuPluginContext(besuPluginContext).autoLogBloomCaching(autoLogBloomCachingEnabled).ethstatsUrl(ethstatsOptions.getEthstatsUrl()).ethstatsContact(ethstatsOptions.getEthstatsContact()).storageProvider(keyValueStorageProvider(keyValueStorageName)).forkIdSupplier(() -> besuController.getProtocolManager().getForkIdAsBytesList()).rpcEndpointService(rpcEndpointServiceImpl).build();
addShutdownHook(runner);
return runner;
}
use of org.hyperledger.besu.metrics.ObservableMetricsSystem in project teku by ConsenSys.
the class RocksDbStatsTest method shouldNotCrashIfMetricsRequestedAfterClose.
@Test
void shouldNotCrashIfMetricsRequestedAfterClose() throws Exception {
final ObservableMetricsSystem metricsSystem = new PrometheusMetricsSystem(Set.of(TekuMetricCategory.STORAGE_HOT_DB), true);
try (RocksDbStats stats = new RocksDbStats(metricsSystem, TekuMetricCategory.STORAGE_HOT_DB)) {
stats.registerMetrics(database);
}
when(database.getLongProperty(any())).thenThrow(new IllegalStateException("Database shutdown"));
final List<Observation> metrics = metricsSystem.streamObservations().collect(Collectors.toList());
assertThat(metrics).isNotEmpty();
}
use of org.hyperledger.besu.metrics.ObservableMetricsSystem in project besu by hyperledger.
the class ThreadBesuNodeRunner method startNode.
@Override
public void startNode(final BesuNode node) {
if (MDC.get("node") != null) {
LOG.error("ThreadContext node is already set to {}", MDC.get("node"));
}
MDC.put("node", node.getName());
if (!node.getRunCommand().isEmpty()) {
throw new UnsupportedOperationException("commands are not supported with thread runner");
}
final StorageServiceImpl storageService = new StorageServiceImpl();
final SecurityModuleServiceImpl securityModuleService = new SecurityModuleServiceImpl();
final Path dataDir = node.homeDirectory();
final BesuConfiguration commonPluginConfiguration = new BesuConfigurationImpl(dataDir, dataDir.resolve(DATABASE_PATH));
final BesuPluginContextImpl besuPluginContext = besuPluginContextMap.computeIfAbsent(node, n -> buildPluginContext(node, storageService, securityModuleService, commonPluginConfiguration));
final ObservableMetricsSystem metricsSystem = MetricsSystemFactory.create(node.getMetricsConfiguration());
final List<EnodeURL> bootnodes = node.getConfiguration().getBootnodes().stream().map(EnodeURLImpl::fromURI).collect(Collectors.toList());
final NetworkName network = node.getNetwork() == null ? NetworkName.DEV : node.getNetwork();
final EthNetworkConfig.Builder networkConfigBuilder = new EthNetworkConfig.Builder(EthNetworkConfig.getNetworkConfig(network)).setBootNodes(bootnodes);
node.getConfiguration().getGenesisConfig().ifPresent(networkConfigBuilder::setGenesisConfig);
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder.build();
final BesuControllerBuilder builder = new BesuController.Builder().fromEthNetworkConfig(ethNetworkConfig);
final KeyValueStorageProvider storageProvider = new KeyValueStorageProviderBuilder().withStorageFactory(storageService.getByName("rocksdb").get()).withCommonConfiguration(commonPluginConfiguration).withMetricsSystem(metricsSystem).build();
final TransactionPoolConfiguration txPoolConfig = ImmutableTransactionPoolConfiguration.builder().strictTransactionReplayProtectionEnabled(node.isStrictTxReplayProtectionEnabled()).build();
final int maxPeers = 25;
builder.synchronizerConfiguration(new SynchronizerConfiguration.Builder().build()).dataDirectory(node.homeDirectory()).miningParameters(node.getMiningParameters()).privacyParameters(node.getPrivacyParameters()).nodeKey(new NodeKey(new KeyPairSecurityModule(KeyPairUtil.loadKeyPair(dataDir)))).metricsSystem(metricsSystem).transactionPoolConfiguration(txPoolConfig).ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()).clock(Clock.systemUTC()).isRevertReasonEnabled(node.isRevertReasonEnabled()).storageProvider(storageProvider).gasLimitCalculator(GasLimitCalculator.constant()).pkiBlockCreationConfiguration(node.getPkiKeyStoreConfiguration().map(pkiConfig -> new PkiBlockCreationConfigurationProvider().load(pkiConfig))).evmConfiguration(EvmConfiguration.DEFAULT).maxPeers(maxPeers);
node.getGenesisConfig().map(GenesisConfigFile::fromConfig).ifPresent(builder::genesisConfigFile);
final BesuController besuController = builder.build();
final RunnerBuilder runnerBuilder = new RunnerBuilder();
runnerBuilder.permissioningConfiguration(node.getPermissioningConfiguration());
final Runner runner = runnerBuilder.vertx(Vertx.vertx()).besuController(besuController).ethNetworkConfig(ethNetworkConfig).discovery(node.isDiscoveryEnabled()).p2pAdvertisedHost(node.getHostName()).p2pListenPort(0).maxPeers(maxPeers).networkingConfiguration(node.getNetworkingConfiguration()).jsonRpcConfiguration(node.jsonRpcConfiguration()).webSocketConfiguration(node.webSocketConfiguration()).jsonRpcIpcConfiguration(node.jsonRpcIpcConfiguration()).dataDir(node.homeDirectory()).metricsSystem(metricsSystem).permissioningService(new PermissioningServiceImpl()).metricsConfiguration(node.getMetricsConfiguration()).p2pEnabled(node.isP2pEnabled()).p2pTLSConfiguration(node.getTLSConfiguration()).graphQLConfiguration(GraphQLConfiguration.createDefault()).staticNodes(node.getStaticNodes().stream().map(EnodeURLImpl::fromString).collect(Collectors.toList())).besuPluginContext(new BesuPluginContextImpl()).autoLogBloomCaching(false).storageProvider(storageProvider).forkIdSupplier(() -> besuController.getProtocolManager().getForkIdAsBytesList()).rpcEndpointService(new RpcEndpointServiceImpl()).build();
besuPluginContext.beforeExternalServices();
runner.startExternalServices();
besuPluginContext.addService(BesuEvents.class, new BesuEventsImpl(besuController.getProtocolContext().getBlockchain(), besuController.getProtocolManager().getBlockBroadcaster(), besuController.getTransactionPool(), besuController.getSyncState()));
besuPluginContext.startPlugins();
runner.startEthereumMainLoop();
besuRunners.put(node.getName(), runner);
MDC.remove("node");
}
use of org.hyperledger.besu.metrics.ObservableMetricsSystem in project besu by hyperledger.
the class JsonRpcTestMethodsFactory method methods.
public Map<String, JsonRpcMethod> methods() {
final P2PNetwork peerDiscovery = mock(P2PNetwork.class);
final EthPeers ethPeers = mock(EthPeers.class);
final TransactionPool transactionPool = mock(TransactionPool.class);
final PoWMiningCoordinator miningCoordinator = mock(PoWMiningCoordinator.class);
final ObservableMetricsSystem metricsSystem = new NoOpMetricsSystem();
final Optional<AccountLocalConfigPermissioningController> accountWhitelistController = Optional.of(mock(AccountLocalConfigPermissioningController.class));
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController = Optional.of(mock(NodeLocalConfigPermissioningController.class));
final PrivacyParameters privacyParameters = mock(PrivacyParameters.class);
final FilterManager filterManager = new FilterManagerBuilder().blockchainQueries(blockchainQueries).transactionPool(transactionPool).privacyParameters(privacyParameters).build();
final JsonRpcConfiguration jsonRpcConfiguration = mock(JsonRpcConfiguration.class);
final WebSocketConfiguration webSocketConfiguration = mock(WebSocketConfiguration.class);
final MetricsConfiguration metricsConfiguration = mock(MetricsConfiguration.class);
final NatService natService = new NatService(Optional.empty());
final List<String> apis = new ArrayList<>();
apis.add(RpcApis.ETH.name());
apis.add(RpcApis.NET.name());
apis.add(RpcApis.WEB3.name());
apis.add(RpcApis.PRIV.name());
apis.add(RpcApis.DEBUG.name());
final Path dataDir = mock(Path.class);
return new JsonRpcMethodsFactory().methods(CLIENT_VERSION, NETWORK_ID, new StubGenesisConfigOptions(), peerDiscovery, blockchainQueries, synchronizer, importer.getProtocolSchedule(), context, filterManager, transactionPool, miningCoordinator, metricsSystem, new HashSet<>(), accountWhitelistController, nodeWhitelistController, apis, privacyParameters, jsonRpcConfiguration, webSocketConfiguration, metricsConfiguration, natService, new HashMap<>(), dataDir, ethPeers);
}
use of org.hyperledger.besu.metrics.ObservableMetricsSystem in project besu by hyperledger.
the class OpenTelemetryMetricsSystemTest method shouldCreateObservationFromGauge.
@Test
public void shouldCreateObservationFromGauge() {
final MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().metricCategories(ImmutableSet.of(BesuMetricCategory.RPC)).enabled(true).protocol(OPENTELEMETRY).build();
final ObservableMetricsSystem localMetricSystem = MetricsSystemFactory.create(metricsConfiguration);
localMetricSystem.createGauge(RPC, "myValue", "Help", () -> 7.0);
assertThat(localMetricSystem.streamObservations()).containsExactlyInAnyOrder(new Observation(RPC, "myValue", 7.0, emptyList()));
}
Aggregations