mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
scaffold labels into components
This commit is contained in:
@@ -18,10 +18,11 @@ package io.nosqlbench.engine.cli;
|
||||
|
||||
import io.nosqlbench.api.annotations.Annotation;
|
||||
import io.nosqlbench.api.annotations.Layer;
|
||||
import io.nosqlbench.api.config.NBLabeledElement;
|
||||
import io.nosqlbench.api.config.NBLabels;
|
||||
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;
|
||||
@@ -66,7 +67,7 @@ import java.util.ServiceLoader.Provider;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NBCLI implements Function<String[], Integer> {
|
||||
public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
|
||||
|
||||
private static Logger logger;
|
||||
private static final LoggerConfig loggerConfig;
|
||||
@@ -81,6 +82,9 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
|
||||
private final String commandName;
|
||||
|
||||
private NBLabels labels;
|
||||
private String sessionName;
|
||||
|
||||
public NBCLI(final String commandName) {
|
||||
this.commandName = commandName;
|
||||
}
|
||||
@@ -95,7 +99,7 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
*/
|
||||
public static void main(final String[] args) {
|
||||
try {
|
||||
final NBCLI cli = new NBCLI("nb");
|
||||
final NBCLI cli = new NBCLI("nb5");
|
||||
final int statusCode = cli.apply(args);
|
||||
System.exit(statusCode);
|
||||
} catch (final Exception e) {
|
||||
@@ -115,7 +119,7 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
@Override
|
||||
public Integer apply(final String[] args) {
|
||||
try {
|
||||
final NBCLI cli = new NBCLI("nb");
|
||||
final NBCLI cli = new NBCLI("nb5");
|
||||
final int result = cli.applyDirect(args);
|
||||
return result;
|
||||
} catch (final Exception e) {
|
||||
@@ -149,7 +153,8 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
NBCLI.loggerConfig.setConsoleLevel(NBLogLevel.ERROR);
|
||||
|
||||
final NBCLIOptions globalOptions = new NBCLIOptions(args, Mode.ParseGlobalsOnly);
|
||||
final String sessionName = SessionNamer.format(globalOptions.getSessionName());
|
||||
this.labels=NBLabels.forKV("command",commandName).and(globalOptions.getLabelMap());
|
||||
this.sessionName = SessionNamer.format(globalOptions.getSessionName());
|
||||
|
||||
NBCLI.loggerConfig
|
||||
.setSessionName(sessionName)
|
||||
@@ -432,7 +437,8 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
options.getReportSummaryTo(),
|
||||
String.join("\n", args),
|
||||
options.getLogsDirectory(),
|
||||
Maturity.Unspecified);
|
||||
Maturity.Unspecified,
|
||||
this);
|
||||
|
||||
final ScriptBuffer buffer = new BasicScriptBuffer()
|
||||
.add(options.getCommands()
|
||||
@@ -504,4 +510,8 @@ public class NBCLI implements Function<String[], Integer> {
|
||||
return metrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBLabels getLabels() {
|
||||
return labels;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class NBCLIOptions {
|
||||
private static final String userHome = System.getProperty("user.home");
|
||||
|
||||
|
||||
private static final Map<String,String> DEFAULT_LABELS=Map.of("appname","nosqlbench");
|
||||
private static final String METRICS_PREFIX = "--metrics-prefix";
|
||||
private static final String ANNOTATE_EVENTS = "--annotate";
|
||||
private static final String ANNOTATORS_CONFIG = "--annotators";
|
||||
@@ -82,6 +83,9 @@ public class NBCLIOptions {
|
||||
private static final String EXPERIMENTAL = "--experimental";
|
||||
private static final String MATURITY = "--maturity";
|
||||
|
||||
private static final String SET_LABELS = "--set-labels";
|
||||
private static final String ADD_LABELS = "--add-labels";
|
||||
|
||||
// Execution
|
||||
private static final String EXPORT_CYCLE_LOG = "--export-cycle-log";
|
||||
private static final String IMPORT_CYCLE_LOG = "--import-cycle-log";
|
||||
@@ -132,6 +136,7 @@ public class NBCLIOptions {
|
||||
// private static final String DEFAULT_CONSOLE_LOGGING_PATTERN = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n";
|
||||
|
||||
|
||||
private final Map<String,String> labels = new LinkedHashMap<>(DEFAULT_LABELS);
|
||||
private final List<Cmd> cmdList = new ArrayList<>();
|
||||
private int logsMax;
|
||||
private boolean wantsVersionShort;
|
||||
@@ -205,6 +210,9 @@ public class NBCLIOptions {
|
||||
return this.annotatorsConfig;
|
||||
}
|
||||
|
||||
public Map<String,String> getLabelMap() {
|
||||
return Collections.unmodifiableMap(this.labels);
|
||||
}
|
||||
|
||||
public String getChartHdrFileName() {
|
||||
return this.hdrForChartFileName;
|
||||
@@ -460,6 +468,16 @@ public class NBCLIOptions {
|
||||
arglist.removeFirst();
|
||||
final String maturity = this.readWordOrThrow(arglist, "maturity of components to allow");
|
||||
minMaturity = Maturity.valueOf(maturity.toLowerCase(Locale.ROOT));
|
||||
case NBCLIOptions.SET_LABELS:
|
||||
arglist.removeFirst();
|
||||
String setLabelData = arglist.removeFirst();
|
||||
setLabels(setLabelData);
|
||||
break;
|
||||
case NBCLIOptions.ADD_LABELS:
|
||||
arglist.removeFirst();
|
||||
String addLabeldata = arglist.removeFirst();
|
||||
addLabels(addLabeldata);
|
||||
break;
|
||||
default:
|
||||
nonincludes.addLast(arglist.removeFirst());
|
||||
}
|
||||
@@ -468,6 +486,29 @@ public class NBCLIOptions {
|
||||
return nonincludes;
|
||||
}
|
||||
|
||||
private void setLabels(String labeldata) {
|
||||
this.labels.clear();
|
||||
addLabels(labeldata);
|
||||
}
|
||||
|
||||
private void addLabels(String labeldata) {
|
||||
Map<String,String> newLabels = parseLabels(labeldata);
|
||||
this.labels.putAll(newLabels);
|
||||
}
|
||||
|
||||
private Map<String, String> parseLabels(String labeldata) {
|
||||
Map<String,String> setLabelsTo = new LinkedHashMap<>();
|
||||
for (String component : labeldata.split("[,; ]")) {
|
||||
String[] parts = component.split("\\W", 2);
|
||||
if (parts.length!=2) {
|
||||
throw new BasicError("Unable to parse labels to set:" + labeldata);
|
||||
}
|
||||
setLabelsTo.put(parts[0],parts[1]);
|
||||
}
|
||||
return setLabelsTo;
|
||||
}
|
||||
|
||||
|
||||
private Path setStatePath() {
|
||||
if (0 < statePathAccesses.size())
|
||||
throw new BasicError("The state dir must be set before it is used by other\n" +
|
||||
|
||||
@@ -74,6 +74,7 @@ public class Scenario implements Callable<ExecutionMetricsResult>, NBLabeledElem
|
||||
private ScenarioMetadata scenarioMetadata;
|
||||
|
||||
private ExecutionMetricsResult result;
|
||||
private final NBLabeledElement parentComponent;
|
||||
|
||||
public Optional<ExecutionMetricsResult> getResultIfComplete() {
|
||||
return Optional.ofNullable(result);
|
||||
@@ -82,7 +83,7 @@ public class Scenario implements Callable<ExecutionMetricsResult>, NBLabeledElem
|
||||
|
||||
@Override
|
||||
public NBLabels getLabels() {
|
||||
return NBLabels.forKV("scenario", this.scenarioName);
|
||||
return this.parentComponent.getLabels().and("scenario", this.scenarioName);
|
||||
}
|
||||
|
||||
public enum State {
|
||||
@@ -100,10 +101,10 @@ public class Scenario implements Callable<ExecutionMetricsResult>, NBLabeledElem
|
||||
private ScenarioContext scriptEnv;
|
||||
private final String scenarioName;
|
||||
private ScriptParams scenarioScriptParams;
|
||||
private String scriptfile;
|
||||
private final String scriptfile;
|
||||
private Engine engine = Engine.Graalvm;
|
||||
private boolean wantsStackTraces;
|
||||
private boolean wantsCompiledScript;
|
||||
private final boolean wantsStackTraces;
|
||||
private final boolean wantsCompiledScript;
|
||||
private long startedAtMillis = -1L;
|
||||
private long endedAtMillis = -1L;
|
||||
|
||||
@@ -121,7 +122,8 @@ public class Scenario implements Callable<ExecutionMetricsResult>, NBLabeledElem
|
||||
final String reportSummaryTo,
|
||||
final String commandLine,
|
||||
final Path logsPath,
|
||||
final Maturity minMaturity) {
|
||||
final Maturity minMaturity,
|
||||
NBLabeledElement parentComponent) {
|
||||
|
||||
this.scenarioName = scenarioName;
|
||||
this.scriptfile = scriptfile;
|
||||
@@ -133,17 +135,22 @@ public class Scenario implements Callable<ExecutionMetricsResult>, NBLabeledElem
|
||||
this.commandLine = commandLine;
|
||||
this.logsPath = logsPath;
|
||||
this.minMaturity = minMaturity;
|
||||
this.parentComponent = parentComponent;
|
||||
}
|
||||
|
||||
public Scenario(final String name, final Engine engine, final String reportSummaryTo, final Maturity minMaturity) {
|
||||
scenarioName = name;
|
||||
this.reportSummaryTo = reportSummaryTo;
|
||||
this.engine = engine;
|
||||
commandLine = "";
|
||||
this.minMaturity = minMaturity;
|
||||
logsPath = Path.of("logs");
|
||||
public static Scenario forTesting(final String name, final Engine engine, final String reportSummaryTo, final Maturity minMaturity) {
|
||||
return new Scenario(name,null,engine,"console:10s",true,true,reportSummaryTo,"",Path.of("logs"),minMaturity, NBLabeledElement.forKV("test-name","name"));
|
||||
}
|
||||
|
||||
// public Scenario(final String name, final Engine engine, final String reportSummaryTo, final Maturity minMaturity) {
|
||||
// scenarioName = name;
|
||||
// this.reportSummaryTo = reportSummaryTo;
|
||||
// this.engine = engine;
|
||||
// commandLine = "";
|
||||
// this.minMaturity = minMaturity;
|
||||
// logsPath = Path.of("logs");
|
||||
// }
|
||||
//
|
||||
public Scenario setLogger(final Logger logger) {
|
||||
this.logger = logger;
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user