mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
partial switchover of metrics from ActivityMetrics
This commit is contained in:
parent
3ec511f61f
commit
4efd428de3
@ -23,6 +23,7 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -33,6 +34,10 @@ import java.util.function.Function;
|
||||
public class AmqpDriverAdapter extends BaseDriverAdapter<AmqpTimeTrackOp, AmqpSpace> {
|
||||
private final static Logger logger = LogManager.getLogger(AmqpDriverAdapter.class);
|
||||
|
||||
public AmqpDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<AmqpTimeTrackOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends AmqpSpace> spaceCache = getSpaceCache();
|
||||
|
@ -61,11 +61,10 @@ public class AmqpAdapterMetrics {
|
||||
"message_size", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
|
||||
// Timer metrics
|
||||
bindTimer =
|
||||
ActivityMetrics.timer(this.amqpBaseOpDispenser,
|
||||
bindTimer = amqpBaseOpDispenser.create().timer(
|
||||
"bind", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
executeTimer =
|
||||
ActivityMetrics.timer(this.amqpBaseOpDispenser,
|
||||
amqpBaseOpDispenser.create().timer(
|
||||
"execute", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
|
||||
// End-to-end metrics
|
||||
|
@ -17,8 +17,12 @@
|
||||
package io.nosqlbench.adapter.cqld4;
|
||||
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
|
||||
@Service(value = DriverAdapter.class, selector = "cql")
|
||||
public class CqlDriverAdapterStub extends Cqld4DriverAdapter {
|
||||
public CqlDriverAdapterStub(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -38,6 +39,10 @@ import java.util.function.Function;
|
||||
public class Cqld4DriverAdapter extends BaseDriverAdapter<Op, Cqld4Space> {
|
||||
private final static Logger logger = LogManager.getLogger(Cqld4DriverAdapter.class);
|
||||
|
||||
public Cqld4DriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<Op> getOpMapper() {
|
||||
DriverSpaceCache<? extends Cqld4Space> spaceCache = getSpaceCache();
|
||||
|
@ -25,6 +25,8 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.decorators.SyntheticOpTemplateProvider;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.components.NBParentComponentInjection;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.api.config.params.NBParams;
|
||||
import io.nosqlbench.api.config.standard.NBConfigModel;
|
||||
@ -45,7 +47,9 @@ public class DiagDriverAdapter extends BaseDriverAdapter<DiagOp, DiagSpace> impl
|
||||
private final static Logger logger = LogManager.getLogger(DiagDriverAdapter.class);
|
||||
private DiagOpMapper mapper;
|
||||
|
||||
public DiagDriverAdapter() {
|
||||
|
||||
public DiagDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
logger.debug("starting up");
|
||||
}
|
||||
|
||||
|
@ -18,12 +18,16 @@ package io.nosqlbench.adapter.diag.optasks;
|
||||
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BaseDiagTask implements DiagTask {
|
||||
private NBLabeledElement parentLabels;
|
||||
private String name;
|
||||
protected NBComponent parent;
|
||||
|
||||
|
||||
@Override
|
||||
public abstract Map<String, Object> apply(Long cycle, Map<String, Object> opstate);
|
||||
@ -51,4 +55,8 @@ public abstract class BaseDiagTask implements DiagTask {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyParentComponent(NBComponent parent) {
|
||||
this.parent=parent;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.adapter.diag.optasks;
|
||||
import io.nosqlbench.api.config.standard.NBConfigurable;
|
||||
import io.nosqlbench.api.config.standard.NBReconfigurable;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.components.NBParentComponentInjection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
@ -44,7 +45,8 @@ import java.util.function.BiFunction;
|
||||
public interface DiagTask extends
|
||||
BiFunction<Long,Map<String,Object>, Map<String,Object>>,
|
||||
NBConfigurable,
|
||||
NBLabeledElement
|
||||
NBLabeledElement,
|
||||
NBParentComponentInjection
|
||||
{
|
||||
Map<String, Object> apply(Long cycle, Map<String, Object> opstate);
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class DiagTask_diagrate extends BaseDiagTask implements NBReconfigurable
|
||||
private void updateRateLimiter(String spec) {
|
||||
this.rateSpec = new RateSpec(spec);
|
||||
rateLimiter = RateLimiters.createOrUpdate(
|
||||
this,
|
||||
this.parent,
|
||||
"diag",
|
||||
rateLimiter,
|
||||
rateSpec
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package io.nosqlbench.adapter.diag.optasks;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.api.config.standard.ConfigModel;
|
||||
import io.nosqlbench.api.config.standard.NBConfigModel;
|
||||
|
@ -21,6 +21,7 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Maturity;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.api.config.standard.NBConfigModel;
|
||||
@ -31,6 +32,10 @@ import java.util.function.Function;
|
||||
@Service(value = DriverAdapter.class, selector = "dynamodb", maturity = Maturity.Experimental)
|
||||
public class DynamoDBDriverAdapter extends BaseDriverAdapter<DynamoDBOp, DynamoDBSpace> {
|
||||
|
||||
public DynamoDBDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<DynamoDBOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends DynamoDBSpace> spaceCache = getSpaceCache();
|
||||
|
@ -26,6 +26,7 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||
@ -39,6 +40,10 @@ import java.util.function.Function;
|
||||
@Service(value = DriverAdapter.class, selector = "http")
|
||||
public class HttpDriverAdapter extends BaseDriverAdapter<HttpOp, HttpSpace> {
|
||||
|
||||
public HttpDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<HttpOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends HttpSpace> spaceCache = getSpaceCache();
|
||||
|
@ -18,6 +18,7 @@ package io.nosqlbench.adapter.http;
|
||||
|
||||
import io.nosqlbench.adapter.http.core.HttpOpMapper;
|
||||
import io.nosqlbench.adapter.http.core.HttpSpace;
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.adapters.api.activityconfig.OpsLoader;
|
||||
@ -26,6 +27,7 @@ import io.nosqlbench.adapters.api.activityconfig.yaml.OpTemplateFormat;
|
||||
import io.nosqlbench.adapters.api.activityconfig.yaml.OpsDocList;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
@ -43,10 +45,12 @@ public class HttpOpMapperTest {
|
||||
static HttpDriverAdapter adapter;
|
||||
static HttpOpMapper mapper;
|
||||
|
||||
static NBComponent parent = new TestComponent("parent","parent");
|
||||
|
||||
@BeforeAll
|
||||
public static void initializeTestMapper() {
|
||||
HttpOpMapperTest.cfg = HttpSpace.getConfigModel().apply(Map.of());
|
||||
HttpOpMapperTest.adapter = new HttpDriverAdapter();
|
||||
HttpOpMapperTest.adapter = new HttpDriverAdapter(parent);
|
||||
HttpOpMapperTest.adapter.applyConfig(HttpOpMapperTest.cfg);
|
||||
final DriverSpaceCache<? extends HttpSpace> cache = HttpOpMapperTest.adapter.getSpaceCache();
|
||||
HttpOpMapperTest.mapper = new HttpOpMapper(HttpOpMapperTest.adapter, HttpOpMapperTest.cfg, cache);
|
||||
@ -55,7 +59,7 @@ public class HttpOpMapperTest {
|
||||
private static ParsedOp parsedOpFor(final String yaml) {
|
||||
final OpsDocList docs = OpsLoader.loadString(yaml, OpTemplateFormat.yaml, Map.of(), null);
|
||||
final OpTemplate opTemplate = docs.getOps().get(0);
|
||||
final ParsedOp parsedOp = new ParsedOp(opTemplate, HttpOpMapperTest.cfg, List.of(HttpOpMapperTest.adapter.getPreprocessor()), NBLabeledElement.forMap(Map.of()));
|
||||
final ParsedOp parsedOp = new ParsedOp(opTemplate, HttpOpMapperTest.cfg, List.of(HttpOpMapperTest.adapter.getPreprocessor()), parent);
|
||||
return parsedOp;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -33,6 +34,10 @@ import java.util.function.Function;
|
||||
public class JDBCDriverAdapter extends BaseDriverAdapter<JDBCOp, JDBCSpace> {
|
||||
private final static Logger logger = LogManager.getLogger(JDBCDriverAdapter.class);
|
||||
|
||||
public JDBCDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<JDBCOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends JDBCSpace> spaceCache = getSpaceCache();
|
||||
|
@ -23,6 +23,7 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -33,6 +34,10 @@ import java.util.function.Function;
|
||||
public class KafkaDriverAdapter extends BaseDriverAdapter<KafkaOp, KafkaSpace> {
|
||||
private final static Logger logger = LogManager.getLogger(KafkaDriverAdapter.class);
|
||||
|
||||
public KafkaDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<KafkaOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends KafkaSpace> spaceCache = getSpaceCache();
|
||||
|
@ -62,10 +62,10 @@ public class KafkaAdapterMetrics {
|
||||
|
||||
// Timer metrics
|
||||
bindTimer =
|
||||
ActivityMetrics.timer(this.kafkaBaseOpDispenser,
|
||||
this.kafkaBaseOpDispenser.create().timer(
|
||||
"bind", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
executeTimer =
|
||||
ActivityMetrics.timer(this.kafkaBaseOpDispenser,
|
||||
this.kafkaBaseOpDispenser.create().timer(
|
||||
"execute", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
|
||||
// End-to-end metrics
|
||||
|
@ -22,6 +22,7 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
|
||||
import java.util.function.Function;
|
||||
@ -32,6 +33,10 @@ import java.util.function.Function;
|
||||
@Service(value = DriverAdapter.class, selector = "mongodb")
|
||||
public class MongodbDriverAdapter extends BaseDriverAdapter<Op, MongoSpace> {
|
||||
|
||||
public MongodbDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<Op> getOpMapper() {
|
||||
return new MongoOpMapper(this, getConfiguration(), getSpaceCache());
|
||||
|
@ -23,6 +23,7 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
|
||||
import java.util.function.Function;
|
||||
@ -30,6 +31,10 @@ import java.util.function.Function;
|
||||
@Service(value = DriverAdapter.class, selector = "pinecone")
|
||||
public class PineconeDriverAdapter extends BaseDriverAdapter<PineconeOp, PineconeSpace> {
|
||||
|
||||
public PineconeDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<PineconeOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends PineconeSpace> spaceCache = getSpaceCache();
|
||||
|
@ -21,6 +21,7 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||
@ -34,6 +35,10 @@ public class PulsarDriverAdapter extends BaseDriverAdapter<PulsarOp, PulsarSpace
|
||||
|
||||
private final static Logger logger = LogManager.getLogger(PulsarDriverAdapter.class);
|
||||
|
||||
public PulsarDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<PulsarOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends PulsarSpace> spaceCache = getSpaceCache();
|
||||
|
@ -84,16 +84,15 @@ public class PulsarAdapterMetrics {
|
||||
|
||||
// Timer metrics
|
||||
bindTimer =
|
||||
ActivityMetrics.timer(this.pulsarBaseOpDispenser,
|
||||
"bind", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
pulsarBaseOpDispenser.create().timer("bind", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
executeTimer =
|
||||
ActivityMetrics.timer(this.pulsarBaseOpDispenser,
|
||||
pulsarBaseOpDispenser.create().timer(
|
||||
"execute", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
createTransactionTimer =
|
||||
ActivityMetrics.timer(this.pulsarBaseOpDispenser,
|
||||
pulsarBaseOpDispenser.create().timer(
|
||||
"create_transaction", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
commitTransactionTimer =
|
||||
ActivityMetrics.timer(this.pulsarBaseOpDispenser,
|
||||
pulsarBaseOpDispenser.create().timer(
|
||||
"commit_transaction", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
}
|
||||
|
||||
@ -113,7 +112,7 @@ public class PulsarAdapterMetrics {
|
||||
// Pulsar client producer API metrics
|
||||
//////////////////////////////////////
|
||||
//
|
||||
private static class ProducerGaugeImpl implements Gauge<Object> {
|
||||
private static class ProducerGaugeImpl implements Gauge<Double> {
|
||||
private final Producer<?> producer;
|
||||
private final Function<ProducerStats, Double> valueExtractor;
|
||||
|
||||
@ -123,7 +122,7 @@ public class PulsarAdapterMetrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
public Double getValue() {
|
||||
// see Pulsar bug https://github.com/apache/pulsar/issues/10100
|
||||
// we need to synchronize on producer otherwise we could receive corrupted data
|
||||
synchronized(this.producer) {
|
||||
@ -156,7 +155,7 @@ public class PulsarAdapterMetrics {
|
||||
// Pulsar client consumer API metrics
|
||||
//////////////////////////////////////
|
||||
//
|
||||
private static class ConsumerGaugeImpl implements Gauge<Object> {
|
||||
private static class ConsumerGaugeImpl implements Gauge<Double> {
|
||||
private final Consumer<?> consumer;
|
||||
private final Function<ConsumerStats, Double> valueExtractor;
|
||||
|
||||
@ -166,7 +165,7 @@ public class PulsarAdapterMetrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
public Double getValue() {
|
||||
// see Pulsar bug https://github.com/apache/pulsar/issues/10100
|
||||
// - this is a bug report for producer stats.
|
||||
// - assume this also applies to consumer stats.
|
||||
|
@ -23,6 +23,7 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -33,6 +34,10 @@ import java.util.function.Function;
|
||||
public class S4JDriverAdapter extends BaseDriverAdapter<S4JOp, S4JSpace> {
|
||||
private final static Logger logger = LogManager.getLogger(S4JDriverAdapter.class);
|
||||
|
||||
public S4JDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<S4JOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends S4JSpace> spaceCache = getSpaceCache();
|
||||
|
@ -45,10 +45,10 @@ public class S4JAdapterMetrics {
|
||||
|
||||
// Timer metrics
|
||||
this.bindTimer =
|
||||
ActivityMetrics.timer(this.s4jBaseOpDispenser,
|
||||
s4jBaseOpDispenser.create().timer(
|
||||
"bind", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
this.executeTimer =
|
||||
ActivityMetrics.timer(this.s4jBaseOpDispenser,
|
||||
s4jBaseOpDispenser.create().timer(
|
||||
"execute", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.decorators.SyntheticOpTemplateProvider;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.api.config.standard.ConfigModel;
|
||||
import io.nosqlbench.api.config.standard.NBConfigModel;
|
||||
@ -40,6 +41,10 @@ import java.util.stream.Collectors;
|
||||
public class StdoutDriverAdapter extends BaseDriverAdapter<StdoutOp, StdoutSpace> implements SyntheticOpTemplateProvider {
|
||||
private final static Logger logger = LogManager.getLogger(StdoutDriverAdapter.class);
|
||||
|
||||
public StdoutDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<StdoutOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends StdoutSpace> ctxCache = getSpaceCache();
|
||||
|
@ -27,6 +27,7 @@ import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.decorators.SyntheticOpTemplateProvider;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -38,7 +39,13 @@ import java.util.function.Function;
|
||||
public class TcpClientDriverAdapter extends BaseDriverAdapter<TcpClientOp, TcpClientAdapterSpace> implements SyntheticOpTemplateProvider {
|
||||
private final static Logger logger = LogManager.getLogger(TcpClientDriverAdapter.class);
|
||||
|
||||
private final static StdoutDriverAdapter adap = new StdoutDriverAdapter();
|
||||
private final StdoutDriverAdapter adap;
|
||||
|
||||
public TcpClientDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
adap=new StdoutDriverAdapter(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<TcpClientOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends TcpClientAdapterSpace> ctxCache = getSpaceCache();
|
||||
|
@ -26,6 +26,7 @@ import io.nosqlbench.adapters.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.decorators.SyntheticOpTemplateProvider;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -37,7 +38,13 @@ import java.util.function.Function;
|
||||
public class TcpServerDriverAdapter extends BaseDriverAdapter<TcpServerOp, TcpServerAdapterSpace> implements SyntheticOpTemplateProvider {
|
||||
private final static Logger logger = LogManager.getLogger(TcpServerDriverAdapter.class);
|
||||
|
||||
private final static StdoutDriverAdapter adap = new StdoutDriverAdapter();
|
||||
private final StdoutDriverAdapter adap;
|
||||
|
||||
public TcpServerDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
adap = new StdoutDriverAdapter(parentComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpMapper<TcpServerOp> getOpMapper() {
|
||||
DriverSpaceCache<? extends TcpServerAdapterSpace> ctxCache = getSpaceCache();
|
||||
|
@ -27,6 +27,8 @@ import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.errors.OpConfigError;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.virtdata.core.templates.ParsedTemplateString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -45,7 +47,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* @param <T>
|
||||
* The type of operation
|
||||
*/
|
||||
public abstract class BaseOpDispenser<T extends Op, S> implements OpDispenser<T>, NBLabeledElement {
|
||||
public abstract class BaseOpDispenser<T extends Op, S> extends NBBaseComponent implements OpDispenser<T>{
|
||||
private final static Logger logger = LogManager.getLogger(BaseOpDispenser.class);
|
||||
public static final String VERIFIER = "verifier";
|
||||
public static final String VERIFIER_INIT = "verifier-init";
|
||||
@ -78,6 +80,7 @@ public abstract class BaseOpDispenser<T extends Op, S> implements OpDispenser<T>
|
||||
private final ThreadLocal<CycleFunction<Boolean>> tlVerifier;
|
||||
|
||||
protected BaseOpDispenser(final DriverAdapter<T, S> adapter, final ParsedOp op) {
|
||||
super(adapter);
|
||||
opName = op.getName();
|
||||
this.adapter = adapter;
|
||||
labels = op.getLabels();
|
||||
@ -99,7 +102,7 @@ public abstract class BaseOpDispenser<T extends Op, S> implements OpDispenser<T>
|
||||
verifiers = configureVerifiers(op);
|
||||
this._verifier = CycleFunctions.of((a, b) -> a && b, verifiers, true);
|
||||
this.tlVerifier = ThreadLocal.withInitial(_verifier::newInstance);
|
||||
this.verifierTimer = ActivityMetrics.timer(this,"verifier",3);
|
||||
this.verifierTimer = create().timer("verifier",3);
|
||||
}
|
||||
|
||||
private CycleFunction<Boolean> cloneVerifiers() {
|
||||
@ -178,10 +181,10 @@ public abstract class BaseOpDispenser<T extends Op, S> implements OpDispenser<T>
|
||||
private void configureInstrumentation(final ParsedOp pop) {
|
||||
instrument = pop.takeStaticConfigOr("instrument", false);
|
||||
if (this.instrument) {
|
||||
final int hdrDigits = pop.getStaticConfigOr("hdr_digits", 4).intValue();
|
||||
final int hdrDigits = pop.getStaticConfigOr("hdr_digits", 4);
|
||||
|
||||
successTimer = ActivityMetrics.timer(pop, ActivityMetrics.sanitize("successfor_"+getOpName()), hdrDigits);
|
||||
errorTimer = ActivityMetrics.timer(pop, ActivityMetrics.sanitize("errorsfor_"+getOpName()), hdrDigits);
|
||||
successTimer = create().timer(ActivityMetrics.sanitize("successfor_"+getOpName()),hdrDigits);
|
||||
errorTimer = create().timer(ActivityMetrics.sanitize("errorsfor_"+getOpName()),hdrDigits);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@ import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
|
||||
import io.nosqlbench.api.config.standard.*;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.fieldmappers.FieldDestructuringMapper;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -31,13 +33,17 @@ import java.util.function.Function;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BaseDriverAdapter<R extends Op, S> implements DriverAdapter<R, S>, NBConfigurable, NBReconfigurable {
|
||||
public abstract class BaseDriverAdapter<R extends Op, S> extends NBBaseComponent implements DriverAdapter<R, S>, NBConfigurable, NBReconfigurable {
|
||||
private final static Logger logger = LogManager.getLogger("ADAPTER");
|
||||
|
||||
private DriverSpaceCache<? extends S> spaceCache;
|
||||
private NBConfiguration cfg;
|
||||
private LongFunction<S> spaceF;
|
||||
|
||||
public BaseDriverAdapter(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
/**
|
||||
* BaseDriverAdapter will take any provided functions from {@link #getOpStmtRemappers()}
|
||||
* and {@link #getOpFieldRemappers()} and construct a preprocessor list. These are applied
|
||||
|
@ -22,6 +22,7 @@ import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
|
||||
import io.nosqlbench.api.docsapi.Docs;
|
||||
import io.nosqlbench.api.docsapi.DocsBinder;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Maturity;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||
@ -54,7 +55,7 @@ import java.util.function.LongFunction;
|
||||
* during construction of R type operations, or even for individual
|
||||
* operations.
|
||||
*/
|
||||
public interface DriverAdapter<OPTYPE extends Op, SPACETYPE> {
|
||||
public interface DriverAdapter<OPTYPE extends Op, SPACETYPE> extends NBComponent {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -20,6 +20,7 @@ import com.codahale.metrics.Timer;
|
||||
import com.codahale.metrics.Timer.Context;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricTimer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -41,7 +42,8 @@ public class ThreadLocalNamedTimers {
|
||||
public static void addTimer(final ParsedOp pop, final String name) {
|
||||
if (ThreadLocalNamedTimers.timers.containsKey("name"))
|
||||
ThreadLocalNamedTimers.logger.warn("A timer named '{}' was already defined and initialized.", name);
|
||||
ThreadLocalNamedTimers.timers.put(name, ActivityMetrics.timer(pop,name,ActivityMetrics.DEFAULT_HDRDIGITS));
|
||||
NBMetricTimer timer = pop.create().timer(name, 3);
|
||||
ThreadLocalNamedTimers.timers.put(name, timer);
|
||||
}
|
||||
|
||||
public void start(final String name) {
|
||||
|
@ -25,6 +25,8 @@ import io.nosqlbench.api.config.fieldreaders.StaticFieldReader;
|
||||
import io.nosqlbench.api.config.standard.NBConfigError;
|
||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.api.errors.OpConfigError;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.api.templating.ObjectCache;
|
||||
import io.nosqlbench.engine.api.templating.ParsedTemplateMap;
|
||||
import io.nosqlbench.engine.api.templating.TypeAndTarget;
|
||||
@ -298,7 +300,7 @@ import java.util.function.LongFunction;
|
||||
* in the activity parameters if needed to find a missing configuration parameter, but this will only work if
|
||||
* the specific named parameter is allowed at the activity level.</P>
|
||||
*/
|
||||
public class ParsedOp implements LongFunction<Map<String, ?>>, NBLabeledElement, StaticFieldReader, DynamicFieldReader {
|
||||
public class ParsedOp extends NBBaseComponent implements LongFunction<Map<String, ?>>, NBLabeledElement, StaticFieldReader, DynamicFieldReader {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ParsedOp.class);
|
||||
|
||||
@ -334,8 +336,9 @@ public class ParsedOp implements LongFunction<Map<String, ?>>, NBLabeledElement,
|
||||
OpTemplate opTemplate,
|
||||
NBConfiguration activityCfg,
|
||||
List<Function<Map<String, Object>, Map<String, Object>>> preprocessors,
|
||||
NBLabeledElement parent
|
||||
NBComponent parent
|
||||
) {
|
||||
super(parent,NBLabels.forKV("op",opTemplate.getName()));
|
||||
this._opTemplate = opTemplate;
|
||||
this.activityCfg = activityCfg;
|
||||
|
||||
|
@ -18,6 +18,7 @@ package io.nosqlbench.adapters.api.templating;
|
||||
|
||||
import io.nosqlbench.adapters.api.activityconfig.OpsLoader;
|
||||
import io.nosqlbench.adapters.api.activityconfig.yaml.OpTemplate;
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.adapters.api.activityconfig.yaml.OpData;
|
||||
import io.nosqlbench.adapters.api.activityconfig.yaml.OpTemplateFormat;
|
||||
@ -25,6 +26,7 @@ import io.nosqlbench.adapters.api.activityconfig.yaml.OpsDocList;
|
||||
import io.nosqlbench.api.config.standard.ConfigModel;
|
||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.api.config.standard.Param;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
@ -35,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ParsedOpTest {
|
||||
|
||||
final NBComponent parent = new TestComponent("opparent","opparent");
|
||||
ParsedOp pc = new ParsedOp(
|
||||
new OpData().applyFields(
|
||||
Map.of(
|
||||
@ -54,7 +57,7 @@ public class ParsedOpTest {
|
||||
.asReadOnly()
|
||||
.apply(Map.of()),
|
||||
List.of(),
|
||||
NBLabeledElement.forMap(Map.of())
|
||||
parent
|
||||
);
|
||||
|
||||
@Test
|
||||
@ -75,7 +78,7 @@ public class ParsedOpTest {
|
||||
final OpsDocList stmtsDocs = OpsLoader.loadString(opt, OpTemplateFormat.yaml, cfg.getMap(), null);
|
||||
assertThat(stmtsDocs.getOps().size()).isEqualTo(1);
|
||||
final OpTemplate opTemplate = stmtsDocs.getOps().get(0);
|
||||
final ParsedOp parsedOp = new ParsedOp(opTemplate, cfg, List.of(), NBLabeledElement.forMap(Map.of()));
|
||||
final ParsedOp parsedOp = new ParsedOp(opTemplate, cfg, List.of(), parent);
|
||||
|
||||
assertThat(parsedOp.getAsFunctionOr("d1", "invalid").apply(1L)).isEqualTo("one");
|
||||
assertThat(parsedOp.getAsFunctionOr("s1", "invalid").apply(1L)).isEqualTo("static-one");
|
||||
@ -114,7 +117,7 @@ public class ParsedOpTest {
|
||||
.asReadOnly()
|
||||
.apply(Map.of()),
|
||||
List.of(),
|
||||
NBLabeledElement.forMap(Map.of())
|
||||
parent
|
||||
);
|
||||
final LongFunction<? extends String> f1 = parsedOp.getAsRequiredFunction("field1-literal");
|
||||
final LongFunction<? extends String> f2 = parsedOp.getAsRequiredFunction("field2-object");
|
||||
@ -186,7 +189,7 @@ public class ParsedOpTest {
|
||||
.asReadOnly()
|
||||
.apply(Map.of()),
|
||||
List.of(),
|
||||
NBLabeledElement.forMap(Map.of())
|
||||
parent
|
||||
);
|
||||
|
||||
Map<String, Object> result = pc.getTemplateMap().apply(1);
|
||||
|
@ -158,8 +158,6 @@ public interface Activity extends Comparable<Activity>, ActivityDefObserver, Pro
|
||||
*/
|
||||
RateLimiter getStrideRateLimiter(Supplier<? extends RateLimiter> supplier);
|
||||
|
||||
Timer getResultTimer();
|
||||
|
||||
/**
|
||||
* Get or create the instrumentation needed for this activity. This provides
|
||||
* a single place to find and manage, and document instrumentation that is
|
||||
|
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* 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.api.activityapi.core;
|
||||
|
||||
import com.codahale.metrics.Counter;
|
||||
import com.codahale.metrics.Histogram;
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.activityimpl.ParameterMap;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
|
||||
public class CoreActivityInstrumentation implements ActivityInstrumentation {
|
||||
|
||||
private static final String STRICTMETRICNAMES = "strictmetricnames";
|
||||
|
||||
private static final String WAIT_TIME = "_waittime";
|
||||
private static final String SERVICE_TIME = "_servicetime";
|
||||
private static final String RESPONSE_TIME = "_responsetime";
|
||||
|
||||
private final Activity activity;
|
||||
private final ActivityDef def;
|
||||
private final ParameterMap params;
|
||||
private final String svcTimeSuffix;
|
||||
private final boolean strictNaming;
|
||||
|
||||
public CoreActivityInstrumentation(final Activity activity) {
|
||||
this.activity = activity;
|
||||
def = activity.getActivityDef();
|
||||
params = this.def.getParams();
|
||||
strictNaming = this.params.getOptionalBoolean(CoreActivityInstrumentation.STRICTMETRICNAMES).orElse(true);
|
||||
this.svcTimeSuffix = this.strictNaming ? CoreActivityInstrumentation.SERVICE_TIME : "";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized Timer getOrCreateInputTimer() {
|
||||
final String metricName = "read_input";
|
||||
return ActivityMetrics.timer(this.activity, metricName, this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized Timer getOrCreateStridesServiceTimer() {
|
||||
return ActivityMetrics.timer(this.activity, "strides" + CoreActivityInstrumentation.SERVICE_TIME, this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Timer getStridesResponseTimerOrNull() {
|
||||
if (null == activity.getStrideLimiter()) return null;
|
||||
return ActivityMetrics.timer(this.activity, "strides" + CoreActivityInstrumentation.RESPONSE_TIME, this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized Timer getOrCreateCyclesServiceTimer() {
|
||||
return ActivityMetrics.timer(this.activity, "cycles" + this.svcTimeSuffix, this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Timer getCyclesResponseTimerOrNull() {
|
||||
if (null == activity.getCycleLimiter()) return null;
|
||||
final String metricName = "cycles" + CoreActivityInstrumentation.RESPONSE_TIME;
|
||||
return ActivityMetrics.timer(this.activity, metricName, this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Counter getOrCreatePendingOpCounter() {
|
||||
final String metricName = "pending_ops";
|
||||
return ActivityMetrics.counter(this.activity, metricName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Counter getOrCreateOpTrackerBlockedCounter() {
|
||||
final String metricName = "optracker_blocked";
|
||||
return ActivityMetrics.counter(this.activity, metricName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Timer getOrCreateBindTimer() {
|
||||
return ActivityMetrics.timer(this.activity, "bind", this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Timer getOrCreateExecuteTimer() {
|
||||
return ActivityMetrics.timer(this.activity,"execute", this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Timer getOrCreateResultTimer() {
|
||||
return ActivityMetrics.timer(this.activity,"result", this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Timer getOrCreateResultSuccessTimer() {
|
||||
return ActivityMetrics.timer(this.activity,"result_success", this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Histogram getOrCreateTriesHistogram() {
|
||||
return ActivityMetrics.histogram(this.activity,"tries", this.activity.getHdrDigits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timer getOrCreateVerifierTimer() {
|
||||
return ActivityMetrics.timer(this.activity,"verifier", this.activity.getHdrDigits());
|
||||
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ package io.nosqlbench.engine.api.activityapi.errorhandling;
|
||||
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.api.metrics.ExceptionCountMetrics;
|
||||
import io.nosqlbench.engine.api.metrics.ExceptionExpectedResultVerificationMetrics;
|
||||
import io.nosqlbench.engine.api.metrics.ExceptionHistoMetrics;
|
||||
@ -28,42 +29,42 @@ import java.util.function.Supplier;
|
||||
|
||||
public class ErrorMetrics {
|
||||
|
||||
private final NBLabeledElement parentLabels;
|
||||
private final NBComponent parent;
|
||||
private ExceptionCountMetrics exceptionCountMetrics;
|
||||
private ExceptionHistoMetrics exceptionHistoMetrics;
|
||||
private ExceptionMeterMetrics exceptionMeterMetrics;
|
||||
private ExceptionTimerMetrics exceptionTimerMetrics;
|
||||
private ExceptionExpectedResultVerificationMetrics exceptionExpectedResultVerificationMetrics;
|
||||
|
||||
public ErrorMetrics(final NBLabeledElement parentLabels) {
|
||||
this.parentLabels = parentLabels;
|
||||
public ErrorMetrics(final NBComponent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public synchronized ExceptionCountMetrics getExceptionCountMetrics() {
|
||||
if (null == exceptionCountMetrics) this.exceptionCountMetrics = new ExceptionCountMetrics(this.parentLabels);
|
||||
if (null == exceptionCountMetrics) this.exceptionCountMetrics = new ExceptionCountMetrics(this.parent);
|
||||
return this.exceptionCountMetrics;
|
||||
}
|
||||
|
||||
public synchronized ExceptionHistoMetrics getExceptionHistoMetrics() {
|
||||
if (null == exceptionHistoMetrics)
|
||||
this.exceptionHistoMetrics = new ExceptionHistoMetrics(this.parentLabels, ActivityDef.parseActivityDef(""));
|
||||
this.exceptionHistoMetrics = new ExceptionHistoMetrics(this.parent, ActivityDef.parseActivityDef(""));
|
||||
return this.exceptionHistoMetrics;
|
||||
}
|
||||
|
||||
public synchronized ExceptionMeterMetrics getExceptionMeterMetrics() {
|
||||
if (null == exceptionMeterMetrics) this.exceptionMeterMetrics = new ExceptionMeterMetrics(this.parentLabels);
|
||||
if (null == exceptionMeterMetrics) this.exceptionMeterMetrics = new ExceptionMeterMetrics(this.parent);
|
||||
return this.exceptionMeterMetrics;
|
||||
}
|
||||
|
||||
public synchronized ExceptionTimerMetrics getExceptionTimerMetrics() {
|
||||
if (null == exceptionTimerMetrics)
|
||||
this.exceptionTimerMetrics = new ExceptionTimerMetrics(this.parentLabels, ActivityDef.parseActivityDef(""));
|
||||
this.exceptionTimerMetrics = new ExceptionTimerMetrics(this.parent, ActivityDef.parseActivityDef(""));
|
||||
return this.exceptionTimerMetrics;
|
||||
}
|
||||
|
||||
public synchronized ExceptionExpectedResultVerificationMetrics getExceptionExpectedResultVerificationMetrics() {
|
||||
if (null == exceptionExpectedResultVerificationMetrics)
|
||||
this.exceptionExpectedResultVerificationMetrics = new ExceptionExpectedResultVerificationMetrics(this.parentLabels);
|
||||
this.exceptionExpectedResultVerificationMetrics = new ExceptionExpectedResultVerificationMetrics(this.parent);
|
||||
return this.exceptionExpectedResultVerificationMetrics;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@ package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
import com.codahale.metrics.Gauge;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -76,7 +78,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
* </p>
|
||||
*/
|
||||
@Service(value = RateLimiter.class, selector = "hybrid")
|
||||
public class HybridRateLimiter implements RateLimiter {
|
||||
public class HybridRateLimiter extends NBBaseComponent implements RateLimiter {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(HybridRateLimiter.class);
|
||||
private NBLabeledElement named;
|
||||
@ -100,13 +102,14 @@ public class HybridRateLimiter implements RateLimiter {
|
||||
// TODO Doc rate limiter scenarios, including when you want to reset the waittime, and when you don't
|
||||
private final AtomicLong cumulativeWaitTimeNanos = new AtomicLong(0L);
|
||||
|
||||
protected HybridRateLimiter() {
|
||||
protected HybridRateLimiter(NBComponent parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public HybridRateLimiter(final NBLabeledElement named, final String label, final RateSpec rateSpec) {
|
||||
public HybridRateLimiter(final NBComponent parent, final String label, final RateSpec rateSpec) {
|
||||
super(parent);
|
||||
this.label = label;
|
||||
this.init(named);
|
||||
this.named = named;
|
||||
applyRateSpec(rateSpec);
|
||||
}
|
||||
|
||||
@ -142,7 +145,7 @@ public class HybridRateLimiter implements RateLimiter {
|
||||
if (updatingRateSpec.equals(rateSpec) && !updatingRateSpec.isRestart()) return;
|
||||
|
||||
rateSpec = updatingRateSpec;
|
||||
tokens = null == this.tokens ? new ThreadDrivenTokenPool(this.rateSpec, this.named) : tokens.apply(this.named, this.rateSpec);
|
||||
tokens = null == this.tokens ? new ThreadDrivenTokenPool(this,this.rateSpec, this.named) : tokens.apply(this.named, this.rateSpec);
|
||||
// this.filler = (this.filler == null) ? new TokenFiller(rateSpec, activityDef) : filler.apply(rateSpec);
|
||||
// this.tokens = this.filler.getTokenPool();
|
||||
|
||||
|
@ -17,8 +17,8 @@
|
||||
package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.api.util.Colors;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -58,7 +58,7 @@ public class InlineTokenPool {
|
||||
private static final Logger logger = LogManager.getLogger(InlineTokenPool.class);
|
||||
|
||||
public static final double MIN_CONCURRENT_OPS = 5;
|
||||
private final NBLabeledElement parentLabels;
|
||||
private final NBComponent parent;
|
||||
|
||||
// Size limit of active pool
|
||||
private long maxActivePoolSize;
|
||||
@ -104,22 +104,22 @@ public class InlineTokenPool {
|
||||
*
|
||||
* @param rateSpec a {@link RateSpec}
|
||||
*/
|
||||
public InlineTokenPool(final RateSpec rateSpec, final ActivityDef def, final NBLabeledElement parentLabels) {
|
||||
this.parentLabels = parentLabels;
|
||||
public InlineTokenPool(final RateSpec rateSpec, final ActivityDef def, final NBComponent parent) {
|
||||
this.parent = parent;
|
||||
final ByteBuffer logbuf = this.getBuffer();
|
||||
this.apply(rateSpec);
|
||||
InlineTokenPool.logger.debug("initialized token pool: {} for rate:{}", this, rateSpec);
|
||||
refillTimer = ActivityMetrics.timer(parentLabels, "tokenfiller",4);
|
||||
refillTimer = parent.create().timer("tokenfiller",4);
|
||||
}
|
||||
|
||||
public InlineTokenPool(final long poolsize, final double burstRatio, final ActivityDef def, final NBLabeledElement parentLabels) {
|
||||
this.parentLabels = parentLabels;
|
||||
public InlineTokenPool(final long poolsize, final double burstRatio, final ActivityDef def, final NBComponent parent) {
|
||||
this.parent = parent;
|
||||
final ByteBuffer logbuf = this.getBuffer();
|
||||
maxActivePoolSize = poolsize;
|
||||
this.burstRatio = burstRatio;
|
||||
maxActiveAndBurstSize = (long) (this.maxActivePoolSize * burstRatio);
|
||||
maxBurstPoolSize = this.maxActiveAndBurstSize - this.maxActivePoolSize;
|
||||
refillTimer = ActivityMetrics.timer(parentLabels, "tokenfiller",4);
|
||||
refillTimer = parent.create().timer( "tokenfiller",4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,7 @@ package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import com.codahale.metrics.Gauge;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -25,10 +26,10 @@ public enum RateLimiters {
|
||||
;
|
||||
private static final Logger logger = LogManager.getLogger(RateLimiters.class);
|
||||
|
||||
public static synchronized RateLimiter createOrUpdate(final NBLabeledElement def, final String label, final RateLimiter extant, final RateSpec spec) {
|
||||
public static synchronized RateLimiter createOrUpdate(final NBComponent parent, final String label, final RateLimiter extant, final RateSpec spec) {
|
||||
|
||||
if (null == extant) {
|
||||
final RateLimiter rateLimiter= new HybridRateLimiter(def, label, spec);
|
||||
final RateLimiter rateLimiter= new HybridRateLimiter(parent, label, spec);
|
||||
|
||||
RateLimiters.logger.info(() -> "Using rate limiter: " + rateLimiter);
|
||||
return rateLimiter;
|
||||
@ -38,7 +39,7 @@ public enum RateLimiters {
|
||||
return extant;
|
||||
}
|
||||
|
||||
public static synchronized RateLimiter create(final NBLabeledElement def, final String label, final String specString) {
|
||||
public static synchronized RateLimiter create(final NBComponent def, final String label, final String specString) {
|
||||
return RateLimiters.createOrUpdate(def, label, null, new RateSpec(specString));
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -49,6 +50,7 @@ public class ThreadDrivenTokenPool implements TokenPool {
|
||||
private static final Logger logger = LogManager.getLogger(ThreadDrivenTokenPool.class);
|
||||
|
||||
public static final double MIN_CONCURRENT_OPS = 2;
|
||||
private final NBComponent parent;
|
||||
|
||||
private long maxActivePool;
|
||||
private long burstPoolSize;
|
||||
@ -70,7 +72,8 @@ public class ThreadDrivenTokenPool implements TokenPool {
|
||||
*
|
||||
* @param rateSpec a {@link RateSpec}
|
||||
*/
|
||||
public ThreadDrivenTokenPool(final RateSpec rateSpec, final NBLabeledElement named) {
|
||||
public ThreadDrivenTokenPool(NBComponent parent, final RateSpec rateSpec, final NBLabeledElement named) {
|
||||
this.parent = parent;
|
||||
this.apply(named,rateSpec);
|
||||
ThreadDrivenTokenPool.logger.debug(() -> "initialized token pool: " + this + " for rate:" + rateSpec);
|
||||
// filler.start();
|
||||
@ -91,7 +94,7 @@ public class ThreadDrivenTokenPool implements TokenPool {
|
||||
|
||||
burstPoolSize = this.maxOverActivePool - this.maxActivePool;
|
||||
nanosPerOp = rateSpec.getNanosPerOp();
|
||||
filler = null == this.filler ? new TokenFiller(rateSpec, this, labeled, 3) : this.filler.apply(rateSpec);
|
||||
filler = null == this.filler ? new TokenFiller(parent, rateSpec, this, labeled, 3) : this.filler.apply(rateSpec);
|
||||
this.notifyAll();
|
||||
return this;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -47,10 +48,10 @@ public class TokenFiller implements Runnable {
|
||||
* in the JVM.
|
||||
*
|
||||
*/
|
||||
public TokenFiller(final RateSpec rateSpec, final ThreadDrivenTokenPool tokenPool, final NBLabeledElement labeled, final int hdrdigits) {
|
||||
public TokenFiller(NBComponent parent, final RateSpec rateSpec, final ThreadDrivenTokenPool tokenPool, final NBLabeledElement labeled, final int hdrdigits) {
|
||||
this.rateSpec = rateSpec;
|
||||
this.tokenPool = tokenPool;
|
||||
timer = ActivityMetrics.timer(labeled, "tokenfiller", hdrdigits);
|
||||
timer = parent.create().timer("tokenfiller",3);
|
||||
}
|
||||
|
||||
public TokenFiller apply(final RateSpec rateSpec) {
|
||||
|
@ -275,10 +275,6 @@ public class SimpleActivity extends NBBaseComponent implements Activity {
|
||||
return strideLimiter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timer getResultTimer() {
|
||||
return ActivityMetrics.timer(this, "result", getParams().getOptionalInteger("hdr_digits").orElse(4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized ActivityInstrumentation getInstrumentation() {
|
||||
|
@ -20,6 +20,7 @@ import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -33,25 +34,20 @@ public class ExceptionTimerMetrics {
|
||||
private final ConcurrentHashMap<String, Timer> timers = new ConcurrentHashMap<>();
|
||||
private final Timer allerrors;
|
||||
private final ActivityDef activityDef;
|
||||
private final NBLabeledElement parentLabels;
|
||||
private final NBComponent parentLabels;
|
||||
|
||||
public ExceptionTimerMetrics(final NBLabeledElement parentLabels, final ActivityDef activityDef) {
|
||||
public ExceptionTimerMetrics(final NBComponent parent, final ActivityDef activityDef) {
|
||||
this.activityDef = activityDef;
|
||||
this.parentLabels = parentLabels;
|
||||
this.parentLabels = parent;
|
||||
|
||||
this.allerrors = ActivityMetrics.timer(
|
||||
parentLabels,
|
||||
"errortimers_ALL",
|
||||
activityDef.getParams().getOptionalInteger("hdr_digits").orElse(4)
|
||||
);
|
||||
this.allerrors=parent.create().timer("errortimers_ALL",4);
|
||||
}
|
||||
|
||||
public void update(final String name, final long nanosDuration) {
|
||||
Timer timer = this.timers.get(name);
|
||||
if (null == timer) synchronized (this.timers) {
|
||||
timer = this.timers.computeIfAbsent(
|
||||
name,
|
||||
k -> ActivityMetrics.timer(this.parentLabels, "errortimers_" + name, this.activityDef.getParams().getOptionalInteger("hdr_digits").orElse(4))
|
||||
name, k -> parentLabels.create().timer("errortimers_" + name, 3)
|
||||
);
|
||||
}
|
||||
timer.update(nanosDuration, TimeUnit.NANOSECONDS);
|
||||
|
@ -20,7 +20,9 @@ import com.codahale.metrics.Counter;
|
||||
import com.codahale.metrics.Histogram;
|
||||
import com.codahale.metrics.Meter;
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.errors.ResultMismatchError;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.api.activityapi.errorhandling.ErrorMetrics;
|
||||
import io.nosqlbench.engine.api.activityapi.errorhandling.modular.handlers.CountErrorHandler;
|
||||
import io.nosqlbench.engine.api.activityapi.errorhandling.modular.handlers.CounterErrorHandler;
|
||||
@ -47,10 +49,9 @@ class NBErrorHandlerTest {
|
||||
private static final String ERROR_HANDLER_APPENDER_NAME = "ErrorHandler";
|
||||
private final RuntimeException runtimeException = new RuntimeException("test exception");
|
||||
|
||||
|
||||
@Test
|
||||
void testNullConfig() {
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_stop"));
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_stop"));
|
||||
final NBErrorHandler errhandler = new NBErrorHandler(() -> "stop", () -> errorMetrics);
|
||||
assertThatExceptionOfType(RuntimeException.class)
|
||||
.isThrownBy(() -> errhandler.handleError(this.runtimeException, 1, 2));
|
||||
@ -58,7 +59,7 @@ class NBErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
void testMultipleWithRetry() {
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_wr"));
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_wr"));
|
||||
final NBErrorHandler eh = new NBErrorHandler(() -> "warn,retry", () -> errorMetrics);
|
||||
final ErrorDetail detail = eh.handleError(this.runtimeException, 1, 2);
|
||||
assertThat(detail.isRetryable()).isTrue();
|
||||
@ -69,7 +70,7 @@ class NBErrorHandlerTest {
|
||||
final Logger logger = (Logger) LogManager.getLogger("ERRORS");
|
||||
final LogAppender appender = NBMock.registerTestLogger(NBErrorHandlerTest.ERROR_HANDLER_APPENDER_NAME, logger, Level.WARN);
|
||||
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_warn"));
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_warn"));
|
||||
final NBErrorHandler eh = new NBErrorHandler(() -> "warn", () -> errorMetrics);
|
||||
final ErrorDetail detail = eh.handleError(this.runtimeException, 1, 2);
|
||||
|
||||
@ -84,7 +85,7 @@ class NBErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
void testHistogramErrorHandler() {
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_histos"));
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_histos"));
|
||||
final NBErrorHandler eh = new NBErrorHandler(() -> "histogram", () -> errorMetrics);
|
||||
final ErrorDetail detail = eh.handleError(this.runtimeException, 1, 2);
|
||||
assertThat(detail.isRetryable()).isFalse();
|
||||
@ -94,7 +95,7 @@ class NBErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
void testTimerErrorHandler() {
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_timers"));
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_timers"));
|
||||
final NBErrorHandler eh = new NBErrorHandler(() -> "timer", () -> errorMetrics);
|
||||
final ErrorDetail detail = eh.handleError(this.runtimeException, 1, 2);
|
||||
assertThat(detail.isRetryable()).isFalse();
|
||||
@ -107,7 +108,7 @@ class NBErrorHandlerTest {
|
||||
final Logger logger = (Logger) LogManager.getLogger(CounterErrorHandler.class);
|
||||
final LogAppender appender = NBMock.registerTestLogger(NBErrorHandlerTest.ERROR_HANDLER_APPENDER_NAME, logger, Level.INFO);
|
||||
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_counters"));
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_counters"));
|
||||
final NBErrorHandler eh = new NBErrorHandler(() -> "counter", () -> errorMetrics);
|
||||
final ErrorDetail detail = eh.handleError(this.runtimeException, 1, 2);
|
||||
assertThat(detail.isRetryable()).isFalse();
|
||||
@ -126,7 +127,7 @@ class NBErrorHandlerTest {
|
||||
final Logger logger = (Logger) LogManager.getLogger(CountErrorHandler.class);
|
||||
final LogAppender appender = NBMock.registerTestLogger(NBErrorHandlerTest.ERROR_HANDLER_APPENDER_NAME, logger, Level.WARN);
|
||||
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_count"));
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_count"));
|
||||
final NBErrorHandler eh = new NBErrorHandler(() -> "count", () -> errorMetrics);
|
||||
final ErrorDetail detail = eh.handleError(this.runtimeException, 1, 2);
|
||||
assertThat(detail.isRetryable()).isFalse();
|
||||
@ -143,7 +144,7 @@ class NBErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
void testMeterErrorHandler() {
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_meters"));
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_meters"));
|
||||
final NBErrorHandler eh = new NBErrorHandler(() -> "meter", () -> errorMetrics);
|
||||
final ErrorDetail detail = eh.handleError(this.runtimeException, 1, 2);
|
||||
assertThat(detail.isRetryable()).isFalse();
|
||||
@ -153,7 +154,7 @@ class NBErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
void testCodeShorthand() {
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_meters"));
|
||||
final ErrorMetrics errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_meters"));
|
||||
final NBErrorHandler eh = new NBErrorHandler(() -> "handler=code code=42", () -> errorMetrics);
|
||||
final ErrorDetail detail = eh.handleError(this.runtimeException, 1, 2);
|
||||
assertThat(detail.isRetryable()).isFalse();
|
||||
@ -184,7 +185,7 @@ class NBErrorHandlerTest {
|
||||
void testExpectedResultVerificationErrorHandler(String name, Exception error, String log, long retriesCount, long errorsCount, Logger logger) {
|
||||
// given
|
||||
NBMock.LogAppender appender = NBMock.registerTestLogger(ERROR_HANDLER_APPENDER_NAME, logger, Level.INFO);
|
||||
var errorMetrics = new ErrorMetrics(NBLabeledElement.forKV("activity","testalias_result_verification_" + name));
|
||||
var errorMetrics = new ErrorMetrics(new TestComponent("activity","testalias_result_verification_" + name));
|
||||
var eh = new NBErrorHandler(() -> "verifyexpected", () -> errorMetrics);
|
||||
var retries = errorMetrics.getExceptionExpectedResultVerificationMetrics().getVerificationRetries();
|
||||
var errors = errorMetrics.getExceptionExpectedResultVerificationMetrics().getVerificationErrors();
|
||||
|
@ -19,6 +19,7 @@ package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.testutils.Perf;
|
||||
import io.nosqlbench.api.testutils.Result;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -27,7 +28,7 @@ import java.util.function.Function;
|
||||
|
||||
public class TestHybridRateLimiterPerf {
|
||||
|
||||
private final Function<RateSpec, RateLimiter> rlFunction = rs -> new HybridRateLimiter(NBLabeledElement.EMPTY,"hybrid", rs.withVerb(RateSpec.Verb.start));
|
||||
private final Function<RateSpec, RateLimiter> rlFunction = rs -> new HybridRateLimiter(NBBaseComponent.EMPTY_COMPONENT,"hybrid", rs.withVerb(RateSpec.Verb.start));
|
||||
private final RateLimiterPerfTestMethods methods = new RateLimiterPerfTestMethods();
|
||||
|
||||
@Test
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.testutils.Perf;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
@ -32,7 +33,7 @@ import java.util.function.Function;
|
||||
*/
|
||||
public class TestRateLimiterPerf1E7 {
|
||||
|
||||
private final Function<RateSpec, RateLimiter> rlFunction = rs -> new HybridRateLimiter(NBLabeledElement.forKV("alias","tokenrl"),"hybrid", rs.withVerb(RateSpec.Verb.configure));
|
||||
private final Function<RateSpec, RateLimiter> rlFunction = rs -> new HybridRateLimiter(new TestComponent("alias","tokenrl"),"hybrid", rs.withVerb(RateSpec.Verb.configure));
|
||||
private final RateLimiterPerfTestMethods methods = new RateLimiterPerfTestMethods();
|
||||
|
||||
// 160 threads at 10_000_000 ops/s
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.testutils.Perf;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
@ -36,7 +37,7 @@ public class TestRateLimiterPerf1E8 {
|
||||
|
||||
private final Function<RateSpec, RateLimiter> rlFunction =
|
||||
rs -> new HybridRateLimiter(
|
||||
this.def,
|
||||
new TestComponent("test","rltest"),
|
||||
"hybrid",
|
||||
rs.withVerb(RateSpec.Verb.configure)
|
||||
);
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.testutils.Result;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
@ -32,7 +33,7 @@ import java.util.function.Function;
|
||||
*/
|
||||
public class TestRateLimiterPerfSingle {
|
||||
|
||||
private final Function<RateSpec, RateLimiter> rlFunction = rs -> new HybridRateLimiter(NBLabeledElement.forKV("alias","tokenrl"),"hybrid", rs.withVerb(RateSpec.Verb.start));
|
||||
private final Function<RateSpec, RateLimiter> rlFunction = rs -> new HybridRateLimiter(new TestComponent("alias","tokenrl"),"hybrid", rs.withVerb(RateSpec.Verb.start));
|
||||
private final RateLimiterPerfTestMethods methods = new RateLimiterPerfTestMethods();
|
||||
|
||||
@Test
|
||||
|
@ -16,16 +16,19 @@
|
||||
|
||||
package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class TestableHybridRateLimiter extends HybridRateLimiter {
|
||||
|
||||
private final AtomicLong clock;
|
||||
private final static NBComponent parent = new TestComponent("rlparent","rlparent");
|
||||
|
||||
public TestableHybridRateLimiter(final AtomicLong clock, final RateSpec rateSpec, final NBLabeledElement def) {
|
||||
super(def, "test", rateSpec);
|
||||
super(parent, "test", rateSpec);
|
||||
this.applyRateSpec(rateSpec);
|
||||
this.setLabel("test");
|
||||
this.clock = clock;
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
@ -29,10 +30,12 @@ public class TokenPoolTest {
|
||||
ActivityDef adef = new ActivityDef(ParameterMap.parseOrException("alias=testing"));
|
||||
NBLabeledElement def = NBLabeledElement.forMap(this.adef.getParams().getStringStringMap());
|
||||
|
||||
TestComponent component = new TestComponent("test","component");
|
||||
|
||||
|
||||
@Test
|
||||
public void testBackfillFullRate() {
|
||||
ThreadDrivenTokenPool p = new ThreadDrivenTokenPool(new RateSpec(10000000, 1.1), this.def);
|
||||
ThreadDrivenTokenPool p = new ThreadDrivenTokenPool(component,new RateSpec(10000000, 1.1), this.def);
|
||||
assertThat(p.refill(1000000L)).isEqualTo(1000000L);
|
||||
assertThat(p.getWaitPool()).isEqualTo(0L);
|
||||
assertThat(p.refill(100L)).isEqualTo(1000100);
|
||||
@ -46,7 +49,7 @@ public class TokenPoolTest {
|
||||
}
|
||||
@Test
|
||||
public void testTakeRanges() {
|
||||
ThreadDrivenTokenPool p = new ThreadDrivenTokenPool(new RateSpec(100, 10), def);
|
||||
ThreadDrivenTokenPool p = new ThreadDrivenTokenPool(component,new RateSpec(100, 10), def);
|
||||
p.refill(100);
|
||||
assertThat(p.takeUpTo(99)).isEqualTo(99L);
|
||||
assertThat(p.takeUpTo(10)).isEqualTo(1L);
|
||||
@ -57,7 +60,7 @@ public class TokenPoolTest {
|
||||
public void testChangedParameters() {
|
||||
|
||||
RateSpec s1 = new RateSpec(1000L, 1.10D);
|
||||
ThreadDrivenTokenPool p = new ThreadDrivenTokenPool(s1, def);
|
||||
ThreadDrivenTokenPool p = new ThreadDrivenTokenPool(component,s1, def);
|
||||
long r = p.refill(10000000);
|
||||
assertThat(r).isEqualTo(10000000L);
|
||||
assertThat(p.getWaitTime()).isEqualTo(10000000L);
|
||||
|
@ -94,8 +94,8 @@ public class NBSceneBuffer implements NBSceneFixtures {
|
||||
return (NBSceneFixtures) this;
|
||||
}
|
||||
|
||||
public static NBSceneBuffer init(String name) {
|
||||
TestComponent root = new TestComponent("scene", "self");
|
||||
return new NBSceneBuffer(NBDefaultSceneFixtures.ofDefault(name));
|
||||
}
|
||||
// public static NBSceneBuffer init(String name) {
|
||||
// TestComponent root = new TestComponent("scene", "self");
|
||||
// return new NBSceneBuffer(NBDefaultSceneFixtures.ofDefault(name));
|
||||
// }
|
||||
}
|
||||
|
@ -18,13 +18,14 @@ package io.nosqlbench.engine.core.lifecycle.scenario.execution;
|
||||
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneBuffer;
|
||||
|
||||
public class ScenarioResult extends NBSceneBuffer {
|
||||
public class ScenarioResult {
|
||||
private final long startedAt;
|
||||
private final long endedAt;
|
||||
private final Exception exception;
|
||||
private final NBSceneBuffer fixtures;
|
||||
|
||||
public ScenarioResult(NBSceneBuffer fixtures, long start, long end, Exception exception) {
|
||||
super(fixtures);
|
||||
this.fixtures = fixtures;
|
||||
this.startedAt=start;
|
||||
this.endedAt=end;
|
||||
this.exception =exception;
|
||||
@ -34,10 +35,6 @@ public class ScenarioResult extends NBSceneBuffer {
|
||||
return this.exception;
|
||||
}
|
||||
|
||||
public static ScenarioResult ofError(Exception e, long now) {
|
||||
return new ScenarioResult(NBSceneBuffer.init("error"),now,now,e);
|
||||
}
|
||||
|
||||
public void report() {
|
||||
System.out.println(getIOLog());
|
||||
if (exception!=null) {
|
||||
@ -53,4 +50,8 @@ public class ScenarioResult extends NBSceneBuffer {
|
||||
System.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
public String getIOLog() {
|
||||
return fixtures.getIOLog();
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,7 @@ import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
||||
import io.nosqlbench.engine.core.lifecycle.IndexedThreadFactory;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBDefaultSceneFixtures;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneBuffer;
|
||||
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.*;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.script.ScenarioExceptionHandler;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -65,7 +62,7 @@ public class ScenariosExecutor extends NBBaseComponent {
|
||||
NBSceneFixtures basecontext = new NBDefaultSceneFixtures(
|
||||
ScriptParams.of(params),
|
||||
this.getParent(),
|
||||
scenario.getActivitiesController(),
|
||||
new ActivitiesController(this),
|
||||
loadExtensions(),
|
||||
new PrintWriter(System.out),
|
||||
new PrintWriter(System.err),
|
||||
@ -180,7 +177,7 @@ public class ScenariosExecutor extends NBBaseComponent {
|
||||
} catch (Exception e) {
|
||||
long now = System.currentTimeMillis();
|
||||
logger.debug("creating exceptional scenario result from getAsyncResultStatus");
|
||||
oResult = Optional.of(ScenarioResult.ofError(e, now));
|
||||
throw new RuntimeException("replace with a proper error type");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package io.nosqlbench.engine.core.lifecycle.scenario.script;
|
||||
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneBuffer;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBSceneFixtures;
|
||||
|
||||
import javax.script.SimpleScriptContext;
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package io.nosqlbench.engine.core.lifecycle.scenario.script;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
||||
@ -51,7 +49,7 @@ public class NBScriptedScenario extends NBScenario {
|
||||
private Exception error;
|
||||
|
||||
private ExecutionMetricsResult result;
|
||||
private final NBLabeledElement parentComponent;
|
||||
private BufferedScriptContext context;
|
||||
|
||||
public Optional<ExecutionMetricsResult> getResultIfComplete() {
|
||||
return Optional.ofNullable(result);
|
||||
@ -68,7 +66,7 @@ public class NBScriptedScenario extends NBScenario {
|
||||
|
||||
private ActivitiesProgressIndicator activitiesProgressIndicator;
|
||||
private String progressInterval = "console:1m";
|
||||
private ScenarioScriptShell scriptEnv;
|
||||
// private ScenarioScriptShell scriptEnv;
|
||||
private final String scenarioName;
|
||||
private ScriptParams scenarioScriptParams;
|
||||
private final Engine engine = Engine.Graalvm;
|
||||
@ -86,7 +84,6 @@ public class NBScriptedScenario extends NBScenario {
|
||||
super(parentComponent, scenarioName);
|
||||
this.scenarioName = scenarioName;
|
||||
this.progressInterval = progressInterval;
|
||||
this.parentComponent = parentComponent;
|
||||
}
|
||||
|
||||
public static NBScriptedScenario ofScripted(String name, Map<String, String> params, NBComponent parent, Invocation invocation) {
|
||||
@ -117,17 +114,14 @@ public class NBScriptedScenario extends NBScenario {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void initializeScriptContext(NBSceneFixtures fixtures) {
|
||||
private BufferedScriptContext initializeScriptContext(NBSceneFixtures fixtures) {
|
||||
BufferedScriptContext ctx = new BufferedScriptContext(fixtures);
|
||||
this.scriptEngine.setContext(ctx);
|
||||
// this.scriptEngine.setContext(ctx);
|
||||
ctx.getBindings(ScriptContext.ENGINE_SCOPE).put("scenario",new PolyglotScenarioController(fixtures.controller()));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
private void initializeScriptingEngine() {
|
||||
|
||||
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)
|
||||
@ -145,30 +139,15 @@ public class NBScriptedScenario extends NBScenario {
|
||||
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);
|
||||
|
||||
// NBScenarioPojoContext sctx = new NBScenarioPojoContext(
|
||||
// this.scenarioScriptParams,
|
||||
// (NBSession) this.getParent(),
|
||||
// scenarioController,
|
||||
// new ActivityBindings(scenarioController)
|
||||
// );
|
||||
//
|
||||
// this.scriptEngine.put("params", sctx.params());
|
||||
// this.scriptEngine.put("session", sctx.session());
|
||||
// this.scriptEngine.put("activities", sctx.activities());
|
||||
// this.scriptEngine.put("scenario", new PolyglotScenarioController(sctx.controller()));
|
||||
//
|
||||
}
|
||||
|
||||
protected synchronized void runScenario(NBSceneFixtures context) {
|
||||
protected synchronized void runScenario(NBSceneFixtures shell) {
|
||||
if (null == result) {
|
||||
try {
|
||||
this.logger.debug("Initializing scripting engine for {}.", scenarioName);
|
||||
this.initializeScriptingEngine();
|
||||
this.initializeScriptContext(context);
|
||||
this.context = this.initializeScriptContext(shell);
|
||||
this.logger.debug("Running control script for {}.", scenarioName);
|
||||
this.executeScenarioScripts();
|
||||
} catch (final Exception e) {
|
||||
@ -190,7 +169,7 @@ public class NBScriptedScenario extends NBScenario {
|
||||
this.logger.debug("Using direct script compilation");
|
||||
final CompiledScript compiled = compilableEngine.compile(script);
|
||||
this.logger.debug("-> invoking main scenario script (compiled)");
|
||||
result = compiled.eval();
|
||||
result = compiled.eval(this.context);
|
||||
this.logger.debug("<- scenario script completed (compiled)");
|
||||
}
|
||||
// else if ((null != scriptfile) && !this.scriptfile.isEmpty()) {
|
||||
|
@ -34,7 +34,6 @@ public class NBScenarioTest {
|
||||
|
||||
@Test
|
||||
public void shouldLoadScriptText() {
|
||||
ScriptEnvBuffer buffer = new ScriptEnvBuffer();
|
||||
NBScriptedScenario scenario = NBScriptedScenario.ofScripted("testing", Map.of(),new TestComponent(), NBScriptedScenario.Invocation.EXECUTE_SCRIPT);
|
||||
scenario.addScriptText("print('loaded script environment...');\n");
|
||||
try {
|
||||
|
@ -141,34 +141,6 @@ public class ActivityMetrics {
|
||||
get().remove(graphiteName);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Create a timer associated with an activity.</p>
|
||||
*
|
||||
* <p>If the provide ActivityDef contains a parameter "hdr_digits", then it will be used to set the number of
|
||||
* significant digits on the histogram's precision.</p>
|
||||
*
|
||||
* <p>This method ensures that if multiple threads attempt to create the same-named metric on a given activity,
|
||||
* that only one of them succeeds.</p>
|
||||
*
|
||||
* @param named
|
||||
* an associated activity def
|
||||
* @param metricFamilyName
|
||||
* a simple, descriptive name for the timer
|
||||
* @return the timer, perhaps a different one if it has already been registered
|
||||
*/
|
||||
public static Timer timer(NBLabeledElement parent, String metricFamilyName, int hdrdigits) {
|
||||
final NBLabels labels = parent.getLabels().and("name", sanitize(metricFamilyName));
|
||||
|
||||
|
||||
Timer registeredTimer = (Timer) register(labels, () ->
|
||||
new NBMetricTimer(labels,
|
||||
new DeltaHdrHistogramReservoir(
|
||||
labels,
|
||||
hdrdigits
|
||||
)
|
||||
));
|
||||
return registeredTimer;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Create an HDR histogram associated with an activity.</p>
|
||||
|
@ -26,6 +26,10 @@ public class NBMetricGaugeWrapper implements NBMetricGauge, NBMetric {
|
||||
|
||||
public NBMetricGaugeWrapper(NBLabels labels, Gauge<Double> gauge) {
|
||||
this.gauge = gauge;
|
||||
if (gauge.getValue() instanceof Double d) {
|
||||
} else {
|
||||
throw new RuntimeException("NBMetricGauges only support Double values");
|
||||
}
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,8 @@ import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class NBBuilders {
|
||||
|
||||
// TODO: add mandatory sanitize() around all label names and label "name" values
|
||||
private final Logger logger = LogManager.getLogger(NBBuilders.class);
|
||||
private final NBBaseComponent base;
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.spi.SimpleServiceLoader;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class NBComponentLoader {
|
||||
public static <C extends NBComponent> C load(NBComponent parent, String selector, Class<C> clazz) {
|
||||
ServiceLoader<C> loader = ServiceLoader.load(clazz);
|
||||
ServiceLoader.Provider<C> cp = loader.stream().filter(p -> {
|
||||
Service service = Arrays.stream(p.type().getAnnotationsByType(Service.class)).findFirst().orElseThrow();
|
||||
return service.selector().equals(selector);
|
||||
}).findFirst().orElseThrow();
|
||||
try {
|
||||
Constructor<? extends C> ctor = cp.type().getConstructor(NBComponent.class);
|
||||
return ctor.newInstance(parent);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package io.nosqlbench.components;
|
||||
|
||||
public interface NBParentComponentInjection {
|
||||
void applyParentComponent(NBComponent component);
|
||||
}
|
@ -16,13 +16,17 @@
|
||||
|
||||
package io.nosqlbench.engine.api.scripting;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DiagWriter extends PrintWriter {
|
||||
|
||||
@ -31,6 +35,7 @@ public class DiagWriter extends PrintWriter {
|
||||
CharArrayWriter buffer = new CharArrayWriter();
|
||||
private final List<String> timedLog = new ArrayList<String>();
|
||||
private final StringBuilder sb = new StringBuilder();
|
||||
private int checkpoint = 0;
|
||||
|
||||
private final DateTimeFormatter tsformat = DateTimeFormatter.ISO_DATE_TIME;
|
||||
|
||||
@ -42,40 +47,227 @@ public class DiagWriter extends PrintWriter {
|
||||
|
||||
@Override
|
||||
public void write(char[] cbuf, int off, int len) {
|
||||
String tsprefix = LocalDateTime.now().format(tsformat);
|
||||
|
||||
buffer.write(cbuf, off, len);
|
||||
String text = new String(cbuf, off, len);
|
||||
|
||||
sb.append(text);
|
||||
|
||||
if (text.contains("\n")) {
|
||||
String msgs = sb.toString();
|
||||
String extra = msgs.substring(msgs.lastIndexOf("\n") + 1);
|
||||
sb.setLength(0);
|
||||
sb.append(extra);
|
||||
String[] parts = msgs.substring(0, msgs.length() - extra.length()).split("\n");
|
||||
for (String part : parts) {
|
||||
if (!part.isBlank()) {
|
||||
String tslogEntry = tsprefix + prefix + part + "\n";
|
||||
timedLog.add(tslogEntry);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
checkpointIf();
|
||||
|
||||
super.write(cbuf, off, len);
|
||||
}
|
||||
|
||||
private void check() {
|
||||
if (sb.substring(checkpoint,sb.length()).contains("\n")) {
|
||||
checkpoint();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkpointIf() {
|
||||
if (checkpoint==sb.length()) {
|
||||
return;
|
||||
}
|
||||
if (sb.substring(checkpoint,sb.length()).contains("\n")) {
|
||||
checkpoint();
|
||||
checkpointIf();
|
||||
}
|
||||
}
|
||||
private void checkpoint() {
|
||||
String tsprefix = LocalDateTime.now().format(tsformat);
|
||||
String msgs = sb.toString();
|
||||
String extra = msgs.substring(msgs.lastIndexOf("\n") + 1);
|
||||
sb.setLength(0);
|
||||
sb.append(extra);
|
||||
String[] parts = msgs.substring(0, msgs.length() - extra.length()).split("\n");
|
||||
for (String part : parts) {
|
||||
if (!part.isBlank()) {
|
||||
String tslogEntry = tsprefix + prefix + part + "\n";
|
||||
timedLog.add(tslogEntry);
|
||||
}
|
||||
}
|
||||
checkpoint = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int c) {
|
||||
this.buffer.write(c);
|
||||
sb.append((char)c);
|
||||
checkpointIf();
|
||||
super.write(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull char[] buf) {
|
||||
try {
|
||||
this.buffer.write(buf);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
sb.append(buf);
|
||||
checkpointIf();
|
||||
super.write(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull String s, int off, int len) {
|
||||
this.buffer.write(s,off,len);
|
||||
sb.append(s);
|
||||
checkpointIf();
|
||||
super.write(s, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull String s) {
|
||||
try {
|
||||
sb.append(s);
|
||||
this.buffer.write(s);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
checkpointIf();
|
||||
super.write(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(boolean b) {
|
||||
super.print(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(char c) {
|
||||
super.print(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(int i) {
|
||||
super.print(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(long l) {
|
||||
super.print(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(float f) {
|
||||
super.print(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(double d) {
|
||||
super.print(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(@NotNull char[] s) {
|
||||
super.print(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String s) {
|
||||
super.print(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(Object obj) {
|
||||
super.print(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println() {
|
||||
super.println();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(boolean x) {
|
||||
super.println(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(char x) {
|
||||
super.println(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(int x) {
|
||||
super.println(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(long x) {
|
||||
super.println(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(float x) {
|
||||
super.println(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(double x) {
|
||||
super.println(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(@NotNull char[] x) {
|
||||
super.println(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(String x) {
|
||||
super.println(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(Object x) {
|
||||
super.println(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter printf(@NotNull String format, Object... args) {
|
||||
return super.printf(format, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter printf(Locale l, @NotNull String format, Object... args) {
|
||||
return super.printf(l, format, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter format(@NotNull String format, Object... args) {
|
||||
return super.format(format, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter format(Locale l, @NotNull String format, Object... args) {
|
||||
return super.format(l, format, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter append(CharSequence csq) {
|
||||
return super.append(csq);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter append(CharSequence csq, int start, int end) {
|
||||
return super.append(csq, start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter append(char c) {
|
||||
return super.append(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
buffer.flush();
|
||||
checkpoint();
|
||||
super.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
buffer.close();
|
||||
checkpoint();
|
||||
super.close();
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ public class PromExpositionFormatTest {
|
||||
|
||||
@Test
|
||||
public void testGaugeFormat() {
|
||||
Gauge cosetteGauge = () -> 1500;
|
||||
Gauge cosetteGauge = () -> 1500d;
|
||||
NBMetricGauge nbMetricGauge = new NBMetricGaugeWrapper(NBLabels.forKV("name","cosette","label6", "value6"), cosetteGauge);
|
||||
String formatted = PromExpositionFormat.format(nowclock, nbMetricGauge);
|
||||
|
||||
@ -162,7 +162,7 @@ public class PromExpositionFormatTest {
|
||||
cosette\\{label6="value6"} 1500.0
|
||||
"""));
|
||||
|
||||
Gauge cosetteGauge2 = () -> "2000.0";
|
||||
Gauge cosetteGauge2 = () -> 2000.0d;
|
||||
NBMetricGauge nbMetricGauge2 = new NBMetricGaugeWrapper(NBLabels.forKV("name","cosette2","label7", "value7"), cosetteGauge2);
|
||||
String formatted2 = PromExpositionFormat.format(nowclock, nbMetricGauge2);
|
||||
|
||||
@ -171,15 +171,5 @@ public class PromExpositionFormatTest {
|
||||
cosette2\\{label7="value7"} 2000.0
|
||||
"""));
|
||||
|
||||
final int number = 3000;
|
||||
final CharSequence charSequence = Integer.toString(number);
|
||||
Gauge cosetteGauge3 = () -> charSequence;
|
||||
NBMetricGauge nbMetricGauge3 = new NBMetricGaugeWrapper(NBLabels.forKV("name","cosette3","label8", "value8"), cosetteGauge3);
|
||||
String formatted3 = PromExpositionFormat.format(nowclock, nbMetricGauge3);
|
||||
|
||||
assertThat(formatted3).matches(Pattern.compile("""
|
||||
# TYPE cosette3 gauge
|
||||
cosette3\\{label8="value8"} 3000
|
||||
"""));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user