Skip to content

Commit

Permalink
[MINOR] ux improvements (#6049)
Browse files Browse the repository at this point in the history
* log command line option that is affected

* made plugins summary log part of config overview

* check for null plugin context

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
macfarla authored Oct 19, 2023
1 parent a90ea05 commit e8bca61
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
2 changes: 2 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3555,6 +3555,8 @@ private String generateConfigurationOverview() {

builder.setTxPoolImplementation(buildTransactionPoolConfiguration().getTxPoolImplementation());

builder.setPluginContext(besuComponent.getBesuPluginContext());

return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.hyperledger.besu.BesuInfo;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
import org.hyperledger.besu.services.BesuPluginContextImpl;
import org.hyperledger.besu.util.log.FramedLogMessage;
import org.hyperledger.besu.util.platform.PlatformDetector;

Expand Down Expand Up @@ -50,6 +51,7 @@ public class ConfigurationOverviewBuilder {
private boolean isHighSpec = false;
private TransactionPoolConfiguration.Implementation txPoolImplementation;
private Map<String, String> environment;
private BesuPluginContextImpl besuPluginContext;

/**
* @param logger the logger
Expand Down Expand Up @@ -277,6 +279,12 @@ public String build() {
lines.add("Total memory: " + normalizeSize(hardwareInfo.getMemory().getTotal()));
lines.add("CPU cores: " + hardwareInfo.getProcessor().getLogicalProcessorCount());

lines.add("");

if (besuPluginContext != null) {
lines.addAll(besuPluginContext.getPluginsSummaryLog());
}

return FramedLogMessage.generate(lines);
}

Expand Down Expand Up @@ -308,4 +316,13 @@ private void detectJemalloc(final List<String> lines) {
private String normalizeSize(final long size) {
return String.format("%.02f", (double) (size) / 1024 / 1024 / 1024) + " GB";
}

/**
* set the plugin context
*
* @param besuPluginContext the plugin context
*/
public void setPluginContext(final BesuPluginContextImpl besuPluginContext) {
this.besuPluginContext = besuPluginContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static void checkMultiOptionDependencies(
}

/**
* Fail if option doesnt meet requirement.
* Fail if option doesn't meet requirement.
*
* @param commandLine the command line
* @param errorMessage the error message
Expand All @@ -126,7 +126,8 @@ public static void failIfOptionDoesntMeetRequirement(
final String affectedOptions = getAffectedOptions(commandLine, dependentOptionsNames);

if (!affectedOptions.isEmpty()) {
throw new CommandLine.ParameterException(commandLine, errorMessage);
throw new CommandLine.ParameterException(
commandLine, errorMessage + " [" + affectedOptions + "]");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.hyperledger.besu.plugin.BesuPlugin;
import org.hyperledger.besu.plugin.services.BesuService;
import org.hyperledger.besu.plugin.services.PluginVersionsProvider;
import org.hyperledger.besu.util.log.FramedLogMessage;

import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -76,6 +75,7 @@ private enum Lifecycle {
private final Map<Class<?>, ? super BesuService> serviceRegistry = new HashMap<>();
private final List<BesuPlugin> plugins = new ArrayList<>();
private final List<String> pluginVersions = new ArrayList<>();
final List<String> lines = new ArrayList<>();

/**
* Add service.
Expand Down Expand Up @@ -105,9 +105,7 @@ public <T extends BesuService> Optional<T> getService(final Class<T> serviceType
* @param pluginsDir the plugins dir
*/
public void registerPlugins(final Path pluginsDir) {
final List<String> lines = new ArrayList<>();
lines.add("plugins dir " + pluginsDir.toAbsolutePath());
lines.add("");
lines.add("Plugins:");
checkState(
state == Lifecycle.UNINITIALIZED,
"Besu plugins have already been registered. Cannot register additional plugins.");
Expand All @@ -120,11 +118,13 @@ public void registerPlugins(final Path pluginsDir) {
final ServiceLoader<BesuPlugin> serviceLoader =
ServiceLoader.load(BesuPlugin.class, pluginLoader);

int pluginsCount = 0;
for (final BesuPlugin plugin : serviceLoader) {
pluginsCount++;
try {
plugin.register(this);
LOG.info("Registered plugin of type {}.", plugin.getClass().getName());
lines.add(String.format("SUCCESS %s", plugin.getClass().getSimpleName()));
lines.add(String.format(plugin.getClass().getSimpleName()));
addPluginVersion(plugin);
} catch (final Exception e) {
LOG.error(
Expand All @@ -139,13 +139,23 @@ public void registerPlugins(final Path pluginsDir) {
}

LOG.debug("Plugin registration complete.");
lines.add("");
lines.add("TOTAL = " + plugins.size());
LOG.debug(FramedLogMessage.generate(lines));
lines.add(
String.format(
"TOTAL = %d of %d plugins successfully loaded", plugins.size(), pluginsCount));
lines.add(String.format("from %s", pluginsDir.toAbsolutePath()));

state = Lifecycle.REGISTERED;
}

/**
* get the summary log, as a list of string lines
*
* @return the summary
*/
public List<String> getPluginsSummaryLog() {
return lines;
}

private void addPluginVersion(final BesuPlugin plugin) {
final Package pluginPackage = plugin.getClass().getPackage();
final String implTitle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

/** The Rpc endpoint service implementation. */
/** The RPC endpoint service implementation. */
public class RpcEndpointServiceImpl implements RpcEndpointService {
private final Map<String, Function<PluginRpcRequest, ?>> rpcMethods = new HashMap<>();

Expand Down

0 comments on commit e8bca61

Please sign in to comment.