mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
revamping plugin extensions
This commit is contained in:
parent
83da24a8ef
commit
71103041f9
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.vectormath;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -30,7 +31,7 @@ public class CqlUtilsPluginInfo implements ScriptingExtensionPluginInfo<CqlUtils
|
||||
}
|
||||
|
||||
@Override
|
||||
public CqlUtils getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
||||
public CqlUtils getExtensionObject(Logger logger, NBBaseComponent baseComponent, LabeledScenarioContext scriptContext) {
|
||||
return new CqlUtils();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.vectormath;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -30,7 +31,7 @@ public class PineconeScriptingUtilsPluginInfo implements ScriptingExtensionPlugi
|
||||
}
|
||||
|
||||
@Override
|
||||
public PineconeScriptingUtils getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
||||
public PineconeScriptingUtils getExtensionObject(Logger logger, NBBaseComponent baseComponent, LabeledScenarioContext scriptContext) {
|
||||
return new PineconeScriptingUtils();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,507 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package io.nosqlbench.engine.core.lifecycle.scenario;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
||||
import io.nosqlbench.api.annotations.Annotation;
|
||||
import io.nosqlbench.api.annotations.Layer;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.extensions.SandboxExtensionFinder;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.metadata.ScenarioMetadata;
|
||||
import io.nosqlbench.api.metadata.ScenarioMetadataAware;
|
||||
import io.nosqlbench.api.metadata.SystemId;
|
||||
import io.nosqlbench.engine.api.scripting.ScriptEnvBuffer;
|
||||
import io.nosqlbench.engine.core.annotation.Annotators;
|
||||
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
||||
import io.nosqlbench.engine.core.lifecycle.activity.ActivityProgressIndicator;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.ScenarioContext;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.ScriptParams;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.bindings.ActivityBindings;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.bindings.PolyglotMetricRegistryBindings;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.bindings.PolyglotScenarioController;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.graalvm.polyglot.Context;
|
||||
import org.graalvm.polyglot.Engine.Builder;
|
||||
import org.graalvm.polyglot.EnvironmentAccess;
|
||||
import org.graalvm.polyglot.HostAccess;
|
||||
import org.graalvm.polyglot.PolyglotAccess;
|
||||
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptEngine;
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class NBScenario extends NBBaseComponent implements Callable<ExecutionMetricsResult> {
|
||||
|
||||
private final String reportSummaryTo;
|
||||
private final Path logsPath;
|
||||
private final Invocation invocation;
|
||||
private final String scriptfile;
|
||||
private Logger logger = LogManager.getLogger("SCENARIO");
|
||||
|
||||
private State state = State.Scheduled;
|
||||
private volatile ScenarioShutdownHook scenarioShutdownHook;
|
||||
private Exception error;
|
||||
private ScenarioMetadata scenarioMetadata;
|
||||
|
||||
private ExecutionMetricsResult result;
|
||||
private final NBLabeledElement parentComponent;
|
||||
|
||||
public Optional<ExecutionMetricsResult> getResultIfComplete() {
|
||||
return Optional.ofNullable(result);
|
||||
}
|
||||
|
||||
public enum Invocation {
|
||||
RENDER_SCRIPT,
|
||||
EXECUTE_SCRIPT
|
||||
}
|
||||
|
||||
public enum State {
|
||||
Scheduled,
|
||||
Running,
|
||||
Errored,
|
||||
Interrupted,
|
||||
Finished
|
||||
}
|
||||
|
||||
private final List<String> scripts = new ArrayList<>();
|
||||
private ScriptEngine scriptEngine;
|
||||
private ScenarioController scenarioController;
|
||||
private ActivityProgressIndicator activityProgressIndicator;
|
||||
private String progressInterval = "console:1m";
|
||||
private ScenarioContext scriptEnv;
|
||||
private final String scenarioName;
|
||||
private ScriptParams scenarioScriptParams;
|
||||
private final Engine engine = Engine.Graalvm;
|
||||
private long startedAtMillis = -1L;
|
||||
private long endedAtMillis = -1L;
|
||||
|
||||
public enum Engine {
|
||||
Graalvm
|
||||
}
|
||||
|
||||
public NBScenario(
|
||||
final String scenarioName,
|
||||
final String progressInterval,
|
||||
final String reportSummaryTo,
|
||||
final Path logsPath,
|
||||
String scriptfile,
|
||||
NBComponent parentComponent,
|
||||
Invocation invocation
|
||||
) {
|
||||
super(parentComponent, NBLabels.forKV("scenario", scenarioName));
|
||||
this.scenarioName = scenarioName;
|
||||
this.progressInterval = progressInterval;
|
||||
this.reportSummaryTo = reportSummaryTo;
|
||||
this.logsPath = logsPath;
|
||||
this.scriptfile = scriptfile;
|
||||
this.parentComponent = parentComponent;
|
||||
this.invocation = invocation;
|
||||
}
|
||||
|
||||
public static NBScenario forTesting(final String name, final String reportSummaryTo, NBComponent parent) {
|
||||
|
||||
return new NBScenario(
|
||||
name,
|
||||
"console:10s",
|
||||
reportSummaryTo,
|
||||
Path.of("logs"),
|
||||
"",
|
||||
new NBBaseComponent(parent,NBLabels.forKV("test","testrun")),
|
||||
Invocation.EXECUTE_SCRIPT
|
||||
);
|
||||
}
|
||||
|
||||
public NBScenario setLogger(final Logger logger) {
|
||||
this.logger = logger;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
public NBScenario addScriptText(final String scriptText) {
|
||||
this.scripts.add(scriptText);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public NBScenario addScriptFiles(final String... args) {
|
||||
for (final String scriptFile : args) {
|
||||
final Path scriptPath = Paths.get(scriptFile);
|
||||
byte[] bytes = new byte[0];
|
||||
try {
|
||||
bytes = Files.readAllBytes(scriptPath);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
final Charset utf8 = StandardCharsets.UTF_8;
|
||||
final String scriptData = utf8.decode(bb).toString();
|
||||
this.addScriptText(scriptData);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void initializeScriptingEngine(final ScenarioController scenarioController) {
|
||||
|
||||
this.logger.debug("Using engine {}", this.engine.toString());
|
||||
final MetricRegistry metricRegistry = ActivityMetrics.getMetricRegistry();
|
||||
|
||||
final Context.Builder contextSettings = Context.newBuilder("js")
|
||||
.allowHostAccess(HostAccess.ALL)
|
||||
.allowNativeAccess(true)
|
||||
.allowCreateThread(true)
|
||||
.allowIO(true)
|
||||
.allowHostClassLookup(s -> true)
|
||||
.allowHostClassLoading(true)
|
||||
.allowCreateProcess(true)
|
||||
.allowAllAccess(true)
|
||||
.allowEnvironmentAccess(EnvironmentAccess.INHERIT)
|
||||
.allowPolyglotAccess(PolyglotAccess.ALL)
|
||||
.option("js.ecmascript-version", "2022")
|
||||
.option("js.nashorn-compat", "true");
|
||||
|
||||
final Builder engineBuilder = org.graalvm.polyglot.Engine.newBuilder();
|
||||
engineBuilder.option("engine.WarnInterpreterOnly", "false");
|
||||
final org.graalvm.polyglot.Engine polyglotEngine = engineBuilder.build();
|
||||
|
||||
// TODO: add in, out, err for this scenario
|
||||
scriptEngine = GraalJSScriptEngine.create(polyglotEngine, contextSettings);
|
||||
|
||||
|
||||
if (!"disabled".equals(progressInterval))
|
||||
this.activityProgressIndicator = new ActivityProgressIndicator(scenarioController, this.progressInterval);
|
||||
|
||||
this.scriptEnv = new ScenarioContext(scenarioName, scenarioController);
|
||||
this.scriptEngine.setContext(this.scriptEnv);
|
||||
|
||||
this.scriptEngine.put("params", this.scenarioScriptParams);
|
||||
this.scriptEngine.put("scenario", new PolyglotScenarioController(scenarioController));
|
||||
this.scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
|
||||
this.scriptEngine.put("activities", new ActivityBindings(scenarioController));
|
||||
|
||||
for (final ScriptingExtensionPluginInfo<?> extensionDescriptor : SandboxExtensionFinder.findAll()) {
|
||||
if (!extensionDescriptor.isAutoLoading()) {
|
||||
this.logger.info(() -> "Not loading " + extensionDescriptor + ", autoloading is false");
|
||||
continue;
|
||||
}
|
||||
|
||||
final Logger extensionLogger =
|
||||
LogManager.getLogger("extensions." + extensionDescriptor.getBaseVariableName());
|
||||
final Object extensionObject = extensionDescriptor.getExtensionObject(
|
||||
extensionLogger,
|
||||
this,
|
||||
this.scriptEnv
|
||||
);
|
||||
ScenarioMetadataAware.apply(extensionObject, this.getScenarioMetadata());
|
||||
this.logger.trace(() -> "Adding extension object: name=" + extensionDescriptor.getBaseVariableName() +
|
||||
" class=" + extensionObject.getClass().getSimpleName());
|
||||
this.scriptEngine.put(extensionDescriptor.getBaseVariableName(), extensionObject);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized ScenarioMetadata getScenarioMetadata() {
|
||||
if (null == this.scenarioMetadata) scenarioMetadata = new ScenarioMetadata(
|
||||
startedAtMillis,
|
||||
scenarioName,
|
||||
SystemId.getNodeId(),
|
||||
SystemId.getNodeFingerprint()
|
||||
);
|
||||
return this.scenarioMetadata;
|
||||
}
|
||||
|
||||
private synchronized void runScenario() {
|
||||
this.scenarioShutdownHook = new ScenarioShutdownHook(this);
|
||||
Runtime.getRuntime().addShutdownHook(this.scenarioShutdownHook);
|
||||
|
||||
this.state = State.Running;
|
||||
this.startedAtMillis = System.currentTimeMillis();
|
||||
Annotators.recordAnnotation(
|
||||
Annotation.newBuilder()
|
||||
.element(this)
|
||||
.now()
|
||||
.layer(Layer.Scenario)
|
||||
.addDetail("engine", engine.toString())
|
||||
.build()
|
||||
);
|
||||
|
||||
this.logger.debug("Running control script for {}.", scenarioName);
|
||||
this.scenarioController = new ScenarioController(this);
|
||||
try {
|
||||
this.initializeScriptingEngine(this.scenarioController);
|
||||
this.executeScenarioScripts();
|
||||
final long awaitCompletionTime = 86400 * 365 * 1000L;
|
||||
this.logger.debug("Awaiting completion of scenario and activities for {} millis.", awaitCompletionTime);
|
||||
this.scenarioController.awaitCompletion(awaitCompletionTime);
|
||||
} catch (final Exception e) {
|
||||
error = e;
|
||||
} finally {
|
||||
this.scenarioController.shutdown();
|
||||
}
|
||||
|
||||
Runtime.getRuntime().removeShutdownHook(this.scenarioShutdownHook);
|
||||
final var runHook = this.scenarioShutdownHook;
|
||||
this.scenarioShutdownHook = null;
|
||||
runHook.run();
|
||||
this.logger.debug("removing scenario shutdown hook");
|
||||
}
|
||||
|
||||
public void notifyException(final Thread t, final Throwable e) {
|
||||
error = new RuntimeException("in thread " + t.getName() + ", " + e, e);
|
||||
}
|
||||
|
||||
private void executeScenarioScripts() {
|
||||
for (final String script : this.scripts)
|
||||
try {
|
||||
Object result = null;
|
||||
if ((scriptEngine instanceof Compilable compilableEngine)) {
|
||||
this.logger.debug("Using direct script compilation");
|
||||
final CompiledScript compiled = compilableEngine.compile(script);
|
||||
this.logger.debug("-> invoking main scenario script (compiled)");
|
||||
result = compiled.eval();
|
||||
this.logger.debug("<- scenario script completed (compiled)");
|
||||
} else if ((null != scriptfile) && !this.scriptfile.isEmpty()) {
|
||||
final String filename = this.scriptfile.replace("_SESSION_", this.scenarioName);
|
||||
this.logger.debug("-> invoking main scenario script (interpreted from {})", filename);
|
||||
final Path written = Files.write(
|
||||
Path.of(filename),
|
||||
script.getBytes(StandardCharsets.UTF_8),
|
||||
StandardOpenOption.TRUNCATE_EXISTING,
|
||||
StandardOpenOption.CREATE
|
||||
);
|
||||
final BufferedReader reader = Files.newBufferedReader(written);
|
||||
this.scriptEngine.eval(reader);
|
||||
this.logger.debug("<- scenario control script completed (interpreted) from {})", filename);
|
||||
} else {
|
||||
this.logger.debug("-> invoking main scenario script (interpreted)");
|
||||
result = this.scriptEngine.eval(script);
|
||||
this.logger.debug("<- scenario control script completed (interpreted)");
|
||||
}
|
||||
|
||||
if (null != result)
|
||||
this.logger.debug("scenario result: type({}): value:{}", result.getClass().getCanonicalName(), result);
|
||||
System.err.flush();
|
||||
System.out.flush();
|
||||
} catch (final Exception e) {
|
||||
error = e;
|
||||
state = State.Errored;
|
||||
this.logger.error("Error in scenario, shutting down. ({})", e);
|
||||
try {
|
||||
scenarioController.forceStopScenario(5000, false);
|
||||
} catch (final Exception eInner) {
|
||||
this.logger.debug("Found inner exception while forcing stop with rethrow=false: {}", eInner);
|
||||
} finally {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} finally {
|
||||
System.out.flush();
|
||||
System.err.flush();
|
||||
this.endedAtMillis = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
this.logger.debug("finishing scenario");
|
||||
this.endedAtMillis = System.currentTimeMillis(); //TODO: Make only one endedAtMillis assignment
|
||||
if (State.Running == this.state) state = State.Finished;
|
||||
|
||||
if (null != scenarioShutdownHook) {
|
||||
// If this method was called while the shutdown hook is defined, then it means
|
||||
// that the scenario was ended before the hook was uninstalled normally.
|
||||
state = State.Interrupted;
|
||||
this.logger.warn("Scenario was interrupted by process exit, shutting down");
|
||||
} else
|
||||
this.logger.info("Scenario completed successfully, with {} logical activities.", this.scenarioController.getActivityExecutorMap().size());
|
||||
|
||||
this.logger.info(() -> "scenario state: " + state);
|
||||
|
||||
// We report the scenario state via annotation even for short runs
|
||||
final Annotation annotation = Annotation.newBuilder()
|
||||
.element(this)
|
||||
.interval(startedAtMillis, this.endedAtMillis)
|
||||
.layer(Layer.Scenario)
|
||||
.addDetail("event", "stop-scenario")
|
||||
.build();
|
||||
|
||||
Annotators.recordAnnotation(annotation);
|
||||
|
||||
}
|
||||
|
||||
public long getStartedAtMillis() {
|
||||
return this.startedAtMillis;
|
||||
}
|
||||
|
||||
public long getEndedAtMillis() {
|
||||
return this.endedAtMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be the only way to get a ScenarioResult for a Scenario.
|
||||
* <p>
|
||||
* The lifecycle of a scenario includes the lifecycles of all of the following:
|
||||
* <OL>
|
||||
* <LI>The scenario control script, executing within a graaljs context.</LI>
|
||||
* <LI>The lifecycle of every activity which is started within the scenario.</LI>
|
||||
* </OL>
|
||||
* <p>
|
||||
* All of these run asynchronously within the scenario, however the same thread that calls
|
||||
* the scenario is the one which executes the control script. A scenario ends when all
|
||||
* of the following conditions are met:
|
||||
* <UL>
|
||||
* <LI>The scenario control script has run to completion, or experienced an exception.</LI>
|
||||
* <LI>Each activity has run to completion, experienced an exception, or all</LI>
|
||||
* </UL>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public synchronized ExecutionMetricsResult call() {
|
||||
if (null == result) {
|
||||
try {
|
||||
this.runScenario();
|
||||
} catch (final Exception e) {
|
||||
error = e;
|
||||
} finally {
|
||||
this.logger.debug("{} scenario run", null == this.error ? "NORMAL" : "ERRORED");
|
||||
}
|
||||
String iolog = error != null ? error.toString() : this.scriptEnv.getTimedLog();
|
||||
result = new ExecutionMetricsResult(startedAtMillis, endedAtMillis, iolog, this.error);
|
||||
this.result.reportMetricsSummaryToLog();
|
||||
this.doReportSummaries(this.reportSummaryTo, this.result);
|
||||
}
|
||||
|
||||
return this.result;
|
||||
}
|
||||
|
||||
private void doReportSummaries(final String reportSummaryTo, final ExecutionMetricsResult result) {
|
||||
final List<PrintStream> fullChannels = new ArrayList<>();
|
||||
final List<PrintStream> briefChannels = new ArrayList<>();
|
||||
|
||||
|
||||
final String[] destinationSpecs = reportSummaryTo.split(", *");
|
||||
|
||||
for (final String spec : destinationSpecs)
|
||||
if ((null != spec) && !spec.isBlank()) {
|
||||
final String[] split = spec.split(":", 2);
|
||||
final String summaryTo = split[0];
|
||||
final long summaryWhen = (2 == split.length) ? (Long.parseLong(split[1]) * 1000L) : 0;
|
||||
|
||||
PrintStream out = null;
|
||||
switch (summaryTo.toLowerCase()) {
|
||||
case "console":
|
||||
case "stdout":
|
||||
out = System.out;
|
||||
break;
|
||||
case "stderr":
|
||||
out = System.err;
|
||||
break;
|
||||
default:
|
||||
final String outName = summaryTo
|
||||
.replaceAll("_SESSION_", scenarioName)
|
||||
.replaceAll("_LOGS_", this.logsPath.toString());
|
||||
try {
|
||||
out = new PrintStream(new FileOutputStream(outName));
|
||||
break;
|
||||
} catch (final FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (result.getElapsedMillis() > summaryWhen) fullChannels.add(out);
|
||||
else {
|
||||
this.logger.debug("Summarizing counting metrics only to {} with scenario duration of {}ms (<{})", spec, summaryWhen, summaryWhen);
|
||||
briefChannels.add(out);
|
||||
}
|
||||
}
|
||||
fullChannels.forEach(result::reportMetricsSummaryTo);
|
||||
// briefChannels.forEach(result::reportCountsTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if ((null == o) || (this.getClass() != o.getClass())) {
|
||||
return false;
|
||||
}
|
||||
final NBScenario scenario = (NBScenario) o;
|
||||
return Objects.equals(this.scenarioName, scenario.scenarioName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (null != this.scenarioName) ? scenarioName.hashCode() : 0;
|
||||
}
|
||||
|
||||
public String getScenarioName() {
|
||||
return this.scenarioName;
|
||||
}
|
||||
|
||||
public ScenarioController getScenarioController() {
|
||||
return this.scenarioController;
|
||||
}
|
||||
|
||||
public String getScriptText() {
|
||||
return String.join("", this.scripts);
|
||||
}
|
||||
|
||||
public Optional<List<String>> getIOLog() {
|
||||
return Optional.ofNullable(this.scriptEnv).map(ScriptEnvBuffer::getTimeLogLines);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "name:'" + scenarioName + '\'';
|
||||
}
|
||||
|
||||
public void addScenarioScriptParams(final ScriptParams scenarioScriptParams) {
|
||||
this.scenarioScriptParams = scenarioScriptParams;
|
||||
}
|
||||
|
||||
public void addScenarioScriptParams(final Map<String, String> scriptParams) {
|
||||
this.addScenarioScriptParams(new ScriptParams() {{
|
||||
this.putAll(scriptParams);
|
||||
}});
|
||||
}
|
||||
|
||||
public State getScenarioState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public String getReportSummaryTo() {
|
||||
return this.reportSummaryTo;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.computefunctions;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -32,7 +33,7 @@ public class ComputeFunctionPluginInfo implements ScriptingExtensionPluginInfo<C
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputeFunctions getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
||||
public ComputeFunctions getExtensionObject(Logger logger, NBBaseComponent baseComponent, LabeledScenarioContext scriptContext) {
|
||||
return new ComputeFunctions();
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.conversions;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -32,7 +33,7 @@ public class ConversionUtilsPluginInfo implements ScriptingExtensionPluginInfo<C
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConverterUtils getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
||||
public ConverterUtils getExtensionObject(Logger logger, NBBaseComponent baseComponent, LabeledScenarioContext scriptContext) {
|
||||
return new ConverterUtils();
|
||||
}
|
||||
|
||||
|
@ -16,28 +16,36 @@
|
||||
|
||||
package io.nosqlbench.engine.extensions.csvmetrics;
|
||||
|
||||
import com.codahale.metrics.CsvReporter;
|
||||
import com.codahale.metrics.Metric;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.CsvReporter;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBBuilders;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CSVMetrics {
|
||||
public class CSVMetrics extends NBBaseComponent {
|
||||
|
||||
private final MetricRegistry registry;
|
||||
private NBBaseComponent baseComponent;
|
||||
private final NBBuilders builders;
|
||||
private final File reportTo;
|
||||
CsvReporter reporter;
|
||||
private CsvReporter reporter;
|
||||
private int interval = 1;
|
||||
private final Logger extensionLogger;
|
||||
|
||||
/**
|
||||
* Create a CSV reporter that is not automatically logging.
|
||||
* @param baseComponent a NBBaseComponent instance to report
|
||||
* @param directory a CSV logging filename
|
||||
* @param logger an extension logger, to be used for logging extension-specific events
|
||||
* @param registry a MetricRegistry to report
|
||||
*/
|
||||
public CSVMetrics(String directory, Logger logger, MetricRegistry registry) {
|
||||
public CSVMetrics(NBBaseComponent baseComponent, String directory, Logger logger) {
|
||||
super(baseComponent);
|
||||
this.baseComponent = baseComponent;
|
||||
extensionLogger = logger;
|
||||
builders = new NBBuilders(baseComponent);
|
||||
File reportTo = new File(directory);
|
||||
if (!reportTo.exists()) {
|
||||
if (!reportTo.mkdirs()) {
|
||||
@ -45,38 +53,35 @@ public class CSVMetrics {
|
||||
}
|
||||
}
|
||||
this.reportTo = reportTo;
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public void setInterval(int interval) {
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
private void initReporter() {
|
||||
if (reporter!=null) {
|
||||
return;
|
||||
}
|
||||
reporter = CsvReporter.forRegistry(registry)
|
||||
.convertDurationsTo(TimeUnit.MILLISECONDS)
|
||||
.convertRatesTo(TimeUnit.SECONDS)
|
||||
.filter(filter)
|
||||
.build(reportTo);
|
||||
|
||||
reporter = builders.csvReporter(reportTo, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an autologging CSV Reporter with the specified period and time unit.
|
||||
* Create an autologging CSV Reporter with the specified period
|
||||
* @param csvFile a CSV logging filename
|
||||
* @param logger an extension logger, to be used for logging extension-specific events
|
||||
* @param registry a MetricRegistry to report
|
||||
* @param baseComponent a NBBaseComponent instance to report
|
||||
* @param period a period between reporting intervals
|
||||
* @param timeUnit the actual timeunit for the period
|
||||
*/
|
||||
public CSVMetrics(String csvFile, Logger logger, MetricRegistry registry, long period, TimeUnit timeUnit) {
|
||||
this(csvFile, logger, registry);
|
||||
reporter.start(period, timeUnit);
|
||||
public CSVMetrics(String csvFile, Logger logger, NBBaseComponent baseComponent, int period) {
|
||||
this(baseComponent, csvFile, logger);
|
||||
this.start(period);
|
||||
}
|
||||
|
||||
public CSVMetrics start(long period, String timeUnitName) {
|
||||
public CSVMetrics start(int period) {
|
||||
setInterval(period);
|
||||
initReporter();
|
||||
TimeUnit timeUnit = TimeUnit.valueOf(timeUnitName);
|
||||
reporter.start(period, timeUnit);
|
||||
reporter.task();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -94,7 +99,7 @@ public class CSVMetrics {
|
||||
private final MetricInstanceFilter filter = new MetricInstanceFilter();
|
||||
|
||||
public CSVMetrics stop() {
|
||||
reporter.stop();
|
||||
reporter.teardown();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -17,19 +17,23 @@
|
||||
package io.nosqlbench.engine.extensions.csvmetrics;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.components.NBComponentMetrics;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CSVMetricsPlugin {
|
||||
public class CSVMetricsPlugin extends NBBaseComponent {
|
||||
private final ScriptContext context;
|
||||
private final Logger logger;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final NBBaseComponent parent;
|
||||
|
||||
public CSVMetricsPlugin(Logger logger, MetricRegistry metricRegistry, ScriptContext scriptContext) {
|
||||
public CSVMetricsPlugin(Logger logger, NBBaseComponent parent, ScriptContext scriptContext) {
|
||||
super(parent);
|
||||
this.logger = logger;
|
||||
this.metricRegistry = metricRegistry;
|
||||
this.parent = parent;
|
||||
this.context = scriptContext;
|
||||
}
|
||||
|
||||
@ -39,7 +43,7 @@ public class CSVMetricsPlugin {
|
||||
* @return the CSVMetrics instance, for method chaining
|
||||
*/
|
||||
public CSVMetrics log(String filename) {
|
||||
CSVMetrics csvMetrics = new CSVMetrics(filename, logger, metricRegistry);
|
||||
CSVMetrics csvMetrics = new CSVMetrics(parent, filename, logger);
|
||||
writeStdout("started new csvmetrics: " + filename + "\n");
|
||||
return csvMetrics;
|
||||
}
|
||||
@ -57,7 +61,7 @@ public class CSVMetricsPlugin {
|
||||
for(String p:pattern) {
|
||||
log.addPattern(p);
|
||||
}
|
||||
return log.start(period, timeUnit);
|
||||
return log.start((int)period);
|
||||
}
|
||||
|
||||
private void writeStdout(String msg) {
|
||||
|
@ -16,9 +16,9 @@
|
||||
|
||||
package io.nosqlbench.engine.extensions.csvmetrics;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -30,9 +30,12 @@ public class CSVMetricsPluginData implements ScriptingExtensionPluginInfo<CSVMet
|
||||
return "Allows a script to log some or all metrics to CSV files";
|
||||
}
|
||||
|
||||
/*
|
||||
* metricComponent should be the Scenario as this is loaded out of NBScenario
|
||||
*/
|
||||
@Override
|
||||
public CSVMetricsPlugin getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
return new CSVMetricsPlugin(logger, metricRegistry, scriptContext);
|
||||
public CSVMetricsPlugin getExtensionObject(final Logger logger, final NBBaseComponent scenario, final LabeledScenarioContext scriptContext) {
|
||||
return new CSVMetricsPlugin(logger, scenario, scriptContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.csvoutput;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -31,7 +32,7 @@ public class CsvOutputPluginData implements ScriptingExtensionPluginInfo<CsvOutp
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsvOutputPluginInstance getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
public CsvOutputPluginInstance getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
return new CsvOutputPluginInstance();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.example;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -32,7 +33,7 @@ public class ExamplePluginData implements ScriptingExtensionPluginInfo<ExamplePl
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExamplePlugin getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
public ExamplePlugin getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
return new ExamplePlugin();
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.files;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -31,7 +32,7 @@ public class FileAccessPluginData implements ScriptingExtensionPluginInfo<FileAc
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileAccess getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
public FileAccess getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
return new FileAccess();
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.globalvars;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -34,7 +35,7 @@ public class GlobalVarsScriptingExtensionPluginData implements ScriptingExtensio
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConcurrentHashMap<String, Object> getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
public ConcurrentHashMap<String, Object> getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
final ConcurrentHashMap<String, Object> map = SharedState.gl_ObjectMap;
|
||||
return map;
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package io.nosqlbench.engine.extensions.histologger;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -23,12 +25,12 @@ import javax.script.ScriptContext;
|
||||
|
||||
public class HdrHistoLogPlugin {
|
||||
private final Logger logger;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final NBBaseComponent baseComponent;
|
||||
private final ScriptContext scriptContext;
|
||||
|
||||
public HdrHistoLogPlugin(Logger logger, MetricRegistry metricRegistry, ScriptContext scriptContext) {
|
||||
public HdrHistoLogPlugin(Logger logger, NBBaseComponent baseComponent, ScriptContext scriptContext) {
|
||||
this.logger = logger;
|
||||
this.metricRegistry = metricRegistry;
|
||||
this.baseComponent = baseComponent;
|
||||
this.scriptContext = scriptContext;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.histologger;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -32,7 +33,7 @@ public class HdrHistoLogPluginData implements ScriptingExtensionPluginInfo<HdrHi
|
||||
}
|
||||
|
||||
@Override
|
||||
public HdrHistoLogPlugin getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
return new HdrHistoLogPlugin(logger,metricRegistry,scriptContext);
|
||||
public HdrHistoLogPlugin getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
return new HdrHistoLogPlugin(logger,baseComponent,scriptContext);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
package io.nosqlbench.engine.extensions.histostatslogger;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
@ -24,12 +26,12 @@ import javax.script.ScriptContext;
|
||||
public class HistoStatsPlugin {
|
||||
|
||||
private final Logger logger;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final NBBaseComponent baseComponent;
|
||||
private final ScriptContext scriptContext;
|
||||
|
||||
public HistoStatsPlugin(Logger logger, MetricRegistry metricRegistry, ScriptContext scriptContext) {
|
||||
public HistoStatsPlugin(Logger logger, NBBaseComponent baseComponent, ScriptContext scriptContext) {
|
||||
this.logger = logger;
|
||||
this.metricRegistry = metricRegistry;
|
||||
this.baseComponent = baseComponent;
|
||||
this.scriptContext = scriptContext;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.histostatslogger;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -31,7 +32,7 @@ public class HistoStatsPluginData implements ScriptingExtensionPluginInfo<HistoS
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoStatsPlugin getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
return new HistoStatsPlugin(logger,metricRegistry,scriptContext);
|
||||
public HistoStatsPlugin getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
return new HistoStatsPlugin(logger,baseComponent,scriptContext);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.http;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -31,7 +32,7 @@ public class HttpPluginData implements ScriptingExtensionPluginInfo<HttpPlugin>
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpPlugin getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
public HttpPlugin getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
return new HttpPlugin();
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package io.nosqlbench.engine.extensions.optimizers;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import org.apache.commons.math3.analysis.MultivariateFunction;
|
||||
import org.apache.commons.math3.optim.*;
|
||||
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType;
|
||||
@ -32,7 +33,7 @@ import java.util.function.Function;
|
||||
public class BobyqaOptimizerInstance {
|
||||
|
||||
private final Logger logger;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final NBBaseComponent baseComponent;
|
||||
private final ScriptContext scriptContext;
|
||||
|
||||
private int interpolations = 0;
|
||||
@ -49,9 +50,9 @@ public class BobyqaOptimizerInstance {
|
||||
private MVLogger mvLogger;
|
||||
private double guessSlew = 0.25d;
|
||||
|
||||
public BobyqaOptimizerInstance(Logger logger, MetricRegistry metricRegistry, ScriptContext scriptContext) {
|
||||
public BobyqaOptimizerInstance(Logger logger, NBBaseComponent baseComponent, ScriptContext scriptContext) {
|
||||
this.logger = logger;
|
||||
this.metricRegistry = metricRegistry;
|
||||
this.baseComponent = baseComponent;
|
||||
this.scriptContext = scriptContext;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
package io.nosqlbench.engine.extensions.optimizers;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBBuilders;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
@ -24,17 +26,17 @@ import javax.script.ScriptContext;
|
||||
public class BobyqaOptimizerPlugin {
|
||||
|
||||
private final Logger logger;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final NBBaseComponent baseComponent;
|
||||
private final ScriptContext scriptContext;
|
||||
|
||||
public BobyqaOptimizerPlugin(Logger logger, MetricRegistry metricRegistry, ScriptContext scriptContext) {
|
||||
public BobyqaOptimizerPlugin(Logger logger, NBBaseComponent baseComponent, ScriptContext scriptContext) {
|
||||
this.logger = logger;
|
||||
this.metricRegistry = metricRegistry;
|
||||
this.baseComponent = baseComponent;
|
||||
this.scriptContext = scriptContext;
|
||||
}
|
||||
|
||||
public BobyqaOptimizerInstance init() {
|
||||
return new BobyqaOptimizerInstance(logger,metricRegistry,scriptContext);
|
||||
return new BobyqaOptimizerInstance(logger,baseComponent,scriptContext);
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.optimizers;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -31,8 +32,8 @@ public class BobyqaOptimizerPluginData implements ScriptingExtensionPluginInfo<B
|
||||
}
|
||||
|
||||
@Override
|
||||
public BobyqaOptimizerPlugin getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
return new BobyqaOptimizerPlugin(logger, metricRegistry, scriptContext);
|
||||
public BobyqaOptimizerPlugin getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
return new BobyqaOptimizerPlugin(logger, baseComponent, scriptContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import io.nosqlbench.addins.s3.s3urlhandler.S3UrlFields;
|
||||
import io.nosqlbench.api.system.NBEnvironment;
|
||||
import io.nosqlbench.api.metadata.ScenarioMetadata;
|
||||
import io.nosqlbench.api.metadata.ScenarioMetadataAware;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
@ -39,13 +40,13 @@ import java.util.Map;
|
||||
|
||||
public class S3Uploader implements ScenarioMetadataAware {
|
||||
private final Logger logger;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final NBBaseComponent baseComponent;
|
||||
private final ScriptContext scriptContext;
|
||||
private ScenarioMetadata scenarioMetadata;
|
||||
|
||||
public S3Uploader(Logger logger, MetricRegistry metricRegistry, ScriptContext scriptContext) {
|
||||
public S3Uploader(Logger logger, NBBaseComponent baseComponent, ScriptContext scriptContext) {
|
||||
this.logger = logger;
|
||||
this.metricRegistry = metricRegistry;
|
||||
this.baseComponent = baseComponent;
|
||||
this.scriptContext = scriptContext;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.s3uploader;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.api.metadata.ScenarioMetadata;
|
||||
import io.nosqlbench.api.metadata.ScenarioMetadataAware;
|
||||
@ -34,8 +35,8 @@ public class S3UploaderPluginData implements ScriptingExtensionPluginInfo<S3Uplo
|
||||
}
|
||||
|
||||
@Override
|
||||
public S3Uploader getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
final S3Uploader uploader = new S3Uploader(logger, metricRegistry, scriptContext);
|
||||
public S3Uploader getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
final S3Uploader uploader = new S3Uploader(logger, baseComponent, scriptContext);
|
||||
ScenarioMetadataAware.apply(uploader, this.scenarioMetadata);
|
||||
return uploader;
|
||||
}
|
||||
|
@ -21,18 +21,19 @@ import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.metrics.DoubleSummaryGauge;
|
||||
import io.nosqlbench.api.engine.metrics.wrappers.RelevancyMeasures;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ScriptingMetrics {
|
||||
private final Logger logger;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final NBBaseComponent baseComponent;
|
||||
private final LabeledScenarioContext scriptContext;
|
||||
|
||||
public ScriptingMetrics(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
public ScriptingMetrics(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
this.logger = logger;
|
||||
this.metricRegistry = metricRegistry;
|
||||
this.baseComponent = baseComponent;
|
||||
this.scriptContext = scriptContext;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.extensions.scriptingmetrics;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -31,7 +32,7 @@ public class ScriptingMetricsPluginData implements ScriptingExtensionPluginInfo<
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptingMetrics getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
return new ScriptingMetrics(logger,metricRegistry,scriptContext);
|
||||
public ScriptingMetrics getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
return new ScriptingMetrics(logger,baseComponent,scriptContext);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package io.nosqlbench.engine.shutdown;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
@ -24,13 +25,13 @@ import java.util.function.Function;
|
||||
|
||||
public class ShutdownHookPlugin {
|
||||
private final Logger logger;
|
||||
private final MetricRegistry metricRegistry;
|
||||
private final NBBaseComponent baseComponent;
|
||||
private final ScriptContext scriptContext;
|
||||
|
||||
public ShutdownHookPlugin(Logger logger, MetricRegistry metricRegistry, ScriptContext scriptContext) {
|
||||
public ShutdownHookPlugin(Logger logger, NBBaseComponent baseComponent, ScriptContext scriptContext) {
|
||||
|
||||
this.logger = logger;
|
||||
this.metricRegistry = metricRegistry;
|
||||
this.baseComponent = baseComponent;
|
||||
this.scriptContext = scriptContext;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.shutdown;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -31,7 +32,7 @@ public class ShutdownHookPluginMetadata implements ScriptingExtensionPluginInfo<
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShutdownHookPlugin getExtensionObject(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||
return new ShutdownHookPlugin(logger,metricRegistry,scriptContext);
|
||||
public ShutdownHookPlugin getExtensionObject(final Logger logger, final NBBaseComponent baseComponent, final LabeledScenarioContext scriptContext) {
|
||||
return new ShutdownHookPlugin(logger,baseComponent,scriptContext);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.nosqlbench.api.engine.metrics.reporters;
|
||||
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.PeriodicTaskComponent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CsvReporter extends PeriodicTaskComponent {
|
||||
public CsvReporter(NBBaseComponent node, File reportTo, int interval) {
|
||||
super(node, null, interval, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void task() {
|
||||
|
||||
}
|
||||
|
||||
public void report() {
|
||||
}
|
||||
}
|
@ -16,8 +16,9 @@
|
||||
|
||||
package io.nosqlbench.api.extensions;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -41,11 +42,11 @@ public interface ScriptingExtensionPluginInfo<T> {
|
||||
|
||||
/**
|
||||
* @param logger A logger named for the extension, in case the extension wants to log internally
|
||||
* @param metricRegistry The main metric registry, in case the extension wants to track metrics internally
|
||||
* @param component The main metrics component, in case the extension wants to track metrics internally
|
||||
* @param scriptContext The scripting context object, useful for interacting with the sandbox directly
|
||||
* @return a new instance of an extension. The extension is given a logger if it desires.
|
||||
*/
|
||||
T getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext);
|
||||
T getExtensionObject(Logger logger, NBBaseComponent component, LabeledScenarioContext scriptContext);
|
||||
|
||||
/**
|
||||
* @return a simple name at the root of the variable namespace to anchor this extension.
|
||||
|
@ -19,12 +19,18 @@ package io.nosqlbench.components;
|
||||
import com.codahale.metrics.Meter;
|
||||
import io.nosqlbench.api.engine.metrics.DeltaHdrHistogramReservoir;
|
||||
import io.nosqlbench.api.engine.metrics.DoubleSummaryGauge;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBFunctionGauge;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricCounter;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricHistogram;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricTimer;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.CsvReporter;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.*;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.PromPushReporterComponent;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.DoubleSummaryStatistics;
|
||||
import java.util.List;
|
||||
@ -112,4 +118,9 @@ public class NBBuilders {
|
||||
return reporter;
|
||||
}
|
||||
|
||||
public CsvReporter csvReporter(File reportTo, int interval) {
|
||||
CsvReporter reporter = new CsvReporter(base, reportTo, interval);
|
||||
return reporter;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user