mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
checkpoint
This commit is contained in:
parent
0699b446a6
commit
9fa711b7ab
@ -941,7 +941,7 @@ public class ParsedOp extends NBBaseComponent implements LongFunction<Map<String
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.tmap.toString();
|
||||
return "ParsedOp: map: " + this.tmap.toString();
|
||||
}
|
||||
|
||||
public List<CapturePoint> getCaptures() {
|
||||
|
@ -47,7 +47,6 @@ public interface Activity extends Comparable<Activity>, ActivityDefObserver, Pro
|
||||
*/
|
||||
void setActivityController(ActivityController activityController);
|
||||
|
||||
ActivityController getActivityController();
|
||||
|
||||
/**
|
||||
* Register an object which should be closed after this activity is shutdown.
|
||||
|
@ -15,7 +15,7 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<Configuration status="debug" strict="true" name="XMLConfigTest">
|
||||
<Configuration status="warn" strict="true" name="XMLConfigTest">
|
||||
|
||||
<Filter type="ThresholdFilter" level="trace"/>
|
||||
|
||||
|
@ -74,18 +74,20 @@ public class ActivitiesController extends NBBaseComponent {
|
||||
*
|
||||
* @param activityDef string in alias=value1;driver=value2;... format
|
||||
*/
|
||||
public synchronized void start(ActivityDef activityDef) {
|
||||
doStartActivity(activityDef);
|
||||
public Activity start(ActivityDef activityDef) {
|
||||
ActivityRuntimeInfo ari = doStartActivity(activityDef);
|
||||
return ari.getActivity();
|
||||
}
|
||||
|
||||
|
||||
private synchronized ActivityRuntimeInfo doStartActivity(ActivityDef activityDef) {
|
||||
private ActivityRuntimeInfo doStartActivity(ActivityDef activityDef) {
|
||||
if (!this.activityInfoMap.containsKey(activityDef.getAlias())) {
|
||||
Activity activity = this.activityLoader.loadActivity(activityDef, this);
|
||||
ActivityExecutor executor = new ActivityExecutor(activity);
|
||||
Future<ExecutionResult> startedActivity = activitiesExecutor.submit(executor);
|
||||
ActivityRuntimeInfo activityRuntimeInfo = new ActivityRuntimeInfo(activity, startedActivity, executor);
|
||||
this.activityInfoMap.put(activity.getAlias(), activityRuntimeInfo);
|
||||
|
||||
}
|
||||
return this.activityInfoMap.get(activityDef.getAlias());
|
||||
}
|
||||
@ -96,9 +98,9 @@ public class ActivitiesController extends NBBaseComponent {
|
||||
*
|
||||
* @param activityDefMap A map containing the activity definition
|
||||
*/
|
||||
public synchronized void start(Map<String, String> activityDefMap) {
|
||||
public Activity start(Map<String, String> activityDefMap) {
|
||||
ActivityDef ad = new ActivityDef(new ParameterMap(activityDefMap));
|
||||
start(ad);
|
||||
return start(ad);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,7 +44,7 @@ public class NBDefaultSceneFixtures implements NBSceneFixtures {
|
||||
/*
|
||||
These are parameters which are passed into the script, named scenario, etc.
|
||||
*/
|
||||
private ScriptParams params;
|
||||
private ScenarioParams params;
|
||||
/*
|
||||
* NBSession is the root component type in a NB process, and all CLI options which
|
||||
* affect global settings are expected to be properties on the session.
|
||||
@ -68,7 +68,7 @@ public class NBDefaultSceneFixtures implements NBSceneFixtures {
|
||||
|
||||
private Reader in;
|
||||
|
||||
public NBDefaultSceneFixtures(ScriptParams params, NBComponent parent, ActivitiesController controller, Extensions extensions, PrintWriter out, PrintWriter err, Reader in) {
|
||||
public NBDefaultSceneFixtures(ScenarioParams params, NBComponent parent, ActivitiesController controller, Extensions extensions, PrintWriter out, PrintWriter err, Reader in) {
|
||||
this.params = params;
|
||||
this.session = parent;
|
||||
this.controller = controller;
|
||||
@ -80,7 +80,7 @@ public class NBDefaultSceneFixtures implements NBSceneFixtures {
|
||||
|
||||
public static NBSceneFixtures ofDefault(String name) {
|
||||
return new NBDefaultSceneFixtures(
|
||||
new ScriptParams(),
|
||||
new ScenarioParams(),
|
||||
new NBSession(
|
||||
new TestComponent("scene", name), "scene~"+name
|
||||
),
|
||||
@ -94,7 +94,7 @@ public class NBDefaultSceneFixtures implements NBSceneFixtures {
|
||||
|
||||
|
||||
@Override
|
||||
public ScriptParams params() {
|
||||
public ScenarioParams params() {
|
||||
return params;
|
||||
}
|
||||
|
||||
|
@ -23,29 +23,54 @@ import io.nosqlbench.engine.api.scripting.DiagWriter;
|
||||
import io.nosqlbench.engine.api.scripting.InterjectingCharArrayWriter;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.Extensions;
|
||||
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.io.StringReader;
|
||||
|
||||
public class NBSceneBuffer implements NBSceneFixtures {
|
||||
private final NBSceneFixtures fixtures;
|
||||
|
||||
public enum IOType {
|
||||
connected,
|
||||
virtual,
|
||||
traced
|
||||
}
|
||||
private final IOType iotype;
|
||||
private DiagWriter stdoutBuffer;
|
||||
private DiagWriter stderrBuffer;
|
||||
private DiagReader stdinBuffer;
|
||||
|
||||
public NBSceneBuffer(NBSceneFixtures fixtures) {
|
||||
public NBSceneBuffer(NBSceneFixtures fixtures, IOType ioTypes) {
|
||||
this.iotype = ioTypes;
|
||||
this.fixtures = fixtures;
|
||||
stdoutBuffer = new DiagWriter(fixtures.out(), new InterjectingCharArrayWriter(" stdout "));
|
||||
stderrBuffer = new DiagWriter(fixtures.err(), new InterjectingCharArrayWriter(" stderr "));
|
||||
stdinBuffer = new DiagReader(fixtures.in(), " stdin ");
|
||||
|
||||
switch (iotype) {
|
||||
case traced:
|
||||
stdoutBuffer = new DiagWriter(fixtures.out(), new InterjectingCharArrayWriter(" stdout "));
|
||||
stderrBuffer = new DiagWriter(fixtures.err(), new InterjectingCharArrayWriter(" stderr "));
|
||||
stdinBuffer = new DiagReader(fixtures.in(), " stdin ");
|
||||
break;
|
||||
case virtual:
|
||||
stdoutBuffer = new DiagWriter(new InterjectingCharArrayWriter(" stdout "));
|
||||
stderrBuffer = new DiagWriter(new InterjectingCharArrayWriter(" stderr "));
|
||||
stdinBuffer = new DiagReader(new StringReader(""), " stdin ");
|
||||
break;
|
||||
case connected:
|
||||
stdoutBuffer = new DiagWriter(fixtures.out());
|
||||
stderrBuffer = new DiagWriter(fixtures.err());
|
||||
stdinBuffer = new DiagReader(fixtures.in(), " stdin ");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public NBSceneBuffer(NBSceneFixtures fixtures) {
|
||||
this(fixtures, IOType.traced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptParams params() {
|
||||
public ScenarioParams params() {
|
||||
return fixtures.params();
|
||||
}
|
||||
|
||||
@ -79,15 +104,6 @@ public class NBSceneBuffer implements NBSceneFixtures {
|
||||
return stdinBuffer;
|
||||
}
|
||||
|
||||
// public List<String> getTimedLogLines() {
|
||||
// List<String> log = new ArrayList<String>();
|
||||
// Optional.ofNullable(this.stdinBuffer).map(DiagReader::getTimedLog).ifPresent(log::addAll);
|
||||
// Optional.ofNullable(this.stderrBuffer).map(DiagWriter::getTimedLog).ifPresent(log::addAll);
|
||||
// Optional.ofNullable(this.stdoutBuffer).map(DiagWriter::getTimedLog).ifPresent(log::addAll);
|
||||
// log = log.stream().map(l -> l.endsWith("\n") ? l : l+"\n").collect(Collectors.toList());
|
||||
// return log;
|
||||
// }
|
||||
|
||||
public String getIOLog() {
|
||||
return this.stdoutBuffer.getTimedLog()+this.stderrBuffer.getTimedLog();
|
||||
}
|
||||
@ -100,4 +116,8 @@ public class NBSceneBuffer implements NBSceneFixtures {
|
||||
TestComponent root = new TestComponent("scene", "self");
|
||||
return new NBSceneBuffer(NBDefaultSceneFixtures.ofDefault(name));
|
||||
}
|
||||
|
||||
public static SceneBuilderFacets.WantsContext builder() {
|
||||
return new SceneBuilder();
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
|
||||
public interface NBSceneFixtures {
|
||||
ScriptParams params();
|
||||
ScenarioParams params();
|
||||
|
||||
NBComponent component();
|
||||
|
||||
|
@ -32,19 +32,19 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Wrap the script parameters in a type which allows for easy manipulation
|
||||
* Wrap the scenario parameters in a type which allows for easy manipulation
|
||||
*/
|
||||
public class ScriptParams extends HashMap<String, String> implements ProxyObject {
|
||||
public class ScenarioParams extends HashMap<String, String> implements ProxyObject {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ScriptParams.class);
|
||||
private static final Logger logger = LogManager.getLogger(ScenarioParams.class);
|
||||
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
public static ScriptParams of(Map<String,String> params) {
|
||||
return new ScriptParams() {{
|
||||
public static ScenarioParams of(Map<String,String> params) {
|
||||
return new ScenarioParams() {{
|
||||
putAll(params);
|
||||
}};
|
||||
}
|
||||
public ScriptParams withOverrides(Object overrides) {
|
||||
public ScenarioParams withOverrides(Object overrides) {
|
||||
Map<String, String> map;
|
||||
if (overrides instanceof Map) {
|
||||
map = (Map) overrides;
|
||||
@ -60,7 +60,7 @@ public class ScriptParams extends HashMap<String, String> implements ProxyObject
|
||||
}
|
||||
checkForNulls("params", "calling withOverrides", this);
|
||||
checkForNulls("overrides", "calling withOverrides", map);
|
||||
ScriptParams result = new ScriptParams();
|
||||
ScenarioParams result = new ScenarioParams();
|
||||
result.putAll(this);
|
||||
|
||||
for (Entry<String, String> overrideEntry : map.entrySet()) {
|
||||
@ -76,12 +76,12 @@ public class ScriptParams extends HashMap<String, String> implements ProxyObject
|
||||
logger.trace("Overrode key '" + oKey + "': from '" + was + " to " + oVal);
|
||||
}
|
||||
}
|
||||
ScriptParams p = new ScriptParams();
|
||||
ScenarioParams p = new ScenarioParams();
|
||||
p.putAll(result);
|
||||
return p;
|
||||
}
|
||||
|
||||
public ScriptParams withDefaults(Object defaults) {
|
||||
public ScenarioParams withDefaults(Object defaults) {
|
||||
Map<String, String> map;
|
||||
if (defaults instanceof Map) {
|
||||
map = (Map) defaults;
|
||||
@ -94,12 +94,12 @@ public class ScriptParams extends HashMap<String, String> implements ProxyObject
|
||||
logger.warn("A null map was provided to withDefaults. This could be a bug in your script.");
|
||||
map = Map.of();
|
||||
}
|
||||
ScriptParams result = new ScriptParams();
|
||||
ScenarioParams result = new ScenarioParams();
|
||||
checkForNulls("params", "calling withDefaults", this);
|
||||
checkForNulls("defaults", "calling withDefaults", map);
|
||||
result.putAll(map);
|
||||
result.putAll(this);
|
||||
ScriptParams p = new ScriptParams();
|
||||
ScenarioParams p = new ScenarioParams();
|
||||
p.putAll(result);
|
||||
return p;
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package io.nosqlbench.engine.core.lifecycle.scenario.context;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.Extensions;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.util.Map;
|
||||
|
||||
public class SceneBuilder implements SceneBuilderFacets.ALL {
|
||||
private Map<String,String> params;
|
||||
private ActivitiesController controller;
|
||||
private Extensions extensions;
|
||||
private PrintWriter out;
|
||||
private PrintWriter err;
|
||||
private Reader in;
|
||||
private NBComponent component;
|
||||
private NBSceneBuffer.IOType iotype;
|
||||
|
||||
|
||||
@Override
|
||||
public SceneBuilder component(NBComponent component) {
|
||||
this.component = component;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NBSceneBuffer build() {
|
||||
NBDefaultSceneFixtures fixtures =
|
||||
new NBDefaultSceneFixtures(
|
||||
ScenarioParams.of(this.params),
|
||||
this.component,
|
||||
((this.controller!=null) ? this.controller : new ActivitiesController(component)),
|
||||
this.extensions,
|
||||
this.out,
|
||||
this.err,
|
||||
this.in);
|
||||
return new NBSceneBuffer(fixtures,iotype);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SceneBuilder controller(ActivitiesController controller) {
|
||||
this.controller = controller;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBuilder out(PrintWriter out) {
|
||||
this.out = out;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBuilder err(PrintWriter err) {
|
||||
this.err = err;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBuilder in(Reader in) {
|
||||
this.in = in;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBuilder extensions(Extensions extensions) {
|
||||
this.extensions = extensions;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBuilder params(Map<String, String> params) {
|
||||
this.params=params;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBuilderFacets.WantsExtensions virtualIO() {
|
||||
this.iotype= NBSceneBuffer.IOType.virtual;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBuilderFacets.WantsExtensions connectedIO() {
|
||||
this.iotype = NBSceneBuffer.IOType.connected;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBuilderFacets.WantsExtensions tracedIO() {
|
||||
this.iotype=NBSceneBuffer.IOType.traced;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package io.nosqlbench.engine.core.lifecycle.scenario.context;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.Extensions;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SceneBuilderFacets {
|
||||
public interface ALL extends
|
||||
WantsContext,
|
||||
WantsController,
|
||||
WantsExtensions,
|
||||
WantsStderr,
|
||||
WantsStdout,
|
||||
WantsStdin,
|
||||
WantsParams,
|
||||
CanBuild,
|
||||
WantsIoType {
|
||||
}
|
||||
|
||||
|
||||
public interface WantsContext {
|
||||
public WantsController component(NBComponent component);
|
||||
}
|
||||
|
||||
public interface WantsController extends WantsStdin, WantsIoType {
|
||||
public WantsStdin controller(ActivitiesController controller);
|
||||
}
|
||||
|
||||
|
||||
public interface WantsStdin extends WantsIoType {
|
||||
public WantsStdout in(Reader in);
|
||||
}
|
||||
|
||||
public interface WantsStdout extends CanBuild {
|
||||
public WantsStderr out(PrintWriter out);
|
||||
}
|
||||
|
||||
public interface WantsStderr extends CanBuild {
|
||||
public WantsExtensions err(PrintWriter err);
|
||||
}
|
||||
|
||||
public interface WantsIoType extends CanBuild {
|
||||
/**
|
||||
* If you want the stdin, stdout, stderr streams to be contained only within the scenario's
|
||||
* execution environment, not connected to the outside world, do this.
|
||||
*/
|
||||
public WantsExtensions virtualIO();
|
||||
|
||||
/**
|
||||
* If you want to connect stdin, stdout, stderr streams to the system in, out and error streams,
|
||||
* do this.
|
||||
*/
|
||||
public WantsExtensions connectedIO();
|
||||
|
||||
/**
|
||||
* If you want to connect the console IO streams to the outside world, but also capture them for
|
||||
* diagnostics or other purposes, do this.
|
||||
*/
|
||||
public WantsExtensions tracedIO();
|
||||
}
|
||||
|
||||
public interface WantsExtensions extends CanBuild {
|
||||
public WantsParams extensions(Extensions extensions);
|
||||
}
|
||||
|
||||
public interface WantsParams extends CanBuild {
|
||||
public CanBuild params(Map<String, String> params);
|
||||
}
|
||||
|
||||
public interface CanBuild {
|
||||
NBSceneBuffer build();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,12 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.nbr.examples;
|
||||
package io.nosqlbench.engine.core.lifecycle.scenario.direct;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ActivitiesController;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScriptParams;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScenarioParams;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.Extensions;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
@ -32,7 +33,8 @@ public abstract class SCBaseScenario extends NBScenario {
|
||||
protected PrintWriter stdout;
|
||||
protected Writer stderr;
|
||||
protected ActivitiesController controller;
|
||||
protected ScriptParams params;
|
||||
protected ScenarioParams params;
|
||||
protected Extensions extensions;
|
||||
|
||||
public SCBaseScenario(NBComponent parentComponent, String scenarioName) {
|
||||
super(parentComponent, scenarioName);
|
||||
@ -46,9 +48,25 @@ public abstract class SCBaseScenario extends NBScenario {
|
||||
this.stderr = shell.err();
|
||||
this.controller = shell.controller();
|
||||
this.params = shell.params();
|
||||
this.extensions = shell.extensions();
|
||||
invoke();
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses must implement this method, which emulates the scope
|
||||
* of previous scenario scripts. Within this method, local
|
||||
* fields will be available directly:
|
||||
* <UL>
|
||||
* <LI>component, an {@link NBComponent} - The NB component upon which all metrics or other services are attached.</LI>
|
||||
* <LI>stdin - a {@link Reader} representing the input buffer which would normally be {@link System#in}
|
||||
* <LI>stdout, stderr</LI>- a {@link PrintWriter}; This can be buffered virtually, attached to {@link System#out} and {@link System#err} or both for IO tracing.</LI>
|
||||
* <LI>controller - A dedicated {@link ActivitiesController} which can be used to define, start, top, and interact with activities.</LI>
|
||||
* <LI>params - The {@link ScenarioParams} which have been passed to this scenario.</LI>
|
||||
* <LI>extensions - A dedicated ahndle to the {@link Extensions} service.</LI>
|
||||
* <LI><EM>all component services</EM> as this scenario IS a component. This includes all implemented methods in any of the {@link NBComponent} sub-interfaces.</EM>
|
||||
* </LI>
|
||||
* </UL>
|
||||
*/
|
||||
public abstract void invoke();
|
||||
|
||||
}
|
@ -26,6 +26,7 @@ import io.nosqlbench.engine.core.lifecycle.scenario.context.*;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.ScenarioExceptionHandler;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
@ -56,17 +57,7 @@ public class ScenariosExecutor extends NBBaseComponent {
|
||||
throw new BasicError("Scenario " + scenario.getScenarioName() + " is already defined. Remove it first to reuse the name.");
|
||||
}
|
||||
|
||||
NBSceneFixtures basecontext = new NBDefaultSceneFixtures(
|
||||
ScriptParams.of(params),
|
||||
this.getParent(),
|
||||
new ActivitiesController(this),
|
||||
loadExtensions(),
|
||||
new PrintWriter(System.out),
|
||||
new PrintWriter(System.err),
|
||||
new InputStreamReader(System.in)
|
||||
);
|
||||
NBSceneBuffer bufferedContext = new NBSceneBuffer(basecontext);
|
||||
|
||||
NBSceneBuffer bufferedContext = getNbSceneBuffer(params);
|
||||
Future<ScenarioResult> future = executor.submit(
|
||||
() -> scenario.apply(bufferedContext) // combine basic execution data with trace
|
||||
);
|
||||
@ -75,6 +66,16 @@ public class ScenariosExecutor extends NBBaseComponent {
|
||||
// TODO at this point, bufferedContext holds all the trace, make it visible in results
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private NBSceneBuffer getNbSceneBuffer(Map<String, String> params) {
|
||||
return NBSceneBuffer.builder()
|
||||
.component(this.getParent())
|
||||
.tracedIO()
|
||||
.extensions(loadExtensions())
|
||||
.params(params)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
@ -174,7 +175,7 @@ public class ScenariosExecutor extends NBBaseComponent {
|
||||
} catch (Exception e) {
|
||||
long now = System.currentTimeMillis();
|
||||
logger.debug("creating exceptional scenario result from getAsyncResultStatus");
|
||||
throw new RuntimeException("replace with a proper error type");
|
||||
throw new RuntimeException("replace with a proper error type: " + e.toString(),e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,5 +293,8 @@ public class ScenariosExecutor extends NBBaseComponent {
|
||||
return extensions;
|
||||
}
|
||||
|
||||
public ScenarioResult run(NBScenario scenario, Map<String,String> params) {
|
||||
return scenario.apply(getNbSceneBuffer(params));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,12 +16,11 @@
|
||||
package io.nosqlbench.engine.core.lifecycle.scenario.script;
|
||||
|
||||
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
||||
import io.nosqlbench.engine.core.lifecycle.activity.ActivitiesProgressIndicator;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScriptParams;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScenarioParams;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.bindings.PolyglotScenarioController;
|
||||
import org.graalvm.polyglot.Context;
|
||||
@ -65,7 +64,7 @@ public class NBScriptedScenario extends NBScenario {
|
||||
private String progressInterval = "console:1m";
|
||||
// private ScenarioScriptShell scriptEnv;
|
||||
private final String scenarioName;
|
||||
private ScriptParams scenarioScriptParams;
|
||||
private ScenarioParams scenarioScenarioParams;
|
||||
private final Engine engine = Engine.Graalvm;
|
||||
private long startedAtMillis = -1L;
|
||||
private long endedAtMillis = -1L;
|
||||
|
@ -26,7 +26,7 @@ import io.nosqlbench.engine.cli.Cmd;
|
||||
import io.nosqlbench.engine.cli.ScriptBuffer;
|
||||
import io.nosqlbench.engine.core.lifecycle.ExecutionResult;
|
||||
import io.nosqlbench.engine.core.lifecycle.process.NBCLIErrorHandler;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScriptParams;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScenarioParams;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosExecutor;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosResults;
|
||||
@ -124,8 +124,8 @@ public class NBSession extends NBBaseComponent implements Function<List<Cmd>, Ex
|
||||
final ScriptBuffer buffer = new BasicScriptBuffer().add(cmds.toArray(new Cmd[0]));
|
||||
final String scriptData = buffer.getParsedScript();
|
||||
|
||||
final ScriptParams scriptParams = new ScriptParams();
|
||||
scriptParams.putAll(buffer.getCombinedParams());
|
||||
final ScenarioParams scenarioParams = new ScenarioParams();
|
||||
scenarioParams.putAll(buffer.getCombinedParams());
|
||||
|
||||
final NBScriptedScenario scenario = new NBScriptedScenario(sessionName, this);
|
||||
|
||||
@ -139,10 +139,21 @@ public class NBSession extends NBBaseComponent implements Function<List<Cmd>, Ex
|
||||
}
|
||||
Cmd javacmd = cmds.get(0);
|
||||
String mainClass = javacmd.getArg("main_class");
|
||||
SimpleServiceLoader<NBScenario> loader = new SimpleServiceLoader<>(NBScenario.class, Maturity.Any);
|
||||
List<SimpleServiceLoader.Component<? extends NBScenario>> namedProviders = loader.getNamedProviders(mainClass);
|
||||
SimpleServiceLoader.Component<? extends NBScenario> provider = namedProviders.get(0);
|
||||
Class<? extends NBScenario> type = provider.provider.type();
|
||||
|
||||
// This doesn't work as expected; The newest service loader docs are vague about Provider and no-args ctor requirements
|
||||
// and the code suggests that you still have to have one unless you are in a named module
|
||||
// SimpleServiceLoader<NBScenario> loader = new SimpleServiceLoader<>(NBScenario.class, Maturity.Any);
|
||||
// List<SimpleServiceLoader.Component<? extends NBScenario>> namedProviders = loader.getNamedProviders(mainClass);
|
||||
// SimpleServiceLoader.Component<? extends NBScenario> provider = namedProviders.get(0);
|
||||
// Class<? extends NBScenario> type = provider.provider.type();
|
||||
|
||||
Class<NBScenario> type;
|
||||
try {
|
||||
type = (Class<NBScenario>) Class.forName(mainClass);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Constructor<? extends NBScenario> constructor = type.getConstructor(NBComponent.class, String.class);
|
||||
NBScenario scenario = constructor.newInstance(this, sessionName);
|
||||
|
@ -15,7 +15,7 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<Configuration status="debug" strict="true" name="XMLConfigTest">
|
||||
<Configuration status="warn" strict="true" name="XMLConfigTest">
|
||||
|
||||
<Filter type="ThresholdFilter" level="trace"/>
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
package io.nosqlbench.engine.core.lifecycle.scenario.context;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SceneBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testBuildDefaultScene() {
|
||||
NBSceneBuffer buffer = NBSceneBuffer.builder()
|
||||
.component(new TestComponent("test", "test"))
|
||||
.tracedIO()
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.engine.core.script;
|
||||
|
||||
import io.nosqlbench.api.errors.BasicError;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScriptParams;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScenarioParams;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -25,11 +25,11 @@ import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
public class ScriptParamsTest {
|
||||
public class ScenarioParamsTest {
|
||||
|
||||
@Test
|
||||
public void testThatNullOverridesKeyThrowsBasicError() {
|
||||
ScriptParams p = new ScriptParams();
|
||||
ScenarioParams p = new ScenarioParams();
|
||||
p.put("a","b");
|
||||
p.withDefaults(Map.of("c","d"));
|
||||
HashMap<String, String> overrides = new HashMap<>();
|
@ -36,7 +36,7 @@ import java.util.stream.Collectors;
|
||||
* <pre>classes/META-INF/services/servicename</pre> file for each
|
||||
* implemented and annotated service name.
|
||||
*/
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_17)
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_21)
|
||||
public class ServiceProcessor extends AbstractProcessor {
|
||||
public final static String SERVICE_NAME = Service.class.getCanonicalName();
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class TestComponent extends NBBaseComponent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return description();
|
||||
return "TestComponent #"+hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,4 +64,5 @@ public class TestComponent extends NBBaseComponent {
|
||||
public void beforeDetach() {
|
||||
// logger.debug("before detach " + description());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class CsvReporter extends PeriodicTaskComponent {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
List<NBMetric> metrics = component.findMetricsInTree("");
|
||||
List<NBMetric> metrics = component.find().metrics();
|
||||
final long timestamp = TimeUnit.MILLISECONDS.toSeconds(clock.getTime());
|
||||
for (NBMetric metric : metrics) {
|
||||
if (metric instanceof Gauge<?>) {
|
||||
|
@ -110,7 +110,7 @@ public class PromPushReporterComponent extends PeriodicTaskComponent implements
|
||||
StringBuilder sb = new StringBuilder(1024 * 1024); // 1M pre-allocated to reduce heap churn
|
||||
|
||||
int total = 0;
|
||||
for (final Object metric : getParent().findMetricsInTree("")) {
|
||||
for (final Object metric : getParent().find().metrics()) {
|
||||
sb = PromExpositionFormat.format(nowclock, sb, metric);
|
||||
total++;
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public class AttachedMetricsPushReporter extends NBBaseComponent implements NBCo
|
||||
StringBuilder sb = new StringBuilder(1024 * 1024); // 1M pre-allocated to reduce heap churn
|
||||
List<NBMetric> metrics = new ArrayList<>();
|
||||
Iterator<NBComponent> allMetrics = NBComponentTraversal.traverseBreadth(getParent());
|
||||
allMetrics.forEachRemaining(m -> metrics.addAll(m.findMetrics("")));
|
||||
allMetrics.forEachRemaining(m -> metrics.addAll(m.findComponentMetrics("")));
|
||||
|
||||
int total = 0;
|
||||
for (NBMetric metric : metrics) {
|
||||
|
@ -42,7 +42,7 @@ public class AttachedMetricsSummaryReporter extends PeriodicTaskComponent {
|
||||
StringBuilder sb = new StringBuilder(1024 * 1024); // 1M pre-allocated to reduce heap churn
|
||||
List<NBMetric> metrics = new ArrayList<>();
|
||||
Iterator<NBComponent> allMetrics = NBComponentTraversal.traverseBreadth(getParent());
|
||||
allMetrics.forEachRemaining(m -> metrics.addAll(m.findMetrics("")));
|
||||
allMetrics.forEachRemaining(m -> metrics.addAll(m.findComponentMetrics("")));
|
||||
|
||||
int total = 0;
|
||||
for (NBMetric metric : metrics) {
|
||||
|
@ -82,38 +82,6 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone
|
||||
return effectiveLabels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBMetric lookupMetricInTree(String name) {
|
||||
Iterator<NBComponent> tree = NBComponentTraversal.traverseBreadth(this);
|
||||
while (tree.hasNext()) {
|
||||
NBComponent c = tree.next();
|
||||
NBMetric metric = c.lookupMetric(name);
|
||||
if (metric != null) return metric;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NBMetric> findMetricsInTree(String pattern) {
|
||||
Iterator<NBComponent> tree = NBComponentTraversal.traverseBreadth(this);
|
||||
List<NBMetric> found = new ArrayList<>();
|
||||
while (tree.hasNext()) {
|
||||
NBComponent c = tree.next();
|
||||
found.addAll(c.findMetrics(pattern));
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBMetric findOneMetricInTree(String pattern) {
|
||||
List<NBMetric> found = findMetricsInTree(pattern);
|
||||
if (found.size() != 1) {
|
||||
System.out.println("Runtime Components and Metrics at this time:\n" + NBComponentFormats.formatAsTree(this));
|
||||
throw new RuntimeException("Found " + found.size() + " metrics with pattern '" + pattern + "', expected exactly 1");
|
||||
}
|
||||
return found.get(0);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeDetach() {
|
||||
@ -156,4 +124,17 @@ public class NBBaseComponent extends NBBaseComponentMetrics implements NBCompone
|
||||
public NBFinders find() {
|
||||
return new NBFinders(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
if (getComponentMetrics().size()>0) {
|
||||
sb.append(System.lineSeparator()).append("metrics:");
|
||||
for (NBMetric componentMetric : getComponentMetrics()) {
|
||||
sb.append(System.lineSeparator()).append("m ").append(componentMetric.toString());
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -19,17 +19,19 @@ package io.nosqlbench.components;
|
||||
import io.nosqlbench.adapters.api.util.TagFilter;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class NBBaseComponentMetrics implements NBComponentMetrics {
|
||||
private final Lock lock = new ReentrantLock(false);
|
||||
private final Map<String, NBMetric> metrics = new HashMap<>();
|
||||
private final Map<String, NBMetric> metrics = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public String addMetric(NBMetric metric) {
|
||||
public String addComponentMetric(NBMetric metric) {
|
||||
try {
|
||||
lock.lock();
|
||||
String openMetricsName = metric.getLabels().linearizeAsMetrics();
|
||||
@ -43,13 +45,18 @@ public class NBBaseComponentMetrics implements NBComponentMetrics {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public NBMetric lookupMetric(String name) {
|
||||
public NBMetric getComponentMetric(String name) {
|
||||
return metrics.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NBMetric> findMetrics(String pattern) {
|
||||
public List<NBMetric> findComponentMetrics(String pattern) {
|
||||
TagFilter filter = new TagFilter(pattern);
|
||||
return filter.filterLabeled(metrics.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends NBMetric> getComponentMetrics() {
|
||||
return metrics.values();
|
||||
}
|
||||
}
|
||||
|
@ -60,14 +60,14 @@ public class NBBuilders {
|
||||
public NBMetricTimer timer(String metricFamilyName, int hdrdigits) {
|
||||
NBLabels labels = base.getLabels().and("name", metricFamilyName);
|
||||
NBMetricTimer timer = new NBMetricTimer(labels, new DeltaHdrHistogramReservoir(labels, hdrdigits));
|
||||
base.addMetric(timer);
|
||||
base.addComponentMetric(timer);
|
||||
return timer;
|
||||
}
|
||||
|
||||
public Meter meter(String metricFamilyName) {
|
||||
NBLabels labels = base.getLabels().and("name", metricFamilyName);
|
||||
NBMetricMeter meter = new NBMetricMeter(labels);
|
||||
base.addMetric(meter);
|
||||
base.addComponentMetric(meter);
|
||||
return meter;
|
||||
}
|
||||
|
||||
@ -75,14 +75,14 @@ public class NBBuilders {
|
||||
public NBMetricCounter counter(String metricFamilyName) {
|
||||
NBLabels labels = base.getLabels().and("name", metricFamilyName);
|
||||
NBMetricCounter counter = new NBMetricCounter(labels);
|
||||
base.addMetric(counter);
|
||||
base.addComponentMetric(counter);
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
public NBFunctionGauge gauge(String metricFamilyName, Supplier<Double> valueSource) {
|
||||
NBFunctionGauge gauge = new NBFunctionGauge(base, valueSource, metricFamilyName);
|
||||
base.addMetric(gauge);
|
||||
base.addComponentMetric(gauge);
|
||||
return gauge;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ public class NBBuilders {
|
||||
DoubleSummaryGauge anyGauge = null;
|
||||
for (DoubleSummaryGauge.Stat stat : stats) {
|
||||
anyGauge = new DoubleSummaryGauge(base.getLabels().and(NBLabels.forKV("name",name,"stat", stat)), stat, reservoir);
|
||||
base.addMetric(anyGauge);
|
||||
base.addComponentMetric(anyGauge);
|
||||
}
|
||||
return anyGauge;
|
||||
}
|
||||
@ -104,7 +104,7 @@ public class NBBuilders {
|
||||
public NBMetricHistogram histogram(String metricFamilyName, int hdrdigits) {
|
||||
NBLabels labels = base.getLabels().and("name", metricFamilyName);
|
||||
NBMetricHistogram histogram = new NBMetricHistogram(labels, new DeltaHdrHistogramReservoir(labels, hdrdigits));
|
||||
base.addMetric(histogram);
|
||||
base.addComponentMetric(histogram);
|
||||
return histogram;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ import java.util.List;
|
||||
*
|
||||
* This interface includes more aspects of above by extension going forward.
|
||||
*/
|
||||
public interface NBComponent extends AutoCloseable, NBLabeledElement, NBComponentMetrics, NBMetricsQuery, NBComponentServices {
|
||||
public interface NBComponent extends AutoCloseable, NBLabeledElement, NBComponentMetrics, NBComponentServices {
|
||||
|
||||
NBComponent EMPTY_COMPONENT = new NBBaseComponent(null);
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class NBComponentFormats {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private final static class PrintVisitor implements NBComponentTraversal.Visitor {
|
||||
protected final static class PrintVisitor implements NBComponentTraversal.Visitor {
|
||||
|
||||
private final StringBuilder builder;
|
||||
|
||||
@ -36,7 +36,14 @@ public class NBComponentFormats {
|
||||
|
||||
@Override
|
||||
public void visit(NBComponent component, int depth) {
|
||||
builder.append(String.format("%03d %s\n",depth,component));
|
||||
String indent = " ".repeat(depth);
|
||||
builder.append(indent).append(String.format("%03d %s",depth,component.description()));
|
||||
String string = component.toString();
|
||||
String[] split = string.split(System.lineSeparator());
|
||||
for (String s : split) {
|
||||
builder.append(System.lineSeparator()).append(indent).append(" >").append(s);
|
||||
}
|
||||
builder.append(System.lineSeparator());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,19 @@ package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* This is the stateful store of metrics on a specific component in the hierarchy.
|
||||
* Mostly, these methods provide the internal logic needed to support easier
|
||||
* access to metrics via {@link NBComponentServices}.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface NBComponentMetrics {
|
||||
String addMetric(NBMetric metric);
|
||||
String addComponentMetric(NBMetric metric);
|
||||
|
||||
/**
|
||||
* If you have the serialized open metrics name of a metric, you can ask for it
|
||||
@ -30,20 +38,17 @@ public interface NBComponentMetrics {
|
||||
* @param name The name of a metric in {@code {a:"b",...}} form
|
||||
* @return the metric or null if it dosen't exist
|
||||
*/
|
||||
NBMetric lookupMetric(String name);
|
||||
NBMetric getComponentMetric(String name);
|
||||
|
||||
default Optional<NBMetric> lookupMetricOptionally(String name) {
|
||||
return Optional.ofNullable(lookupMetric(name));
|
||||
}
|
||||
List<NBMetric> findComponentMetrics(String pattern);
|
||||
|
||||
List<NBMetric> findMetrics(String pattern);
|
||||
|
||||
default NBMetric findOneMetric(String pattern) {
|
||||
List<NBMetric> found = findMetrics(pattern);
|
||||
default NBMetric findOneComponentMetric(String pattern) {
|
||||
List<NBMetric> found = findComponentMetrics(pattern);
|
||||
if (found.size()!=1) {
|
||||
throw new RuntimeException("Found " + found.size() + " metrics with pattern '" + pattern + "', expected exactly 1");
|
||||
}
|
||||
return found.get(0);
|
||||
}
|
||||
|
||||
Collection<? extends NBMetric> getComponentMetrics();
|
||||
}
|
||||
|
@ -16,9 +16,11 @@
|
||||
|
||||
package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricCounter;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricGauge;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class NBFinders {
|
||||
private final NBBaseComponent base;
|
||||
@ -28,12 +30,16 @@ public class NBFinders {
|
||||
}
|
||||
|
||||
public NBMetric metric(String pattern) {
|
||||
NBMetric metric = base.lookupMetricInTree(pattern);
|
||||
if (metric!=null) { return metric; };
|
||||
metric = base.findOneMetricInTree(pattern);
|
||||
return metric;
|
||||
return oneMetricInTree(pattern);
|
||||
}
|
||||
private <T extends NBMetric> T findOneMetricWithType(String pattern, Class<T> clazz) {
|
||||
public List<NBMetric> metrics(String pattern) {
|
||||
return this.metricsInTree(pattern);
|
||||
}
|
||||
public List<NBMetric> metrics() {
|
||||
return this.metricsInTree();
|
||||
}
|
||||
|
||||
private <T extends NBMetric> T oneMetricWithType(String pattern, Class<T> clazz) {
|
||||
NBMetric found = metric(pattern);
|
||||
if (found==null) {
|
||||
System.out.println(NBComponentFormats.formatAsTree(base));
|
||||
@ -52,13 +58,65 @@ public class NBFinders {
|
||||
}
|
||||
|
||||
|
||||
public NBMetricGauge metricGauge(String pattern) {
|
||||
return findOneMetricWithType(pattern, NBMetricGauge.class);
|
||||
public NBMetricGauge gauge(String pattern) {
|
||||
return oneMetricWithType(pattern, NBMetricGauge.class);
|
||||
}
|
||||
|
||||
public NBMetricCounter metricCounter(String pattern) {
|
||||
return findOneMetricWithType(pattern, NBMetricCounter.class);
|
||||
public NBMetricCounter counter(String pattern) {
|
||||
return oneMetricWithType(pattern, NBMetricCounter.class);
|
||||
}
|
||||
|
||||
public NBMetricTimer timer(String pattern) {
|
||||
return oneMetricWithType(pattern, NBMetricTimer.class);
|
||||
}
|
||||
|
||||
public NBMetricHistogram histogram(String pattern) {
|
||||
return oneMetricWithType(pattern, NBMetricHistogram.class);
|
||||
}
|
||||
|
||||
public NBMetricMeter meter(String pattern) {
|
||||
return oneMetricWithType(pattern,NBMetricMeter.class);
|
||||
}
|
||||
|
||||
// public NBMetric firstMetricInTree(String name) {
|
||||
// Iterator<NBComponent> tree = NBComponentTraversal.traverseBreadth(base);
|
||||
// while (tree.hasNext()) {
|
||||
// NBComponent c = tree.next();
|
||||
// NBMetric metric = base.getComponentMetric(name);
|
||||
// if (metric != null) return metric;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
private List<NBMetric> metricsInTree() {
|
||||
Iterator<NBComponent> tree = NBComponentTraversal.traverseBreadth(base);
|
||||
List<NBMetric> found = new ArrayList<>();
|
||||
while (tree.hasNext()) {
|
||||
NBComponent c = tree.next();
|
||||
found.addAll(c.getComponentMetrics());
|
||||
}
|
||||
return found;
|
||||
}
|
||||
private List<NBMetric> metricsInTree(String pattern) {
|
||||
if (pattern.isEmpty()) {
|
||||
throw new RuntimeException("non-empty predicate is required for this form. Perhaps you wanted metricsInTree()");
|
||||
}
|
||||
Iterator<NBComponent> tree = NBComponentTraversal.traverseBreadth(base);
|
||||
List<NBMetric> found = new ArrayList<>();
|
||||
while (tree.hasNext()) {
|
||||
NBComponent c = tree.next();
|
||||
found.addAll(c.findComponentMetrics(pattern));
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private NBMetric oneMetricInTree(String pattern) {
|
||||
List<NBMetric> found = metricsInTree(pattern);
|
||||
if (found.size() != 1) {
|
||||
System.out.println("Runtime Components and Metrics at this time:\n" + NBComponentFormats.formatAsTree(base));
|
||||
throw new RuntimeException("Found " + found.size() + " metrics with pattern '" + pattern + "', expected exactly 1");
|
||||
}
|
||||
return found.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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.components;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface NBMetricsQuery {
|
||||
|
||||
/**
|
||||
* If you have the serialized open metrics name of a metric, you can ask for it
|
||||
* this way and get a direct result.
|
||||
* @param name The name of a metric in {@code {a:"b",...}} form
|
||||
* @return the metric or null if it dosen't exist
|
||||
*/
|
||||
NBMetric lookupMetricInTree(String name);
|
||||
|
||||
default Optional<NBMetric> lookupMetricOptionallyInTree(String name) {
|
||||
return Optional.ofNullable(lookupMetricInTree(name));
|
||||
}
|
||||
|
||||
List<NBMetric> findMetricsInTree(String pattern);
|
||||
|
||||
NBMetric findOneMetricInTree(String pattern);
|
||||
|
||||
}
|
@ -39,8 +39,8 @@ public class DiagWriter extends PrintWriter {
|
||||
Writer wrapped;
|
||||
InterjectingCharArrayWriter buffer;
|
||||
|
||||
public DiagWriter(Writer wrapped, InterjectingCharArrayWriter buffer) {
|
||||
super(new FanWriter(buffer,wrapped));
|
||||
public DiagWriter(Writer... writers) {
|
||||
super(new FanWriter(writers));
|
||||
this.wrapped = wrapped;
|
||||
this.buffer = buffer;
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.config.standard;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestComponentViewTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testDiagnosticView() {
|
||||
NBComponent root = new TestComponent("rootk","rootv");
|
||||
TestComponent tc = new TestComponent(root, "atest", "view");
|
||||
String string = tc.toString();
|
||||
assertThat(string).isEqualTo("TestComponent #1305486145");
|
||||
}
|
||||
|
||||
}
|
@ -30,22 +30,22 @@ class NBBaseComponentMetricsTest {
|
||||
void testBasicAddAndLookup() {
|
||||
NBBaseComponentMetrics cm = new NBBaseComponentMetrics();
|
||||
NBMetric m1 = new NBBaseMetric("k","20");
|
||||
String m1Handle = cm.addMetric(m1);
|
||||
String m1Handle = cm.addComponentMetric(m1);
|
||||
NBMetric m2 = new NBBaseMetric("k","27","l","62");
|
||||
String m2Handle = cm.addMetric(m2);
|
||||
String m2Handle = cm.addComponentMetric(m2);
|
||||
|
||||
assertThat(cm.lookupMetric(m1Handle)).isEqualTo(m1);
|
||||
assertThat(cm.lookupMetric(m2Handle)).isEqualTo(m2);
|
||||
assertThat(cm.getComponentMetric(m1Handle)).isEqualTo(m1);
|
||||
assertThat(cm.getComponentMetric(m2Handle)).isEqualTo(m2);
|
||||
}
|
||||
@Test
|
||||
void find() {
|
||||
NBBaseComponentMetrics cm = new NBBaseComponentMetrics();
|
||||
NBMetric m1 = new NBBaseMetric("k","20");
|
||||
String m1Handle = cm.addMetric(m1);
|
||||
String m1Handle = cm.addComponentMetric(m1);
|
||||
NBMetric m2 = new NBBaseMetric("k","27","l","62");
|
||||
String m2Handle = cm.addMetric(m2);
|
||||
String m2Handle = cm.addComponentMetric(m2);
|
||||
|
||||
assertThat(cm.findMetrics("k=27")).isEqualTo(List.of(m2));
|
||||
assertThat(cm.findMetrics("k=20")).isNotEqualTo(List.of(m2));
|
||||
assertThat(cm.findComponentMetrics("k=27")).isEqualTo(List.of(m2));
|
||||
assertThat(cm.findComponentMetrics("k=20")).isNotEqualTo(List.of(m2));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.components;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
public class NBComponentFormatsTest {
|
||||
|
||||
@Test
|
||||
public void testFormat() {
|
||||
NBComponent root = new TestComponent("rootk","rootv");
|
||||
TestComponent tc = new TestComponent(root, "atest", "view");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
NBComponentFormats.PrintVisitor visitor = new NBComponentFormats.PrintVisitor(sb);
|
||||
visitor.visit(root,2);
|
||||
visitor.visit(tc,3);
|
||||
String diagview = sb.toString();
|
||||
diagview=diagview.replaceAll("#[0-9]+","#id");
|
||||
assertThat(diagview).isEqualTo("""
|
||||
002 TestComponent {rootk="rootv"}
|
||||
>TestComponent #id
|
||||
003 TestComponent {atest="view",rootk="rootv"}
|
||||
>TestComponent #id
|
||||
""");
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -48,7 +48,7 @@ class NBComponentServicesTest {
|
||||
NBFunctionGauge gauge = b1.create().gauge("test_gauge", () -> 5.2d);
|
||||
String gaugeHandle = gauge.getHandle();
|
||||
|
||||
List<NBMetric> metricsInTree = root.findMetricsInTree("");
|
||||
List<NBMetric> metricsInTree = root.find().metrics();
|
||||
assertThat(metricsInTree).containsAll(List.of(timer1, gauge));
|
||||
metricsInTree.forEach(m -> {
|
||||
System.out.println("metric: " + m.toString());
|
||||
|
@ -31,24 +31,24 @@ class NBMetricsQueryTest {
|
||||
private final static TestComponent root_c2 = new TestComponent(root,"c2","c2");
|
||||
private final static TestComponent root_c3 = new TestComponent(root,"c3","c3");
|
||||
private final static NBMetric m1 = new NBBaseMetric("m1","m1");
|
||||
private final static String m1Handle = root.addMetric(m1);
|
||||
private final static String m1Handle = root.addComponentMetric(m1);
|
||||
private final static NBMetric m2 = new NBBaseMetric("m2","m2");
|
||||
private final static String m2Handle = root_c2.addMetric(m2);
|
||||
private final static String m2Handle = root_c2.addComponentMetric(m2);
|
||||
private final static NBMetric m3 = new NBBaseMetric("m3","m3");
|
||||
private final static String m3Handle = root_c3.addMetric(m3);
|
||||
private final static String m3Handle = root_c3.addComponentMetric(m3);
|
||||
|
||||
@Test
|
||||
public void testFindInTree() {
|
||||
NBMetric expectedM3 = root.findOneMetricInTree("m3:m3");
|
||||
NBMetric expectedM3 = root.find().metric("m3:m3");
|
||||
assertThat(expectedM3).isEqualTo(m3);
|
||||
assertThatThrownBy(() -> root.findOneMetricInTree("m3:m4")).isOfAnyClassIn(RuntimeException.class);
|
||||
assertThatThrownBy(() -> root.find().metric("m3:m4")).isOfAnyClassIn(RuntimeException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindOneInTree() {
|
||||
List<NBMetric> metricsInTree = root.findMetricsInTree("");
|
||||
List<NBMetric> metricsInTree = root.find().metrics();
|
||||
assertThat(metricsInTree).containsExactly(m1, m2, m3);
|
||||
List<NBMetric> m3Only = root.findMetricsInTree("m3:m3");
|
||||
List<NBMetric> m3Only = root.find().metrics("m3:m3");
|
||||
assertThat(m3Only).containsExactly(m3);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<Configuration status="debug" strict="true" name="XMLConfigTest">
|
||||
<Configuration status="warn" strict="true" name="XMLConfigTest">
|
||||
|
||||
<Filter type="ThresholdFilter" level="trace"/>
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<Configuration status="debug" strict="true" name="XMLConfigTest">
|
||||
<Configuration status="warn" strict="true" name="XMLConfigTest">
|
||||
|
||||
<Filter type="ThresholdFilter" level="trace"/>
|
||||
|
||||
|
@ -22,7 +22,6 @@ import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenarioResult;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosExecutor;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.ScenariosResults;
|
||||
import io.nosqlbench.nbr.examples.injava.*;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -145,7 +144,7 @@ public class DirectRuntimeScenarioTests {
|
||||
@Disabled("enable before merge")
|
||||
@Test
|
||||
public void test_SC_optimo() {
|
||||
NBScenario scenario = new SC_optimo(testC,"test_SC_optimo");
|
||||
NBScenario scenario = new SC_optimo_test(testC,"test_SC_optimo");
|
||||
ScenarioResult result = scenario.apply(NBSceneBuffer.init("test_SC_optimo"));
|
||||
System.out.println(result);
|
||||
}
|
||||
|
@ -17,8 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -19,7 +19,7 @@ package io.nosqlbench.nbr.examples.injava;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBScenario;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -17,8 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.cli.Cmd;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -19,7 +19,7 @@ package io.nosqlbench.nbr.examples.injava;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricCounter;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricGauge;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -94,8 +94,8 @@ public class SC_cocycledelay_bursty extends SCBaseScenario {
|
||||
stdout.println("starting activity co_cycle_delay_bursty");
|
||||
controller.start(co_cycle_delay_bursty);
|
||||
|
||||
NBMetricCounter service_time_counter = find().metricCounter("activity=co_cycle_delay_bursty,name=cycles_servicetime");
|
||||
NBMetricGauge wait_time_gauge = find().metricGauge("activity=co_cycle_delay_bursty,name=cycles_waittime");
|
||||
NBMetricCounter service_time_counter = find().counter("activity=co_cycle_delay_bursty,name=cycles_servicetime");
|
||||
NBMetricGauge wait_time_gauge = find().gauge("activity=co_cycle_delay_bursty,name=cycles_waittime");
|
||||
String diagrate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("diagrate").toString();
|
||||
String cyclerate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("cyclerate").toString();
|
||||
//
|
||||
|
@ -19,7 +19,7 @@ package io.nosqlbench.nbr.examples.injava;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricCounter;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricGauge;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -94,8 +94,8 @@ public class SC_cocycledelay_bursty_backup extends SCBaseScenario {
|
||||
stdout.println("starting activity co_cycle_delay_bursty");
|
||||
controller.start(co_cycle_delay_bursty);
|
||||
|
||||
NBMetricCounter service_time_counter = find().metricCounter("activity=co_cycle_delay_bursty,name=cycles_servicetime");
|
||||
NBMetricGauge wait_time_gauge = find().metricGauge("activity=co_cycle_delay_bursty,name=cycles_waittime");
|
||||
NBMetricCounter service_time_counter = find().counter("activity=co_cycle_delay_bursty,name=cycles_servicetime");
|
||||
NBMetricGauge wait_time_gauge = find().gauge("activity=co_cycle_delay_bursty,name=cycles_waittime");
|
||||
String diagrate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("diagrate").toString();
|
||||
String cyclerate = controller.getActivityDef("co_cycle_delay_bursty").getParams().get("cyclerate").toString();
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_cocycledelay_strict extends SCBaseScenario {
|
||||
public SC_cocycledelay_strict(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_cycle_rate extends SCBaseScenario {
|
||||
public SC_cycle_rate(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_cycle_rate_change extends SCBaseScenario {
|
||||
public SC_cycle_rate_change(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_extension_csvmetrics extends SCBaseScenario {
|
||||
public SC_extension_csvmetrics(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_extension_csvoutput extends SCBaseScenario {
|
||||
public SC_extension_csvoutput(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_extension_histostatslogger extends SCBaseScenario {
|
||||
public SC_extension_histostatslogger(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_extension_shutdown_hook extends SCBaseScenario {
|
||||
public SC_extension_shutdown_hook(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_histologger extends SCBaseScenario {
|
||||
public SC_histologger(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_linkedinput extends SCBaseScenario {
|
||||
public SC_linkedinput(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -19,12 +19,12 @@ package io.nosqlbench.nbr.examples.injava;
|
||||
import io.nosqlbench.api.optimizers.BobyqaOptimizerInstance;
|
||||
import io.nosqlbench.api.optimizers.MVResult;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.function.ToDoubleFunction;
|
||||
|
||||
public class SC_optimo extends SCBaseScenario {
|
||||
public SC_optimo(NBComponent parentComponent, String scenarioName) {
|
||||
public class SC_optimo_test extends SCBaseScenario {
|
||||
public SC_optimo_test(NBComponent parentComponent, String scenarioName) {
|
||||
super(parentComponent, scenarioName);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_params_variable extends SCBaseScenario {
|
||||
public SC_params_variable(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_readmetrics extends SCBaseScenario {
|
||||
public SC_readmetrics(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_speedcheck extends SCBaseScenario {
|
||||
public SC_speedcheck(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_template extends SCBaseScenario {
|
||||
public SC_template(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_threadchange extends SCBaseScenario {
|
||||
public SC_threadchange(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
public class SC_threadspeeds extends SCBaseScenario {
|
||||
public SC_threadspeeds(NBComponent parentComponent, String scenarioName) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.nosqlbench.nbr.examples.injava;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nbr.examples.SCBaseScenario;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
100
nbr/src/main/java/io/nosqlbench/scenarios/SC_optimo.java
Normal file
100
nbr/src/main/java/io/nosqlbench/scenarios/SC_optimo.java
Normal file
@ -0,0 +1,100 @@
|
||||
package io.nosqlbench.scenarios;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
import io.nosqlbench.api.optimizers.BobyqaOptimizerInstance;
|
||||
import io.nosqlbench.api.optimizers.MVResult;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.api.activityapi.core.Activity;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.direct.SCBaseScenario;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.ToDoubleFunction;
|
||||
|
||||
public class SC_optimo extends SCBaseScenario {
|
||||
private final static Logger logger = LogManager.getLogger(SC_optimo.class);
|
||||
public SC_optimo(NBComponent parentComponent, String scenarioName) {
|
||||
super(parentComponent, scenarioName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke() {
|
||||
// TODO: having "scenario" here as well as in "named scenario" in workload templates is confusing. Make this clearer.
|
||||
String workload = params.getOrDefault("workload", "default_workload");
|
||||
|
||||
Map<String,String> activityParams = new HashMap<>(Map.of(
|
||||
"cycles", String.valueOf(Long.MAX_VALUE),
|
||||
"threads", "1",
|
||||
"driver", "diag",
|
||||
"rate", "1"
|
||||
));
|
||||
if (params.containsKey("workload")) {
|
||||
activityParams.put("workload",params.get("workload"));
|
||||
} else if (params.containsKey("op")) {
|
||||
activityParams.put("op",params.get("op"));
|
||||
} else {
|
||||
activityParams.put("op","log: level=info");
|
||||
logger.warn("You provided neither a workload nor an op, so assuming diagnostic mode.");
|
||||
}
|
||||
|
||||
Activity flywheel = controller.start(activityParams);
|
||||
|
||||
BobyqaOptimizerInstance bobby = create().bobyqaOptimizer();
|
||||
|
||||
bobby.param("threads", 0.0d, 200000.0d);
|
||||
bobby.param("rate", 0.0d, 1_000_000.d);
|
||||
bobby.setInitialRadius(10000.0).setStoppingRadius(0.001).setMaxEval(1000);
|
||||
|
||||
/**
|
||||
* <P>This function is the objective function, and is responsible for applying
|
||||
* the parameters and yielding a result. The higher the returned result, the
|
||||
* better the parameters are.</P>
|
||||
* <P>The parameter values will be passed in as an array, pair-wise with the param calls above.</P>
|
||||
*/
|
||||
ToDoubleFunction<double[]> f = new ToDoubleFunction<double[]>() {
|
||||
@Override
|
||||
public double applyAsDouble(double[] value) {
|
||||
int threads=(int)value[0];
|
||||
|
||||
NBMetric counter = flywheel.find().counter("counterstuff");
|
||||
|
||||
flywheel.getActivityDef().setThreads(threads);
|
||||
|
||||
double rate=value[1];
|
||||
flywheel.getActivityDef().setCycles(String.valueOf(rate));
|
||||
|
||||
|
||||
return 10000000 - ((Math.abs(100-value[0])) + (Math.abs(100-value[1])));
|
||||
}
|
||||
};
|
||||
bobby.setObjectiveFunction(f);
|
||||
MVResult result = bobby.optimize();
|
||||
stdout.println("optimized result was " + result);
|
||||
stdout.println("map of result was " + result.getMap());
|
||||
|
||||
// TODO: controller start should not return the activity itself, but a control point, like activityDef
|
||||
|
||||
// TODO: warn user if one of the result params is near or at the range allowed, as there
|
||||
// could be a better result if the range is arbitrarily limiting the parameter space.
|
||||
}
|
||||
}
|
36
nbr/src/main/java/io/nosqlbench/scenarios/WindowSampler.java
Normal file
36
nbr/src/main/java/io/nosqlbench/scenarios/WindowSampler.java
Normal file
@ -0,0 +1,36 @@
|
||||
package io.nosqlbench.scenarios;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
public class WindowSampler {
|
||||
private final NBComponent base;
|
||||
|
||||
public WindowSampler(NBComponent component) {
|
||||
this.base = component;
|
||||
component.find().metric("doesnot=exist");
|
||||
}
|
||||
|
||||
public Sample sample() {
|
||||
return new Sample(1.0d,2.0d);
|
||||
}
|
||||
|
||||
public static record Sample(double rate, double p99) { }
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<Configuration status="debug" strict="true" name="XMLConfigTest">
|
||||
<Configuration status="warn" strict="true" name="XMLConfigTest">
|
||||
|
||||
<Filter type="ThresholdFilter" level="trace"/>
|
||||
|
||||
|
@ -40,7 +40,7 @@ import static io.nosqlbench.virtdata.api.processors.ProcessorClassNames.ThreadSa
|
||||
* manifests. It simply calls listener interfaces to do the rest of the work.
|
||||
*/
|
||||
@SupportedOptions({"title"})
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_17)
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_21)
|
||||
@SupportedAnnotationTypes({
|
||||
ThreadSafeMapper,
|
||||
PerThreadMapper
|
||||
|
@ -40,7 +40,7 @@ import static io.nosqlbench.virtdata.api.processors.ProcessorClassNames.ThreadSa
|
||||
* enumerate candidate functions without requiring them to have a no-args constructor.
|
||||
*/
|
||||
@SupportedOptions({"title"})
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_17)
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_21)
|
||||
@SupportedAnnotationTypes({
|
||||
ThreadSafeMapper,
|
||||
PerThreadMapper
|
||||
|
@ -15,7 +15,7 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<Configuration status="debug" strict="true" name="XMLConfigTest">
|
||||
<Configuration status="warn" strict="true" name="XMLConfigTest">
|
||||
|
||||
<Filter type="ThresholdFilter" level="trace"/>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user