mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
make config model construction more uniform
This commit is contained in:
parent
ab24cc5aef
commit
284e86e64f
@ -5,11 +5,14 @@ import com.datastax.driver.core.DataType;
|
|||||||
import com.datastax.driver.core.TupleType;
|
import com.datastax.driver.core.TupleType;
|
||||||
import com.datastax.driver.core.TupleValue;
|
import com.datastax.driver.core.TupleValue;
|
||||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
||||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
|
||||||
import io.nosqlbench.nb.api.config.standard.NBMapConfigurable;
|
|
||||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||||
|
import io.nosqlbench.nb.api.config.standard.NBMapConfigurable;
|
||||||
|
import io.nosqlbench.nb.api.config.standard.Param;
|
||||||
|
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.LongFunction;
|
import java.util.function.LongFunction;
|
||||||
import java.util.function.LongToIntFunction;
|
import java.util.function.LongToIntFunction;
|
||||||
import java.util.function.LongUnaryOperator;
|
import java.util.function.LongUnaryOperator;
|
||||||
@ -21,14 +24,14 @@ import java.util.function.LongUnaryOperator;
|
|||||||
*
|
*
|
||||||
* Functions are required for:
|
* Functions are required for:
|
||||||
* <LI>
|
* <LI>
|
||||||
* <LI>map size {@code (LongToIntFunction)}</LI>
|
* <LI>map size {@code (LongToIntFunction)}</LI>
|
||||||
* <LI>key {@code (LongFunction<Object>)}</LI>
|
* <LI>key {@code (LongFunction<Object>)}</LI>
|
||||||
* <LI>tuple field 1 {@code (LongToIntFunction)}</LI>
|
* <LI>tuple field 1 {@code (LongToIntFunction)}</LI>
|
||||||
* <LI>tuple field 2 {@code {LongToIntFunction)}</LI>
|
* <LI>tuple field 2 {@code {LongToIntFunction)}</LI>
|
||||||
* </LI>
|
* </LI>
|
||||||
*/
|
*/
|
||||||
@ThreadSafeMapper
|
@ThreadSafeMapper
|
||||||
public class CustomFunc955 implements LongFunction<Map<?,?>>, NBMapConfigurable {
|
public class CustomFunc955 implements LongFunction<Map<?, ?>>, NBMapConfigurable {
|
||||||
|
|
||||||
private final LongToIntFunction sizefunc;
|
private final LongToIntFunction sizefunc;
|
||||||
private final LongFunction<Object> keyfunc;
|
private final LongFunction<Object> keyfunc;
|
||||||
@ -56,16 +59,16 @@ public class CustomFunc955 implements LongFunction<Map<?,?>>, NBMapConfigurable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<?,?> apply(long value) {
|
public Map<?, ?> apply(long value) {
|
||||||
int size = sizefunc.applyAsInt(value);
|
int size = sizefunc.applyAsInt(value);
|
||||||
|
|
||||||
HashMap<String, TupleValue> map = new HashMap<>(size);
|
HashMap<String, TupleValue> map = new HashMap<>(size);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
String key = keyfunc.apply(value+i).toString();
|
String key = keyfunc.apply(value + i).toString();
|
||||||
int tuple1 = field1func.applyAsInt(value+i);
|
int tuple1 = field1func.applyAsInt(value + i);
|
||||||
long tuple2 = field2func.applyAsLong(value+i);
|
long tuple2 = field2func.applyAsLong(value + i);
|
||||||
TupleValue tupleValue = tupleType.newValue(tuple1, tuple2);
|
TupleValue tupleValue = tupleType.newValue(tuple1, tuple2);
|
||||||
map.put(key,tupleValue);
|
map.put(key, tupleValue);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -81,7 +84,7 @@ public class CustomFunc955 implements LongFunction<Map<?,?>>, NBMapConfigurable
|
|||||||
@Override
|
@Override
|
||||||
public NBConfigModel getConfigModel() {
|
public NBConfigModel getConfigModel() {
|
||||||
return ConfigModel.of(this.getClass())
|
return ConfigModel.of(this.getClass())
|
||||||
.optional("<cluster>", Cluster.class)
|
.add(Param.optional("<cluster>", Cluster.class))
|
||||||
.asReadOnly();
|
.asReadOnly();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,7 @@ import io.nosqlbench.nb.api.SystemId;
|
|||||||
import io.nosqlbench.nb.api.annotations.Annotation;
|
import io.nosqlbench.nb.api.annotations.Annotation;
|
||||||
import io.nosqlbench.nb.api.annotations.Annotator;
|
import io.nosqlbench.nb.api.annotations.Annotator;
|
||||||
import io.nosqlbench.nb.api.config.params.ParamsParser;
|
import io.nosqlbench.nb.api.config.params.ParamsParser;
|
||||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
import io.nosqlbench.nb.api.config.standard.*;
|
||||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
|
||||||
import io.nosqlbench.nb.api.config.standard.NBConfigurable;
|
|
||||||
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
|
||||||
import io.nosqlbench.nb.api.errors.BasicError;
|
import io.nosqlbench.nb.api.errors.BasicError;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -111,7 +108,7 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
|
|||||||
public void applyConfig(NBConfiguration cfg) {
|
public void applyConfig(NBConfiguration cfg) {
|
||||||
|
|
||||||
GrafanaClientConfig gc = new GrafanaClientConfig();
|
GrafanaClientConfig gc = new GrafanaClientConfig();
|
||||||
gc.setBaseUri(cfg.param("baseurl", String.class));
|
gc.setBaseUri(cfg.get("baseurl"));
|
||||||
|
|
||||||
cfg.getOptional("tags")
|
cfg.getOptional("tags")
|
||||||
.map(t -> ParamsParser.parse(t, false))
|
.map(t -> ParamsParser.parse(t, false))
|
||||||
@ -133,7 +130,7 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
|
|||||||
Optional<String> optionalApikey = cfg.getOptional("apikey");
|
Optional<String> optionalApikey = cfg.getOptional("apikey");
|
||||||
|
|
||||||
if (optionalApikeyfile.isPresent()) {
|
if (optionalApikeyfile.isPresent()) {
|
||||||
keyfilePath=optionalApikeyfile.map(Path::of).orElseThrow();
|
keyfilePath = optionalApikeyfile.map(Path::of).orElseThrow();
|
||||||
} else if (optionalApikey.isPresent()) {
|
} else if (optionalApikey.isPresent()) {
|
||||||
gc.addHeaderSource(() -> Map.of("Authorization", "Bearer " + optionalApikey.get()));
|
gc.addHeaderSource(() -> Map.of("Authorization", "Bearer " + optionalApikey.get()));
|
||||||
} else {
|
} else {
|
||||||
@ -151,7 +148,7 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setOnError(OnError onError) {
|
private void setOnError(OnError onError) {
|
||||||
this.onError=onError;
|
this.onError = onError;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTags(Map<String, String> tags) {
|
private void setTags(Map<String, String> tags) {
|
||||||
@ -161,22 +158,22 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
|
|||||||
@Override
|
@Override
|
||||||
public NBConfigModel getConfigModel() {
|
public NBConfigModel getConfigModel() {
|
||||||
return ConfigModel.of(this.getClass())
|
return ConfigModel.of(this.getClass())
|
||||||
.required("baseurl", String.class,
|
.add(Param.required("baseurl", String.class)
|
||||||
"The base url of the grafana node, like http://localhost:3000/")
|
.setDescription("The base url of the grafana node, like http://localhost:3000/"))
|
||||||
.defaults("apikeyfile", "$NBSTATEDIR/grafana/grafana_apikey",
|
.add(Param.defaultTo("apikeyfile", "$NBSTATEDIR/grafana/grafana_apikey")
|
||||||
"The file that contains the api key, supersedes apikey")
|
.setDescription("The file that contains the api key, supersedes apikey"))
|
||||||
.optional("apikey", String.class,
|
.add(Param.optional("apikey", String.class)
|
||||||
"The api key to use, supersedes basic username and password")
|
.setDescription("The api key to use, supersedes basic username and password"))
|
||||||
.optional("username", String.class,
|
.add(Param.optional("username", String.class)
|
||||||
"The username to use for basic auth")
|
.setDescription("The username to use for basic auth"))
|
||||||
.optional("password", String.class,
|
.add(Param.optional("password", String.class)
|
||||||
"The password to use for basic auth")
|
.setDescription("The password to use for basic auth"))
|
||||||
.defaults("tags", "source:nosqlbench",
|
.add(Param.defaultTo("tags", "source:nosqlbench")
|
||||||
"The tags that identify the annotations, in k:v,... form")
|
.setDescription("The tags that identify the annotations, in k:v,... form"))
|
||||||
.defaults("onerror", "warn",
|
.add(Param.defaultTo("onerror", "warn")
|
||||||
"What to do when an error occurs while posting an annotation")
|
.setDescription("What to do when an error occurs while posting an annotation"))
|
||||||
.defaults("timeoutms", 5000,
|
.add(Param.defaultTo("timeoutms", 5000)
|
||||||
"connect and transport timeout for the HTTP client")
|
.setDescription("connect and transport timeout for the HTTP client"))
|
||||||
.asReadOnly();
|
.asReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,7 @@ package io.nosqlbench.engine.core.metrics;
|
|||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import io.nosqlbench.nb.api.annotations.Annotation;
|
import io.nosqlbench.nb.api.annotations.Annotation;
|
||||||
import io.nosqlbench.nb.api.annotations.Annotator;
|
import io.nosqlbench.nb.api.annotations.Annotator;
|
||||||
import io.nosqlbench.nb.api.config.standard.NBMapConfigurable;
|
import io.nosqlbench.nb.api.config.standard.*;
|
||||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
|
||||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
|
||||||
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -35,16 +32,16 @@ public class LoggingAnnotator implements Annotator, NBMapConfigurable {
|
|||||||
public void applyConfig(Map<String, ?> providedConfig) {
|
public void applyConfig(Map<String, ?> providedConfig) {
|
||||||
NBConfigModel configModel = getConfigModel();
|
NBConfigModel configModel = getConfigModel();
|
||||||
NBConfiguration cfg = configModel.apply(providedConfig);
|
NBConfiguration cfg = configModel.apply(providedConfig);
|
||||||
String levelName = cfg.param("level", String.class);
|
String levelName = cfg.get("level");
|
||||||
this.level = Level.valueOf(levelName);
|
this.level = Level.valueOf(levelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBConfigModel getConfigModel() {
|
public NBConfigModel getConfigModel() {
|
||||||
return ConfigModel.of(this.getClass())
|
return ConfigModel.of(this.getClass())
|
||||||
.defaults("level", "INFO",
|
.add(Param.defaultTo("level", "INFO")
|
||||||
"The logging level to use for this annotator")
|
.setDescription("The logging level to use for this annotator"))
|
||||||
.asReadOnly();
|
.asReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user