mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-08 21:38:15 -05:00
Repackage options (#7688)
Updates MetricsOptions to implement CLIOptions, and to contain its unstable options. --------- Signed-off-by: Justin Florentine <justin+github@florentine.us>
This commit is contained in:
committed by
GitHub
parent
49c6cbd1c3
commit
911f12efa0
@@ -18,7 +18,7 @@ import static java.util.Collections.unmodifiableList;
|
||||
import static org.apache.tuweni.io.file.Files.copyResource;
|
||||
|
||||
import org.hyperledger.besu.cli.config.NetworkName;
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.crypto.KeyPair;
|
||||
import org.hyperledger.besu.crypto.KeyPairUtil;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
@@ -228,7 +228,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
|
||||
});
|
||||
this.requestedPlugins = requestedPlugins;
|
||||
engineRpcConfiguration.ifPresent(
|
||||
config -> MergeConfigOptions.setMergeEnabled(config.isEnabled()));
|
||||
config -> MergeConfiguration.setMergeEnabled(config.isEnabled()));
|
||||
this.extraCLIOptions = extraCLIOptions;
|
||||
this.staticNodes = staticNodes;
|
||||
this.isDnsEnabled = isDnsEnabled;
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.hyperledger.besu.cli.options.stable.EthstatsOptions;
|
||||
import org.hyperledger.besu.cli.options.stable.GraphQlOptions;
|
||||
import org.hyperledger.besu.cli.options.stable.JsonRpcHttpOptions;
|
||||
import org.hyperledger.besu.cli.options.stable.LoggingLevelOption;
|
||||
import org.hyperledger.besu.cli.options.stable.MetricsOptionGroup;
|
||||
import org.hyperledger.besu.cli.options.stable.MetricsOptions;
|
||||
import org.hyperledger.besu.cli.options.stable.NodePrivateKeyFileOption;
|
||||
import org.hyperledger.besu.cli.options.stable.P2PDiscoveryOptions;
|
||||
import org.hyperledger.besu.cli.options.stable.PermissionsOptions;
|
||||
@@ -62,7 +62,6 @@ import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.EvmOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.InProcessRpcOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.IpcOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.MetricsCLIOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.NatOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.NativeLibraryOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.NetworkingOptions;
|
||||
@@ -89,7 +88,7 @@ import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.CheckpointConfigOptions;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.config.GenesisConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
import org.hyperledger.besu.controller.BesuControllerBuilder;
|
||||
import org.hyperledger.besu.crypto.Blake2bfMessageDigest;
|
||||
@@ -246,7 +245,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.VertxOptions;
|
||||
import io.vertx.core.json.DecodeException;
|
||||
import io.vertx.core.metrics.MetricsOptions;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.slf4j.Logger;
|
||||
@@ -295,7 +293,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
final NetworkingOptions unstableNetworkingOptions = NetworkingOptions.create();
|
||||
final SynchronizerOptions unstableSynchronizerOptions = SynchronizerOptions.create();
|
||||
final EthProtocolOptions unstableEthProtocolOptions = EthProtocolOptions.create();
|
||||
final MetricsCLIOptions unstableMetricsCLIOptions = MetricsCLIOptions.create();
|
||||
private final DnsOptions unstableDnsOptions = DnsOptions.create();
|
||||
private final NatOptions unstableNatOptions = NatOptions.create();
|
||||
private final NativeLibraryOptions unstableNativeLibraryOptions = NativeLibraryOptions.create();
|
||||
@@ -584,7 +581,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
|
||||
// Metrics Option Group
|
||||
@CommandLine.ArgGroup(validate = false, heading = "@|bold Metrics Options|@%n")
|
||||
MetricsOptionGroup metricsOptionGroup = new MetricsOptionGroup();
|
||||
MetricsOptions metricsOptions = MetricsOptions.create();
|
||||
|
||||
@Option(
|
||||
names = {"--host-allowlist"},
|
||||
@@ -1153,7 +1150,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
final ImmutableMap<String, Object> unstableOptions =
|
||||
unstableOptionsBuild
|
||||
.put("Ethereum Wire Protocol", unstableEthProtocolOptions)
|
||||
.put("Metrics", unstableMetricsCLIOptions)
|
||||
.put("P2P Network", unstableNetworkingOptions)
|
||||
.put("RPC", unstableRPCOptions)
|
||||
.put("DNS Configuration", unstableDnsOptions)
|
||||
@@ -1864,7 +1860,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
* @return instance of MetricsConfiguration.
|
||||
*/
|
||||
public MetricsConfiguration metricsConfiguration() {
|
||||
if (metricsOptionGroup.getMetricsEnabled() && metricsOptionGroup.getMetricsPushEnabled()) {
|
||||
if (metricsOptions.getMetricsEnabled() && metricsOptions.getMetricsPushEnabled()) {
|
||||
throw new ParameterException(
|
||||
this.commandLine,
|
||||
"--metrics-enabled option and --metrics-push-enabled option can't be used at the same "
|
||||
@@ -1875,40 +1871,33 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
logger,
|
||||
commandLine,
|
||||
"--metrics-enabled",
|
||||
!metricsOptionGroup.getMetricsEnabled(),
|
||||
!metricsOptions.getMetricsEnabled(),
|
||||
asList("--metrics-host", "--metrics-port"));
|
||||
|
||||
CommandLineUtils.checkOptionDependencies(
|
||||
logger,
|
||||
commandLine,
|
||||
"--metrics-push-enabled",
|
||||
!metricsOptionGroup.getMetricsPushEnabled(),
|
||||
!metricsOptions.getMetricsPushEnabled(),
|
||||
asList(
|
||||
"--metrics-push-host",
|
||||
"--metrics-push-port",
|
||||
"--metrics-push-interval",
|
||||
"--metrics-push-prometheus-job"));
|
||||
|
||||
return unstableMetricsCLIOptions
|
||||
.toDomainObject()
|
||||
.enabled(metricsOptionGroup.getMetricsEnabled())
|
||||
final MetricsConfiguration.Builder metricsConfigurationBuilder =
|
||||
metricsOptions.toDomainObject();
|
||||
metricsConfigurationBuilder
|
||||
.host(
|
||||
Strings.isNullOrEmpty(metricsOptionGroup.getMetricsHost())
|
||||
Strings.isNullOrEmpty(metricsOptions.getMetricsHost())
|
||||
? p2PDiscoveryOptions.p2pHost
|
||||
: metricsOptionGroup.getMetricsHost())
|
||||
.port(metricsOptionGroup.getMetricsPort())
|
||||
.protocol(metricsOptionGroup.getMetricsProtocol())
|
||||
.metricCategories(metricsOptionGroup.getMetricCategories())
|
||||
.pushEnabled(metricsOptionGroup.getMetricsPushEnabled())
|
||||
: metricsOptions.getMetricsHost())
|
||||
.pushHost(
|
||||
Strings.isNullOrEmpty(metricsOptionGroup.getMetricsPushHost())
|
||||
Strings.isNullOrEmpty(metricsOptions.getMetricsPushHost())
|
||||
? p2PDiscoveryOptions.autoDiscoverDefaultIP().getHostAddress()
|
||||
: metricsOptionGroup.getMetricsPushHost())
|
||||
.pushPort(metricsOptionGroup.getMetricsPushPort())
|
||||
.pushInterval(metricsOptionGroup.getMetricsPushInterval())
|
||||
.hostsAllowlist(hostsAllowlist)
|
||||
.prometheusJob(metricsOptionGroup.getMetricsPrometheusJob())
|
||||
.build();
|
||||
: metricsOptions.getMetricsPushHost())
|
||||
.hostsAllowlist(hostsAllowlist);
|
||||
return metricsConfigurationBuilder.build();
|
||||
}
|
||||
|
||||
private PrivacyParameters privacyParameters() {
|
||||
@@ -2281,7 +2270,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
return new VertxOptions()
|
||||
.setPreferNativeTransport(true)
|
||||
.setMetricsOptions(
|
||||
new MetricsOptions()
|
||||
new io.vertx.core.metrics.MetricsOptions()
|
||||
.setEnabled(true)
|
||||
.setFactory(new VertxMetricsAdapterFactory(metricsSystem)));
|
||||
}
|
||||
@@ -2537,9 +2526,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
effectivePorts, rpcWebsocketOptions.getRpcWsPort(), rpcWebsocketOptions.isRpcWsEnabled());
|
||||
addPortIfEnabled(effectivePorts, engineRPCConfig.engineRpcPort(), isEngineApiEnabled());
|
||||
addPortIfEnabled(
|
||||
effectivePorts,
|
||||
metricsOptionGroup.getMetricsPort(),
|
||||
metricsOptionGroup.getMetricsEnabled());
|
||||
effectivePorts, metricsOptions.getMetricsPort(), metricsOptions.getMetricsEnabled());
|
||||
addPortIfEnabled(
|
||||
effectivePorts,
|
||||
miningParametersSupplier.get().getStratumPort(),
|
||||
@@ -2613,7 +2600,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
}
|
||||
|
||||
private void setMergeConfigOptions() {
|
||||
MergeConfigOptions.setMergeEnabled(
|
||||
MergeConfiguration.setMergeEnabled(
|
||||
genesisConfigOptionsSupplier.get().getTerminalTotalDifficulty().isPresent());
|
||||
}
|
||||
|
||||
@@ -2658,7 +2645,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
}
|
||||
|
||||
private boolean isMergeEnabled() {
|
||||
return MergeConfigOptions.isMergeEnabled();
|
||||
return MergeConfiguration.isMergeEnabled();
|
||||
}
|
||||
|
||||
private boolean isEngineApiEnabled() {
|
||||
@@ -2752,11 +2739,20 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plugin context.
|
||||
* 2 Returns the plugin context.
|
||||
*
|
||||
* @return the plugin context.
|
||||
*/
|
||||
public BesuPluginContextImpl getBesuPluginContext() {
|
||||
return besuPluginContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metrics options
|
||||
*
|
||||
* @return the metrics options
|
||||
*/
|
||||
public MetricsOptions getMetricsOptions() {
|
||||
return metricsOptions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,20 +22,80 @@ import static org.hyperledger.besu.metrics.MetricsProtocol.PROMETHEUS;
|
||||
import static org.hyperledger.besu.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT;
|
||||
import static org.hyperledger.besu.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT;
|
||||
|
||||
import org.hyperledger.besu.cli.options.CLIOptions;
|
||||
import org.hyperledger.besu.cli.util.CommandLineUtils;
|
||||
import org.hyperledger.besu.metrics.MetricsProtocol;
|
||||
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
|
||||
import org.hyperledger.besu.plugin.services.metrics.MetricCategory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
/** Command line options for configuring metrics. */
|
||||
// TODO: implement CLIOption<MetricsConfiguration> and rename to drop the Group
|
||||
public class MetricsOptionGroup {
|
||||
// TODO: implement CLIOption<MetricsConfiguration>
|
||||
public class MetricsOptions implements CLIOptions<MetricsConfiguration.Builder> {
|
||||
|
||||
/**
|
||||
* Returns a MetricsConfiguration.Builder because fields are often overridden from other domains,
|
||||
* like using P2P settings as defaults.
|
||||
*
|
||||
* @return a newly created {@link MetricsOptions} with default values
|
||||
*/
|
||||
@Override
|
||||
public MetricsConfiguration.Builder toDomainObject() {
|
||||
MetricsConfiguration.Builder builder = MetricsConfiguration.builder();
|
||||
builder
|
||||
.timersEnabled(unstableOptions.timersEnabled)
|
||||
.idleTimeout(unstableOptions.idleTimeout)
|
||||
.enabled(getMetricsEnabled())
|
||||
.host(getMetricsHost())
|
||||
.port(getMetricsPort())
|
||||
.protocol(getMetricsProtocol())
|
||||
.metricCategories(getMetricCategories())
|
||||
.pushEnabled(getMetricsPushEnabled())
|
||||
.pushHost(getMetricsPushHost())
|
||||
.pushPort(getMetricsPushPort())
|
||||
.pushInterval(getMetricsPushInterval())
|
||||
.prometheusJob(getMetricsPrometheusJob());
|
||||
return builder;
|
||||
}
|
||||
|
||||
// TODO: why do we need to be able to reverse this?
|
||||
/**
|
||||
* Returns a newly created {@link MetricsOptions} reversed from the supplied MetricsConfiguration
|
||||
*
|
||||
* @param config the metrics configuration
|
||||
* @return a newly created {@link MetricsOptions} reversed from the supplied MetricsConfiguration
|
||||
*/
|
||||
public static MetricsOptions fromConfiguration(final MetricsConfiguration config) {
|
||||
final MetricsOptions metricsOptions = create();
|
||||
metricsOptions.unstableOptions.timersEnabled = config.isTimersEnabled();
|
||||
metricsOptions.unstableOptions.idleTimeout = config.getIdleTimeout();
|
||||
metricsOptions.isMetricsEnabled = config.isEnabled();
|
||||
metricsOptions.metricsHost = config.getHost();
|
||||
metricsOptions.metricsPort = config.getPort();
|
||||
metricsOptions.metricsProtocol = config.getProtocol();
|
||||
metricsOptions.metricCategories = config.getMetricCategories();
|
||||
metricsOptions.metricsPrometheusJob = config.getPrometheusJob();
|
||||
metricsOptions.isMetricsPushEnabled = config.isPushEnabled();
|
||||
metricsOptions.metricsPushHost = config.getPushHost();
|
||||
metricsOptions.metricsPushPort = config.getPushPort();
|
||||
metricsOptions.metricsPushInterval = config.getPushInterval();
|
||||
|
||||
return metricsOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCLIOptions() {
|
||||
return CommandLineUtils.getCLIOptions(this, new MetricsOptions());
|
||||
}
|
||||
|
||||
@CommandLine.Option(
|
||||
names = {"--metrics-enabled"},
|
||||
description = "Set to start the metrics exporter (default: ${DEFAULT-VALUE})")
|
||||
private final Boolean isMetricsEnabled = false;
|
||||
private Boolean isMetricsEnabled = false;
|
||||
|
||||
@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
|
||||
@CommandLine.Option(
|
||||
@@ -50,14 +110,14 @@ public class MetricsOptionGroup {
|
||||
paramLabel = MANDATORY_HOST_FORMAT_HELP,
|
||||
description = "Host for the metrics exporter to listen on (default: ${DEFAULT-VALUE})",
|
||||
arity = "1")
|
||||
private String metricsHost;
|
||||
private String metricsHost = MetricsConfiguration.DEFAULT_METRICS_HOST;
|
||||
|
||||
@CommandLine.Option(
|
||||
names = {"--metrics-port"},
|
||||
paramLabel = MANDATORY_PORT_FORMAT_HELP,
|
||||
description = "Port for the metrics exporter to listen on (default: ${DEFAULT-VALUE})",
|
||||
arity = "1")
|
||||
private final Integer metricsPort = DEFAULT_METRICS_PORT;
|
||||
private Integer metricsPort = DEFAULT_METRICS_PORT;
|
||||
|
||||
@CommandLine.Option(
|
||||
names = {"--metrics-category", "--metrics-categories"},
|
||||
@@ -66,12 +126,12 @@ public class MetricsOptionGroup {
|
||||
arity = "1..*",
|
||||
description =
|
||||
"Comma separated list of categories to track metrics for (default: ${DEFAULT-VALUE})")
|
||||
private final Set<MetricCategory> metricCategories = DEFAULT_METRIC_CATEGORIES;
|
||||
private Set<MetricCategory> metricCategories = DEFAULT_METRIC_CATEGORIES;
|
||||
|
||||
@CommandLine.Option(
|
||||
names = {"--metrics-push-enabled"},
|
||||
description = "Enable the metrics push gateway integration (default: ${DEFAULT-VALUE})")
|
||||
private final Boolean isMetricsPushEnabled = false;
|
||||
private Boolean isMetricsPushEnabled = false;
|
||||
|
||||
@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
|
||||
@CommandLine.Option(
|
||||
@@ -79,14 +139,14 @@ public class MetricsOptionGroup {
|
||||
paramLabel = MANDATORY_HOST_FORMAT_HELP,
|
||||
description = "Host of the Prometheus Push Gateway for push mode (default: ${DEFAULT-VALUE})",
|
||||
arity = "1")
|
||||
private String metricsPushHost;
|
||||
private String metricsPushHost = MetricsConfiguration.DEFAULT_METRICS_PUSH_HOST;
|
||||
|
||||
@CommandLine.Option(
|
||||
names = {"--metrics-push-port"},
|
||||
paramLabel = MANDATORY_PORT_FORMAT_HELP,
|
||||
description = "Port of the Prometheus Push Gateway for push mode (default: ${DEFAULT-VALUE})",
|
||||
arity = "1")
|
||||
private final Integer metricsPushPort = DEFAULT_METRICS_PUSH_PORT;
|
||||
private Integer metricsPushPort = DEFAULT_METRICS_PUSH_PORT;
|
||||
|
||||
@CommandLine.Option(
|
||||
names = {"--metrics-push-interval"},
|
||||
@@ -94,7 +154,7 @@ public class MetricsOptionGroup {
|
||||
description =
|
||||
"Interval in seconds to push metrics when in push mode (default: ${DEFAULT-VALUE})",
|
||||
arity = "1")
|
||||
private final Integer metricsPushInterval = 15;
|
||||
private Integer metricsPushInterval = 15;
|
||||
|
||||
@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
|
||||
@CommandLine.Option(
|
||||
@@ -103,8 +163,16 @@ public class MetricsOptionGroup {
|
||||
arity = "1")
|
||||
private String metricsPrometheusJob = "besu-client";
|
||||
|
||||
/** Returns a newly created {@link MetricsOptionGroup} with default values. */
|
||||
public MetricsOptionGroup() {}
|
||||
/**
|
||||
* Returns a newly created {@link MetricsOptions} with default values.
|
||||
*
|
||||
* @return new instance
|
||||
*/
|
||||
public static MetricsOptions create() {
|
||||
return new MetricsOptions();
|
||||
}
|
||||
|
||||
private MetricsOptions() {}
|
||||
|
||||
/**
|
||||
* Returns whether metrics are enabled.
|
||||
@@ -195,4 +263,26 @@ public class MetricsOptionGroup {
|
||||
public String getMetricsPrometheusJob() {
|
||||
return metricsPrometheusJob;
|
||||
}
|
||||
|
||||
@CommandLine.ArgGroup(validate = false)
|
||||
private final MetricsOptions.Unstable unstableOptions = new MetricsOptions.Unstable();
|
||||
|
||||
static class Unstable {
|
||||
private static final String TIMERS_ENABLED_FLAG = "--Xmetrics-timers-enabled";
|
||||
private static final String IDLE_TIMEOUT_FLAG = "--Xmetrics-idle-timeout";
|
||||
|
||||
@CommandLine.Option(
|
||||
names = TIMERS_ENABLED_FLAG,
|
||||
hidden = true,
|
||||
description = "Whether to enable timer metrics (default: ${DEFAULT-VALUE}).")
|
||||
private Boolean timersEnabled = MetricsConfiguration.DEFAULT_METRICS_TIMERS_ENABLED;
|
||||
|
||||
@CommandLine.Option(
|
||||
hidden = true,
|
||||
names = {IDLE_TIMEOUT_FLAG},
|
||||
paramLabel = "<INTEGER>",
|
||||
description = "Timeout for metrics TCP connections, in seconds (default: ${DEFAULT-VALUE})",
|
||||
arity = "1")
|
||||
private int idleTimeout = MetricsConfiguration.DEFAULT_METRICS_IDLE_TIMEOUT_SECONDS;
|
||||
}
|
||||
}
|
||||
@@ -52,20 +52,7 @@ public class P2PDiscoveryOptions implements CLIOptions<P2PDiscoveryConfiguration
|
||||
arity = "1")
|
||||
public final Boolean p2pEnabled = true;
|
||||
|
||||
/**
|
||||
* Boolean option to indicate if peers should NOT be discovered, default to false indicates that
|
||||
* the peers should be discovered by default.
|
||||
*/
|
||||
//
|
||||
// This negative option is required because of the nature of the option that is
|
||||
// true when
|
||||
// added on the command line. You can't do --option=false, so false is set as
|
||||
// default
|
||||
// and you have not to set the option at all if you want it false.
|
||||
// This seems to be the only way it works with Picocli.
|
||||
// Also many other software use the same negative option scheme for false
|
||||
// defaults
|
||||
// meaning that it's probably the right way to handle disabling options.
|
||||
/** Boolean option to indicate if peers should be discovered. */
|
||||
@CommandLine.Option(
|
||||
names = {"--discovery-enabled"},
|
||||
description = "Enable P2P discovery (default: ${DEFAULT-VALUE})",
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright ConsenSys AG.
|
||||
*
|
||||
* 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.cli.options.unstable;
|
||||
|
||||
import org.hyperledger.besu.cli.options.CLIOptions;
|
||||
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
/** The Metrics cli options. */
|
||||
// TODO: combine into MetricsOptionGroup, use Unstable inner class pattern (see MiningOptions)
|
||||
public class MetricsCLIOptions implements CLIOptions<MetricsConfiguration.Builder> {
|
||||
private static final String TIMERS_ENABLED_FLAG = "--Xmetrics-timers-enabled";
|
||||
private static final String IDLE_TIMEOUT_FLAG = "--Xmetrics-idle-timeout";
|
||||
|
||||
@CommandLine.Option(
|
||||
names = TIMERS_ENABLED_FLAG,
|
||||
hidden = true,
|
||||
description = "Whether to enable timer metrics (default: ${DEFAULT-VALUE}).")
|
||||
private Boolean timersEnabled = MetricsConfiguration.DEFAULT_METRICS_TIMERS_ENABLED;
|
||||
|
||||
@CommandLine.Option(
|
||||
hidden = true,
|
||||
names = {IDLE_TIMEOUT_FLAG},
|
||||
paramLabel = "<INTEGER>",
|
||||
description = "Timeout for metrics TCP connections, in seconds (default: ${DEFAULT-VALUE})",
|
||||
arity = "1")
|
||||
private int idleTimeout = MetricsConfiguration.DEFAULT_METRICS_IDLE_TIMEOUT_SECONDS;
|
||||
|
||||
private MetricsCLIOptions() {}
|
||||
|
||||
/**
|
||||
* Create metrics cli options.
|
||||
*
|
||||
* @return the metrics cli options
|
||||
*/
|
||||
public static MetricsCLIOptions create() {
|
||||
return new MetricsCLIOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* From configuration metrics cli options.
|
||||
*
|
||||
* @param config the config
|
||||
* @return the metrics cli options
|
||||
*/
|
||||
public static MetricsCLIOptions fromConfiguration(final MetricsConfiguration config) {
|
||||
final MetricsCLIOptions metricsOptions = create();
|
||||
metricsOptions.timersEnabled = config.isTimersEnabled();
|
||||
metricsOptions.idleTimeout = config.getIdleTimeout();
|
||||
return metricsOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricsConfiguration.Builder toDomainObject() {
|
||||
return MetricsConfiguration.builder().timersEnabled(timersEnabled).idleTimeout(idleTimeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCLIOptions() {
|
||||
return Arrays.asList(
|
||||
TIMERS_ENABLED_FLAG + "=" + timersEnabled.toString(),
|
||||
IDLE_TIMEOUT_FLAG + "=" + idleTimeout);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.config.GenesisConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.consensus.common.bft.BftEventQueue;
|
||||
import org.hyperledger.besu.consensus.common.bft.network.PeerConnectionTracker;
|
||||
import org.hyperledger.besu.consensus.common.bft.protocol.BftProtocolManager;
|
||||
@@ -250,7 +250,7 @@ public final class RunnerBuilderTest {
|
||||
engine.setEnabled(true);
|
||||
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
|
||||
when(mockMainnet.networkId()).thenReturn(BigInteger.ONE);
|
||||
MergeConfigOptions.setMergeEnabled(true);
|
||||
MergeConfiguration.setMergeEnabled(true);
|
||||
when(besuController.getMiningCoordinator()).thenReturn(mock(MergeMiningCoordinator.class));
|
||||
|
||||
final Runner runner =
|
||||
@@ -292,7 +292,7 @@ public final class RunnerBuilderTest {
|
||||
wsRpc.setEnabled(true);
|
||||
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
|
||||
when(mockMainnet.networkId()).thenReturn(BigInteger.ONE);
|
||||
MergeConfigOptions.setMergeEnabled(true);
|
||||
MergeConfiguration.setMergeEnabled(true);
|
||||
when(besuController.getMiningCoordinator()).thenReturn(mock(MergeMiningCoordinator.class));
|
||||
final JsonRpcConfiguration engineConf = JsonRpcConfiguration.createEngineDefault();
|
||||
engineConf.setEnabled(true);
|
||||
@@ -335,7 +335,7 @@ public final class RunnerBuilderTest {
|
||||
wsRpc.setEnabled(true);
|
||||
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
|
||||
when(mockMainnet.networkId()).thenReturn(BigInteger.ONE);
|
||||
MergeConfigOptions.setMergeEnabled(true);
|
||||
MergeConfiguration.setMergeEnabled(true);
|
||||
when(besuController.getMiningCoordinator()).thenReturn(mock(MergeMiningCoordinator.class));
|
||||
final JsonRpcConfiguration engineConf = JsonRpcConfiguration.createEngineDefault();
|
||||
engineConf.setEnabled(true);
|
||||
@@ -383,7 +383,7 @@ public final class RunnerBuilderTest {
|
||||
defaultWebSockConfig.setEnabled(true);
|
||||
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
|
||||
when(mockMainnet.networkId()).thenReturn(BigInteger.ONE);
|
||||
MergeConfigOptions.setMergeEnabled(true);
|
||||
MergeConfiguration.setMergeEnabled(true);
|
||||
|
||||
final Runner runner =
|
||||
new RunnerBuilder()
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.config.JsonUtil;
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
import org.hyperledger.besu.controller.MainnetBesuControllerBuilder;
|
||||
import org.hyperledger.besu.crypto.KeyPairUtil;
|
||||
@@ -151,7 +151,7 @@ public final class RunnerTest {
|
||||
@Test
|
||||
public void fullSyncFromGenesis() throws Exception {
|
||||
// set merge flag to false, otherwise this test can fail if a merge test runs first
|
||||
MergeConfigOptions.setMergeEnabled(false);
|
||||
MergeConfiguration.setMergeEnabled(false);
|
||||
|
||||
syncFromGenesis(SyncMode.FULL, getFastSyncGenesis());
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public final class RunnerTest {
|
||||
@Test
|
||||
public void fastSyncFromGenesis() throws Exception {
|
||||
// set merge flag to false, otherwise this test can fail if a merge test runs first
|
||||
MergeConfigOptions.setMergeEnabled(false);
|
||||
MergeConfiguration.setMergeEnabled(false);
|
||||
|
||||
syncFromGenesis(SyncMode.FAST, getFastSyncGenesis());
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import static org.mockito.Mockito.mock;
|
||||
import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.cli.config.NetworkName;
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.controller.BesuController;
|
||||
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
|
||||
import org.hyperledger.besu.ethereum.GasLimitCalculator;
|
||||
@@ -91,7 +91,7 @@ public final class RlpBlockImporterTest {
|
||||
@Test
|
||||
public void blockImportRejectsBadPow() throws IOException {
|
||||
// set merge flag to false, otherwise this test can fail if a merge test runs first
|
||||
MergeConfigOptions.setMergeEnabled(false);
|
||||
MergeConfiguration.setMergeEnabled(false);
|
||||
|
||||
final Path source = dataDir.resolve("badpow.blocks");
|
||||
BlockTestUtil.writeBadPowBlocks(source);
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.mockito.Mockito.verify;
|
||||
import org.hyperledger.besu.BesuInfo;
|
||||
import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.datatypes.Wei;
|
||||
@@ -162,13 +162,13 @@ public class BesuCommandTest extends CommandTestAbstract {
|
||||
// and ignore errors in case no trusted setup was already loaded
|
||||
}
|
||||
|
||||
MergeConfigOptions.setMergeEnabled(false);
|
||||
MergeConfiguration.setMergeEnabled(false);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
|
||||
MergeConfigOptions.setMergeEnabled(false);
|
||||
MergeConfiguration.setMergeEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.hyperledger.besu.cli.options.MiningOptions;
|
||||
import org.hyperledger.besu.cli.options.TransactionPoolOptions;
|
||||
import org.hyperledger.besu.cli.options.stable.EthstatsOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.MetricsCLIOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.NetworkingOptions;
|
||||
import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions;
|
||||
import org.hyperledger.besu.components.BesuComponent;
|
||||
@@ -610,10 +609,6 @@ public abstract class CommandTestAbstract {
|
||||
return dataStorageOptions;
|
||||
}
|
||||
|
||||
public MetricsCLIOptions getMetricsCLIOptions() {
|
||||
return unstableMetricsCLIOptions;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (vertx != null) {
|
||||
final AtomicBoolean closed = new AtomicBoolean(false);
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
*/
|
||||
package org.hyperledger.besu.cli.options;
|
||||
|
||||
import org.hyperledger.besu.cli.options.unstable.MetricsCLIOptions;
|
||||
import org.hyperledger.besu.cli.options.stable.MetricsOptions;
|
||||
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MetricsCLIOptionsTest
|
||||
extends AbstractCLIOptionsTest<MetricsConfiguration.Builder, MetricsCLIOptions> {
|
||||
public class MetricsOptionsTest
|
||||
extends AbstractCLIOptionsTest<MetricsConfiguration.Builder, MetricsOptions> {
|
||||
|
||||
@Override
|
||||
protected MetricsConfiguration.Builder createDefaultDomainObject() {
|
||||
@@ -37,13 +37,13 @@ public class MetricsCLIOptionsTest
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MetricsCLIOptions optionsFromDomainObject(
|
||||
protected MetricsOptions optionsFromDomainObject(
|
||||
final MetricsConfiguration.Builder domainObject) {
|
||||
return MetricsCLIOptions.fromConfiguration(domainObject.build());
|
||||
return MetricsOptions.fromConfiguration(domainObject.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MetricsCLIOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) {
|
||||
return besuCommand.getMetricsCLIOptions();
|
||||
protected MetricsOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) {
|
||||
return besuCommand.getMetricsOptions();
|
||||
}
|
||||
}
|
||||
@@ -16,14 +16,14 @@ package org.hyperledger.besu.config;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/** The Merge config options. */
|
||||
// TODO: naming this with Options as the suffix is misleading, it should be MergeConfig - doesn't
|
||||
/** The Merge configuration. */
|
||||
|
||||
// use picocli
|
||||
public class MergeConfigOptions {
|
||||
public class MergeConfiguration {
|
||||
private static final AtomicBoolean mergeEnabled = new AtomicBoolean(false);
|
||||
|
||||
/** Default constructor. */
|
||||
private MergeConfigOptions() {}
|
||||
private MergeConfiguration() {}
|
||||
|
||||
/**
|
||||
* Enables merge.
|
||||
@@ -17,7 +17,7 @@ package org.hyperledger.besu.consensus.clique;
|
||||
import static org.hyperledger.besu.ethereum.mainnet.AbstractGasLimitSpecification.DEFAULT_MAX_GAS_LIMIT;
|
||||
import static org.hyperledger.besu.ethereum.mainnet.AbstractGasLimitSpecification.DEFAULT_MIN_GAS_LIMIT;
|
||||
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.consensus.clique.headervalidationrules.CliqueDifficultyValidationRule;
|
||||
import org.hyperledger.besu.consensus.clique.headervalidationrules.CliqueExtraDataValidationRule;
|
||||
import org.hyperledger.besu.consensus.clique.headervalidationrules.CliqueNoEmptyBlockValidationRule;
|
||||
@@ -69,7 +69,7 @@ public class BlockHeaderValidationRulesetFactory {
|
||||
createEmptyBlocks,
|
||||
epochManager,
|
||||
baseFeeMarket,
|
||||
MergeConfigOptions.isMergeEnabled());
|
||||
MergeConfiguration.isMergeEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,7 +32,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.consensus.merge.MergeContext;
|
||||
import org.hyperledger.besu.consensus.merge.PayloadWrapper;
|
||||
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator.ForkchoiceResult;
|
||||
@@ -204,7 +204,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
return blockCreationTask;
|
||||
});
|
||||
|
||||
MergeConfigOptions.setMergeEnabled(true);
|
||||
MergeConfiguration.setMergeEnabled(true);
|
||||
|
||||
when(ethContext.getEthPeers().subscribeConnect(any())).thenReturn(1L);
|
||||
this.transactionPool =
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider
|
||||
import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.consensus.merge.MergeContext;
|
||||
import org.hyperledger.besu.consensus.merge.PostMergeContext;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
@@ -89,7 +89,7 @@ public class MergeReorgTest implements MergeGenesisConfigHelper {
|
||||
genesisState.writeStateTo(mutable);
|
||||
mutable.persist(null);
|
||||
mergeContext.setTerminalTotalDifficulty(Difficulty.of(1001));
|
||||
MergeConfigOptions.setMergeEnabled(true);
|
||||
MergeConfiguration.setMergeEnabled(true);
|
||||
this.coordinator =
|
||||
new MergeCoordinator(
|
||||
protocolContext,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.mainnet;
|
||||
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.config.MergeConfiguration;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
|
||||
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
|
||||
@@ -130,7 +130,7 @@ public final class MainnetBlockHeaderValidator {
|
||||
|
||||
public static BlockHeaderValidator.Builder createBaseFeeMarketValidator(
|
||||
final BaseFeeMarket baseFeeMarket) {
|
||||
return createBaseFeeMarketValidator(baseFeeMarket, MergeConfigOptions.isMergeEnabled());
|
||||
return createBaseFeeMarketValidator(baseFeeMarket, MergeConfiguration.isMergeEnabled());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -30,13 +30,17 @@ import com.google.common.base.MoreObjects;
|
||||
|
||||
/** The Metrics configuration. */
|
||||
public class MetricsConfiguration {
|
||||
private static final String DEFAULT_METRICS_HOST = "127.0.0.1";
|
||||
|
||||
/** The constant DEFAULT_METRICS_HOST. */
|
||||
public static final String DEFAULT_METRICS_HOST = "127.0.0.1";
|
||||
|
||||
/** The constant DEFAULT_METRICS_PORT. */
|
||||
public static final int DEFAULT_METRICS_PORT = 9545;
|
||||
|
||||
private static final MetricsProtocol DEFAULT_METRICS_PROTOCOL = MetricsProtocol.PROMETHEUS;
|
||||
private static final String DEFAULT_METRICS_PUSH_HOST = "127.0.0.1";
|
||||
|
||||
/** The constant DEFAULT_METRICS_PUSH_HOST. */
|
||||
public static final String DEFAULT_METRICS_PUSH_HOST = "127.0.0.1";
|
||||
|
||||
/** The constant DEFAULT_METRICS_PUSH_PORT. */
|
||||
public static final int DEFAULT_METRICS_PUSH_PORT = 9001;
|
||||
|
||||
Reference in New Issue
Block a user