mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
Metrics Publishing (#1234)
Included the following with core changes to allow labeled metrics for Prometheus exposition format publishing. * javadoc updates * remove extra types * use NBLabeledElement instead of NBNamedElement * contextualize NBLabeledElement for graphite/metrics * externalize labeled ScriptContext to API * add labels to NicerTimer * remove partial packaging * more progress on formatting for prom exposition format * added metrics diagram * resolve build issues with label params * resolve build issues with label params * prometheus export services * added PromExpoFormat Tests for NBMetricMeter(Counting+Sampling) and NBMetricTimer(Counting) * added test for Gauge Formatting * added Gauge Formatting as well as Sampling values (count, stdev ...) * added sketch for metrics labeling contexts * add NBLabeledElement in all the places, retool calling paths to use it * synchronize antlr versions after partial snyk change * unbreak static initializer block after IntelliJ "fixed" it. * engine-api - adapt to NBLabeledElement * adapters-api - adapt to NBLabeledElement * nb-api - adapt to NBLabeledElement * engine-core - adapt to NBLabeledElement * misc-adapters - adapt to NBLabeledElement * streaming-adapters - adapt to NBLabeledElement * add missing test * initial implementation of a prom push reporter * Resolve build issue with parseGlobalOptions * replaced with PromPushReporter * cleanup unused deps * dependency removal for micrometer * allow empty labels for tests * change space.getName to space.getSpaceName * cleanup poms * graphite linearization now includes space element * http adapter should only depend on adapters API * http space does not create its own metric names * import cleanups * improved javadocs * introduce component concepts --------- Co-authored-by: Jonathan Shook <jshook@gmail.com> Co-authored-by: Mike Yaacoub <mike.yaacoub@datastax.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import io.nosqlbench.api.annotations.Layer;
|
||||
import io.nosqlbench.api.content.Content;
|
||||
import io.nosqlbench.api.content.NBIO;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.PromPushReporter;
|
||||
import io.nosqlbench.api.errors.BasicError;
|
||||
import io.nosqlbench.api.logging.NBLogLevel;
|
||||
import io.nosqlbench.api.metadata.SessionNamer;
|
||||
@@ -31,6 +32,8 @@ import io.nosqlbench.engine.api.activityapi.cyclelog.outputs.cyclelog.CycleLogIm
|
||||
import io.nosqlbench.engine.api.activityapi.input.InputType;
|
||||
import io.nosqlbench.engine.api.activityapi.output.OutputType;
|
||||
import io.nosqlbench.engine.api.activityconfig.rawyaml.RawOpsLoader;
|
||||
import io.nosqlbench.engine.cli.NBCLIOptions.LoggerConfigData;
|
||||
import io.nosqlbench.engine.cli.NBCLIOptions.Mode;
|
||||
import io.nosqlbench.engine.core.annotation.Annotators;
|
||||
import io.nosqlbench.engine.core.lifecycle.process.NBCLIErrorHandler;
|
||||
import io.nosqlbench.engine.core.lifecycle.activity.ActivityTypeLoader;
|
||||
@@ -59,6 +62,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.ServiceLoader.Provider;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -72,12 +76,12 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
|
||||
static {
|
||||
loggerConfig = new LoggerConfig();
|
||||
LoggerConfig.setConfigurationFactory(loggerConfig);
|
||||
ConfigurationFactory.setConfigurationFactory(NBCLI.loggerConfig);
|
||||
}
|
||||
|
||||
private final String commandName;
|
||||
|
||||
public NBCLI(String commandName) {
|
||||
public NBCLI(final String commandName) {
|
||||
this.commandName = commandName;
|
||||
}
|
||||
|
||||
@@ -86,14 +90,15 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
* invocations are handled functionally by {@link #apply(String[])}, which allows
|
||||
* for scenario encapsulation and concurrent testing.
|
||||
*
|
||||
* @param args Command Line Args
|
||||
* @param args
|
||||
* Command Line Args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
public static void main(final String[] args) {
|
||||
try {
|
||||
NBCLI cli = new NBCLI("nb");
|
||||
int statusCode = cli.apply(args);
|
||||
final NBCLI cli = new NBCLI("nb");
|
||||
final int statusCode = cli.apply(args);
|
||||
System.exit(statusCode);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
System.out.println("Not expected issue in main: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -101,40 +106,36 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
/**
|
||||
* return null;
|
||||
* }
|
||||
*
|
||||
* <p>
|
||||
* public static void main(String[] args) {
|
||||
*
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Integer apply(String[] args) {
|
||||
public Integer apply(final String[] args) {
|
||||
try {
|
||||
NBCLI cli = new NBCLI("nb");
|
||||
int result = cli.applyDirect(args);
|
||||
final NBCLI cli = new NBCLI("nb");
|
||||
final int result = cli.applyDirect(args);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
boolean showStackTraces = false;
|
||||
for (String arg : args) {
|
||||
|
||||
if (arg.toLowerCase(Locale.ROOT).startsWith("-v") || (arg.toLowerCase(Locale.ROOT).equals("--show-stacktraces"))) {
|
||||
for (final String arg : args)
|
||||
if (arg.toLowerCase(Locale.ROOT).startsWith("-v") || "--show-stacktraces".equals(arg.toLowerCase(Locale.ROOT))) {
|
||||
showStackTraces = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String error = NBCLIErrorHandler.handle(e, showStackTraces);
|
||||
final String error = NBCLIErrorHandler.handle(e, showStackTraces);
|
||||
// Commented for now, as the above handler should do everything needed.
|
||||
if (error != null) {
|
||||
System.err.println("Scenario stopped due to error. See logs for details.");
|
||||
}
|
||||
if (null != error) System.err.println("Scenario stopped due to error. See logs for details.");
|
||||
System.err.flush();
|
||||
System.out.flush();
|
||||
return EXIT_ERROR;
|
||||
return NBCLI.EXIT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer applyDirect(String[] args) {
|
||||
public Integer applyDirect(final String[] args) {
|
||||
|
||||
// Initial logging config covers only command line parsing
|
||||
// We don't want anything to go to console here unless it is a real problem
|
||||
@@ -145,12 +146,12 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
// .activate();
|
||||
// logger = LogManager.getLogger("NBCLI");
|
||||
|
||||
loggerConfig.setConsoleLevel(NBLogLevel.ERROR);
|
||||
NBCLI.loggerConfig.setConsoleLevel(NBLogLevel.ERROR);
|
||||
|
||||
NBCLIOptions globalOptions = new NBCLIOptions(args, NBCLIOptions.Mode.ParseGlobalsOnly);
|
||||
String sessionName = SessionNamer.format(globalOptions.getSessionName());
|
||||
final NBCLIOptions globalOptions = new NBCLIOptions(args, Mode.ParseGlobalsOnly);
|
||||
final String sessionName = SessionNamer.format(globalOptions.getSessionName());
|
||||
|
||||
loggerConfig
|
||||
NBCLI.loggerConfig
|
||||
.setSessionName(sessionName)
|
||||
.setConsoleLevel(globalOptions.getConsoleLogLevel())
|
||||
.setConsolePattern(globalOptions.getConsoleLoggingPattern())
|
||||
@@ -161,63 +162,67 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
.setLogsDirectory(globalOptions.getLogsDirectory())
|
||||
.setAnsiEnabled(globalOptions.isEnableAnsi())
|
||||
.activate();
|
||||
ConfigurationFactory.setConfigurationFactory(loggerConfig);
|
||||
ConfigurationFactory.setConfigurationFactory(NBCLI.loggerConfig);
|
||||
|
||||
logger = LogManager.getLogger("NBCLI");
|
||||
loggerConfig.purgeOldFiles(LogManager.getLogger("SCENARIO"));
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info(() -> "Configured scenario log at " + loggerConfig.getLogfileLocation());
|
||||
} else {
|
||||
System.err.println("Configured scenario log at " + loggerConfig.getLogfileLocation());
|
||||
}
|
||||
logger.debug("Scenario log started");
|
||||
NBCLI.logger = LogManager.getLogger("NBCLI");
|
||||
NBCLI.loggerConfig.purgeOldFiles(LogManager.getLogger("SCENARIO"));
|
||||
if (NBCLI.logger.isInfoEnabled())
|
||||
NBCLI.logger.info(() -> "Configured scenario log at " + NBCLI.loggerConfig.getLogfileLocation());
|
||||
else System.err.println("Configured scenario log at " + NBCLI.loggerConfig.getLogfileLocation());
|
||||
NBCLI.logger.debug("Scenario log started");
|
||||
|
||||
// Global only processing
|
||||
if (args.length == 0) {
|
||||
System.out.println(loadHelpFile("commandline.md"));
|
||||
return EXIT_OK;
|
||||
if (0 == args.length) {
|
||||
System.out.println(this.loadHelpFile("commandline.md"));
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
logger.info(() -> "Running NoSQLBench Version " + new VersionInfo().getVersion());
|
||||
logger.info(() -> "command-line: " + Arrays.stream(args).collect(Collectors.joining(" ")));
|
||||
logger.info(() -> "client-hardware: " + SystemId.getHostSummary());
|
||||
NBCLI.logger.info(() -> "Running NoSQLBench Version " + new VersionInfo().getVersion());
|
||||
NBCLI.logger.info(() -> "command-line: " + Arrays.stream(args).collect(Collectors.joining(" ")));
|
||||
NBCLI.logger.info(() -> "client-hardware: " + SystemId.getHostSummary());
|
||||
|
||||
|
||||
// Invoke any bundled app which matches the name of the first non-option argument, if it exists.
|
||||
// If it does not, continue with no fanfare. Let it drop through to other command resolution methods.
|
||||
if (args.length > 0 && args[0].matches("\\w[\\w\\d-_.]+")) {
|
||||
ServiceSelector<BundledApp> apploader = ServiceSelector.of(args[0], ServiceLoader.load(BundledApp.class));
|
||||
BundledApp app = apploader.get().orElse(null);
|
||||
if (app != null) {
|
||||
String[] appargs = Arrays.copyOfRange(args, 1, args.length);
|
||||
logger.info(() -> "invoking bundled app '" + args[0] + "' (" + app.getClass().getSimpleName() + ").");
|
||||
if ((0 < args.length) && args[0].matches("\\w[\\w\\d-_.]+")) {
|
||||
final ServiceSelector<BundledApp> apploader = ServiceSelector.of(args[0], ServiceLoader.load(BundledApp.class));
|
||||
final BundledApp app = apploader.get().orElse(null);
|
||||
if (null != app) {
|
||||
final String[] appargs = Arrays.copyOfRange(args, 1, args.length);
|
||||
NBCLI.logger.info(() -> "invoking bundled app '" + args[0] + "' (" + app.getClass().getSimpleName() + ").");
|
||||
globalOptions.setWantsStackTraces(true);
|
||||
int result = app.applyAsInt(appargs);
|
||||
final int result = app.applyAsInt(appargs);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
boolean dockerMetrics = globalOptions.wantsDockerMetrics();
|
||||
String dockerMetricsAt = globalOptions.wantsDockerMetricsAt();
|
||||
|
||||
final boolean dockerMetrics = globalOptions.wantsDockerMetrics();
|
||||
final String dockerMetricsAt = globalOptions.wantsDockerMetricsAt();
|
||||
String reportGraphiteTo = globalOptions.wantsReportGraphiteTo();
|
||||
String annotatorsConfig = globalOptions.getAnnotatorsConfig();
|
||||
final String reportPromPushTo = globalOptions.wantsReportPromPushTo();
|
||||
|
||||
int mOpts = (dockerMetrics ? 1 : 0) + (dockerMetricsAt != null ? 1 : 0) + (reportGraphiteTo != null ? 1 : 0);
|
||||
if (mOpts > 1 && (reportGraphiteTo == null || annotatorsConfig == null)) {
|
||||
|
||||
|
||||
final int mOpts = (dockerMetrics ? 1 : 0)
|
||||
+ ((null != dockerMetricsAt) ? 1 : 0)
|
||||
+ ((null != reportGraphiteTo) ? 1 : 0);
|
||||
|
||||
if ((1 < mOpts) && ((null == reportGraphiteTo) || (null == annotatorsConfig)))
|
||||
throw new BasicError("You have multiple conflicting options which attempt to set\n" +
|
||||
" the destination for metrics and annotations. Please select only one of\n" +
|
||||
" --docker-metrics, --docker-metrics-at <addr>, or other options like \n" +
|
||||
" --report-graphite-to <addr> and --annotators <config>\n" +
|
||||
" For more details, see run 'nb help docker-metrics'");
|
||||
}
|
||||
|
||||
String metricsAddr = null;
|
||||
String graphiteMetricsAddress = null;
|
||||
|
||||
if (dockerMetrics) {
|
||||
// Setup docker stack for local docker metrics
|
||||
logger.info("Docker metrics is enabled. Docker must be installed for this to work");
|
||||
DockerMetricsManager dmh = new DockerMetricsManager();
|
||||
Map<String, String> dashboardOptions = Map.of(
|
||||
NBCLI.logger.info("Docker metrics is enabled. Docker must be installed for this to work");
|
||||
final DockerMetricsManager dmh = new DockerMetricsManager();
|
||||
final Map<String, String> dashboardOptions = Map.of(
|
||||
DockerMetricsManager.GRAFANA_TAG, globalOptions.getDockerGrafanaTag(),
|
||||
DockerMetricsManager.PROM_TAG, globalOptions.getDockerPromTag(),
|
||||
DockerMetricsManager.TSDB_RETENTION, String.valueOf(globalOptions.getDockerPromRetentionDays()),
|
||||
@@ -228,152 +233,143 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
|
||||
);
|
||||
dmh.startMetrics(dashboardOptions);
|
||||
String warn = "Docker Containers are started, for grafana and prometheus, hit" +
|
||||
final String warn = "Docker Containers are started, for grafana and prometheus, hit" +
|
||||
" these urls in your browser: http://<host>:3000 and http://<host>:9090";
|
||||
logger.warn(warn);
|
||||
metricsAddr = "localhost";
|
||||
} else if (dockerMetricsAt != null) {
|
||||
metricsAddr = dockerMetricsAt;
|
||||
}
|
||||
NBCLI.logger.warn(warn);
|
||||
graphiteMetricsAddress = "localhost";
|
||||
} else if (null != dockerMetricsAt) graphiteMetricsAddress = dockerMetricsAt;
|
||||
|
||||
if (metricsAddr != null) {
|
||||
reportGraphiteTo = metricsAddr + ":9109";
|
||||
annotatorsConfig = "[{type:'log',level:'info'},{type:'grafana',baseurl:'http://" + metricsAddr + ":3000" +
|
||||
if (null != graphiteMetricsAddress) {
|
||||
reportGraphiteTo = graphiteMetricsAddress + ":9109";
|
||||
annotatorsConfig = "[{type:'log',level:'info'},{type:'grafana',baseurl:'http://" + graphiteMetricsAddress + ":3000" +
|
||||
"/'," +
|
||||
"tags:'appname:nosqlbench',timeoutms:5000,onerror:'warn'}]";
|
||||
} else {
|
||||
annotatorsConfig = "[{type:'log',level:'info'}]";
|
||||
}
|
||||
} else annotatorsConfig = "[{type:'log',level:'info'}]";
|
||||
|
||||
NBCLIOptions options = new NBCLIOptions(args);
|
||||
logger = LogManager.getLogger("NBCLI");
|
||||
final NBCLIOptions options = new NBCLIOptions(args);
|
||||
NBCLI.logger = LogManager.getLogger("NBCLI");
|
||||
|
||||
NBIO.addGlobalIncludes(options.wantsIncludes());
|
||||
|
||||
ActivityMetrics.setHdrDigits(options.getHdrDigits());
|
||||
|
||||
if (options.wantsBasicHelp()) {
|
||||
System.out.println(loadHelpFile("basic.md"));
|
||||
return EXIT_OK;
|
||||
System.out.println(this.loadHelpFile("basic.md"));
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.isWantsVersionShort()) {
|
||||
System.out.println(new VersionInfo().getVersion());
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsVersionCoords()) {
|
||||
System.out.println(new VersionInfo().getArtifactCoordinates());
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.isWantsListApps()) {
|
||||
ServiceLoader<BundledApp> loader = ServiceLoader.load(BundledApp.class);
|
||||
for (ServiceLoader.Provider<BundledApp> provider : loader.stream().toList()) {
|
||||
Class<? extends BundledApp> appType = provider.type();
|
||||
String name = appType.getAnnotation(Service.class).selector();
|
||||
final ServiceLoader<BundledApp> loader = ServiceLoader.load(BundledApp.class);
|
||||
for (final Provider<BundledApp> provider : loader.stream().toList()) {
|
||||
final Class<? extends BundledApp> appType = provider.type();
|
||||
final String name = appType.getAnnotation(Service.class).selector();
|
||||
System.out.printf("%-40s %s%n", name, appType.getCanonicalName());
|
||||
}
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.getWantsListCommands()) {
|
||||
NBCLICommandParser.RESERVED_WORDS.forEach(System.out::println);
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
if (options.wantsActivityTypes()) {
|
||||
new ActivityTypeLoader().getAllSelectors().forEach(System.out::println);
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsWorkloadsList()) {
|
||||
NBCLIScenarios.printWorkloads(false, options.wantsIncludes());
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsScenariosList()) {
|
||||
NBCLIScenarios.printWorkloads(true, options.wantsIncludes());
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsListScripts()) {
|
||||
NBCLIScripts.printScripts(true, options.wantsIncludes());
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsToCopyResource()) {
|
||||
String resourceToCopy = options.wantsToCopyResourceNamed();
|
||||
logger.debug(() -> "user requests to copy out " + resourceToCopy);
|
||||
final String resourceToCopy = options.wantsToCopyResourceNamed();
|
||||
NBCLI.logger.debug(() -> "user requests to copy out " + resourceToCopy);
|
||||
|
||||
Optional<Content<?>> tocopy = NBIO.classpath()
|
||||
.searchPrefixes("activities")
|
||||
.searchPrefixes(options.wantsIncludes())
|
||||
.pathname(resourceToCopy).extensionSet(RawOpsLoader.YAML_EXTENSIONS).first();
|
||||
|
||||
if (tocopy.isEmpty()) {
|
||||
if (tocopy.isEmpty()) tocopy = NBIO.classpath()
|
||||
.searchPrefixes().searchPrefixes(options.wantsIncludes())
|
||||
.searchPrefixes(options.wantsIncludes())
|
||||
.pathname(resourceToCopy).first();
|
||||
|
||||
tocopy = NBIO.classpath()
|
||||
.searchPrefixes().searchPrefixes(options.wantsIncludes())
|
||||
.searchPrefixes(options.wantsIncludes())
|
||||
.pathname(resourceToCopy).first();
|
||||
}
|
||||
|
||||
Content<?> data = tocopy.orElseThrow(
|
||||
final Content<?> data = tocopy.orElseThrow(
|
||||
() -> new BasicError(
|
||||
"Unable to find " + resourceToCopy +
|
||||
" in classpath to copy out")
|
||||
);
|
||||
|
||||
Path writeTo = Path.of(data.asPath().getFileName().toString());
|
||||
if (Files.exists(writeTo)) {
|
||||
throw new BasicError("A file named " + writeTo + " exists. Remove it first.");
|
||||
}
|
||||
final Path writeTo = Path.of(data.asPath().getFileName().toString());
|
||||
if (Files.exists(writeTo)) throw new BasicError("A file named " + writeTo + " exists. Remove it first.");
|
||||
try {
|
||||
Files.writeString(writeTo, data.getCharBuffer(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new BasicError("Unable to write to " + writeTo + ": " + e.getMessage());
|
||||
}
|
||||
logger.info(() -> "Copied internal resource '" + data.asPath() + "' to '" + writeTo + "'");
|
||||
return EXIT_OK;
|
||||
NBCLI.logger.info(() -> "Copied internal resource '" + data.asPath() + "' to '" + writeTo + '\'');
|
||||
return NBCLI.EXIT_OK;
|
||||
|
||||
}
|
||||
|
||||
if (options.wantsInputTypes()) {
|
||||
InputType.FINDER.getAllSelectors().forEach((k, v) -> System.out.println(k + " (" + v.name() + ")"));
|
||||
return EXIT_OK;
|
||||
InputType.FINDER.getAllSelectors().forEach((k, v) -> System.out.println(k + " (" + v.name() + ')'));
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsMarkerTypes()) {
|
||||
OutputType.FINDER.getAllSelectors().forEach((k, v) -> System.out.println(k + " (" + v.name() + ")"));
|
||||
return EXIT_OK;
|
||||
OutputType.FINDER.getAllSelectors().forEach((k, v) -> System.out.println(k + " (" + v.name() + ')'));
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsToDumpCyclelog()) {
|
||||
CycleLogDumperUtility.main(options.getCycleLogExporterOptions());
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsToImportCycleLog()) {
|
||||
CycleLogImporterUtility.main(options.getCyclelogImportOptions());
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsTopicalHelp()) {
|
||||
Optional<String> helpDoc = MarkdownFinder.forHelpTopic(options.wantsTopicalHelpFor());
|
||||
final Optional<String> helpDoc = MarkdownFinder.forHelpTopic(options.wantsTopicalHelpFor());
|
||||
System.out.println(helpDoc.orElseThrow(
|
||||
() -> new RuntimeException("No help could be found for " + options.wantsTopicalHelpFor())
|
||||
));
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsMetricsForActivity() != null) {
|
||||
String metricsHelp = getMetricsHelpFor(options.wantsMetricsForActivity());
|
||||
System.out.println("Available metric names for activity:" + options.wantsMetricsForActivity() + ":");
|
||||
if (null != options.wantsMetricsForActivity()) {
|
||||
final String metricsHelp = this.getMetricsHelpFor(options.wantsMetricsForActivity());
|
||||
System.out.println("Available metric names for activity:" + options.wantsMetricsForActivity() + ':');
|
||||
System.out.println(metricsHelp);
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
logger.debug("initializing annotators with config:'" + annotatorsConfig + "'");
|
||||
NBCLI.logger.debug("initializing annotators with config:'{}'", annotatorsConfig);
|
||||
Annotators.init(annotatorsConfig);
|
||||
Annotators.recordAnnotation(
|
||||
Annotation.newBuilder()
|
||||
@@ -384,53 +380,48 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
.build()
|
||||
);
|
||||
|
||||
if (reportGraphiteTo != null || options.wantsReportCsvTo() != null) {
|
||||
MetricReporters reporters = MetricReporters.getInstance();
|
||||
if ((null != reportPromPushTo) || (null != reportGraphiteTo) || (null != options.wantsReportCsvTo())) {
|
||||
final MetricReporters reporters = MetricReporters.getInstance();
|
||||
reporters.addRegistry("workloads", ActivityMetrics.getMetricRegistry());
|
||||
|
||||
if (reportGraphiteTo != null) {
|
||||
reporters.addGraphite(reportGraphiteTo, options.wantsMetricsPrefix());
|
||||
}
|
||||
if (options.wantsReportCsvTo() != null) {
|
||||
if (null != reportPromPushTo) reporters.addPromPush(reportPromPushTo, options.wantsMetricsPrefix());
|
||||
if (null != reportGraphiteTo) reporters.addGraphite(reportGraphiteTo, options.wantsMetricsPrefix());
|
||||
if (null != options.wantsReportCsvTo())
|
||||
reporters.addCSVReporter(options.wantsReportCsvTo(), options.wantsMetricsPrefix());
|
||||
}
|
||||
reporters.start(10, options.getReportInterval());
|
||||
}
|
||||
|
||||
if (options.wantsEnableChart()) {
|
||||
logger.info("Charting enabled");
|
||||
if (options.getHistoLoggerConfigs().size() == 0) {
|
||||
logger.info("Adding default histologger configs");
|
||||
String pattern = ".*";
|
||||
String file = options.getChartHdrFileName();
|
||||
String interval = "1s";
|
||||
NBCLI.logger.info("Charting enabled");
|
||||
if (0 == options.getHistoLoggerConfigs().size()) {
|
||||
NBCLI.logger.info("Adding default histologger configs");
|
||||
final String pattern = ".*";
|
||||
final String file = options.getChartHdrFileName();
|
||||
final String interval = "1s";
|
||||
options.setHistoLoggerConfigs(pattern, file, interval);
|
||||
}
|
||||
}
|
||||
|
||||
for (
|
||||
NBCLIOptions.LoggerConfigData histoLogger : options.getHistoLoggerConfigs()) {
|
||||
final LoggerConfigData histoLogger : options.getHistoLoggerConfigs())
|
||||
ActivityMetrics.addHistoLogger(sessionName, histoLogger.pattern, histoLogger.file, histoLogger.interval);
|
||||
}
|
||||
for (
|
||||
NBCLIOptions.LoggerConfigData statsLogger : options.getStatsLoggerConfigs()) {
|
||||
final LoggerConfigData statsLogger : options.getStatsLoggerConfigs())
|
||||
ActivityMetrics.addStatsLogger(sessionName, statsLogger.pattern, statsLogger.file, statsLogger.interval);
|
||||
}
|
||||
for (
|
||||
NBCLIOptions.LoggerConfigData classicConfigs : options.getClassicHistoConfigs()) {
|
||||
final LoggerConfigData classicConfigs : options.getClassicHistoConfigs())
|
||||
ActivityMetrics.addClassicHistos(sessionName, classicConfigs.pattern, classicConfigs.file, classicConfigs.interval);
|
||||
}
|
||||
|
||||
// intentionally not shown for warn-only
|
||||
logger.info(() -> "console logging level is " + options.getConsoleLogLevel());
|
||||
NBCLI.logger.info(() -> "console logging level is " + options.getConsoleLogLevel());
|
||||
|
||||
ScenariosExecutor scenariosExecutor = new ScenariosExecutor("executor-" + sessionName, 1);
|
||||
final ScenariosExecutor scenariosExecutor = new ScenariosExecutor("executor-" + sessionName, 1);
|
||||
if (options.getConsoleLogLevel().isGreaterOrEqualTo(NBLogLevel.WARN)) {
|
||||
options.setWantsStackTraces(true);
|
||||
logger.debug(() -> "enabling stack traces since log level is " + options.getConsoleLogLevel());
|
||||
NBCLI.logger.debug(() -> "enabling stack traces since log level is " + options.getConsoleLogLevel());
|
||||
}
|
||||
|
||||
Scenario scenario = new Scenario(
|
||||
final Scenario scenario = new Scenario(
|
||||
sessionName,
|
||||
options.getScriptFile(),
|
||||
options.getScriptingEngine(),
|
||||
@@ -442,78 +433,73 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
options.getLogsDirectory(),
|
||||
Maturity.Unspecified);
|
||||
|
||||
ScriptBuffer buffer = new BasicScriptBuffer()
|
||||
final ScriptBuffer buffer = new BasicScriptBuffer()
|
||||
.add(options.getCommands()
|
||||
.toArray(new Cmd[0]));
|
||||
String scriptData = buffer.getParsedScript();
|
||||
final String scriptData = buffer.getParsedScript();
|
||||
|
||||
if (options.wantsShowScript()) {
|
||||
System.out.println("// Rendered Script");
|
||||
System.out.println(scriptData);
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
if (options.wantsEnableChart()) {
|
||||
logger.info("Charting enabled");
|
||||
NBCLI.logger.info("Charting enabled");
|
||||
scenario.enableCharting();
|
||||
} else {
|
||||
logger.info("Charting disabled");
|
||||
}
|
||||
} else NBCLI.logger.info("Charting disabled");
|
||||
|
||||
|
||||
// Execute Scenario!
|
||||
if (options.getCommands().size() == 0) {
|
||||
logger.info("No commands provided. Exiting before scenario.");
|
||||
return EXIT_OK;
|
||||
if (0 == options.getCommands().size()) {
|
||||
NBCLI.logger.info("No commands provided. Exiting before scenario.");
|
||||
return NBCLI.EXIT_OK;
|
||||
}
|
||||
|
||||
scenario.addScriptText(scriptData);
|
||||
ScriptParams scriptParams = new ScriptParams();
|
||||
final ScriptParams scriptParams = new ScriptParams();
|
||||
scriptParams.putAll(buffer.getCombinedParams());
|
||||
scenario.addScenarioScriptParams(scriptParams);
|
||||
|
||||
scenariosExecutor.execute(scenario);
|
||||
ScenariosResults scenariosResults = scenariosExecutor.awaitAllResults();
|
||||
logger.debug(() -> "Total of " + scenariosResults.getSize() + " result object returned from ScenariosExecutor");
|
||||
final ScenariosResults scenariosResults = scenariosExecutor.awaitAllResults();
|
||||
NBCLI.logger.debug(() -> "Total of " + scenariosResults.getSize() + " result object returned from ScenariosExecutor");
|
||||
|
||||
ActivityMetrics.closeMetrics(options.wantsEnableChart());
|
||||
scenariosResults.reportToLog();
|
||||
ShutdownManager.shutdown();
|
||||
|
||||
logger.info(scenariosResults.getExecutionSummary());
|
||||
NBCLI.logger.info(scenariosResults.getExecutionSummary());
|
||||
|
||||
if (scenariosResults.hasError()) {
|
||||
Exception exception = scenariosResults.getOne().getException();
|
||||
logger.warn(scenariosResults.getExecutionSummary());
|
||||
final Exception exception = scenariosResults.getOne().getException();
|
||||
NBCLI.logger.warn(scenariosResults.getExecutionSummary());
|
||||
NBCLIErrorHandler.handle(exception, options.wantsStackTraces());
|
||||
System.err.println(exception.getMessage()); // TODO: make this consistent with ConsoleLogging sequencing
|
||||
return EXIT_ERROR;
|
||||
} else {
|
||||
logger.info(scenariosResults.getExecutionSummary());
|
||||
return EXIT_OK;
|
||||
return NBCLI.EXIT_ERROR;
|
||||
}
|
||||
NBCLI.logger.info(scenariosResults.getExecutionSummary());
|
||||
return NBCLI.EXIT_OK;
|
||||
|
||||
}
|
||||
|
||||
private String loadHelpFile(String filename) {
|
||||
ClassLoader cl = getClass().getClassLoader();
|
||||
InputStream resourceAsStream = cl.getResourceAsStream(filename);
|
||||
if (resourceAsStream == null) {
|
||||
throw new RuntimeException("Unable to find " + filename + " in classpath.");
|
||||
}
|
||||
private String loadHelpFile(final String filename) {
|
||||
final ClassLoader cl = this.getClass().getClassLoader();
|
||||
final InputStream resourceAsStream = cl.getResourceAsStream(filename);
|
||||
if (null == resourceAsStream) throw new RuntimeException("Unable to find " + filename + " in classpath.");
|
||||
String basicHelp;
|
||||
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(resourceAsStream))) {
|
||||
try (final BufferedReader buffer = new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8))) {
|
||||
basicHelp = buffer.lines().collect(Collectors.joining("\n"));
|
||||
} catch (Throwable t) {
|
||||
} catch (final Throwable t) {
|
||||
throw new RuntimeException("Unable to buffer " + filename + ": " + t);
|
||||
}
|
||||
basicHelp = basicHelp.replaceAll("PROG", commandName);
|
||||
basicHelp = basicHelp.replaceAll("PROG", this.commandName);
|
||||
return basicHelp;
|
||||
|
||||
}
|
||||
|
||||
private String getMetricsHelpFor(String activityType) {
|
||||
String metrics = MetricsMapper.metricsDetail(activityType);
|
||||
private String getMetricsHelpFor(final String activityType) {
|
||||
final String metrics = MetricsMapper.metricsDetail(activityType);
|
||||
return metrics;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user