mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
refactor diag tasks to better support labels
This commit is contained in:
parent
74decafbf5
commit
50b7416c18
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 nosqlbench
|
* Copyright (c) 2022-2023 nosqlbench
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -62,10 +62,13 @@ public class DiagOpDispenser extends BaseOpDispenser<DiagOp,DiagSpace> implement
|
|||||||
taskcfg.computeIfAbsent("name",l -> taskname);
|
taskcfg.computeIfAbsent("name",l -> taskname);
|
||||||
taskcfg.computeIfAbsent("type",l -> taskname);
|
taskcfg.computeIfAbsent("type",l -> taskname);
|
||||||
String optype = taskcfg.remove("type").toString();
|
String optype = taskcfg.remove("type").toString();
|
||||||
|
String opname = taskcfg.get("name").toString();
|
||||||
|
|
||||||
// Dynamically load the named task instance, based on the op field key AKA the taskname
|
// Dynamically load the named task instance, based on the op field key AKA the taskname
|
||||||
// and ensure that exactly one is found or throw an error
|
// and ensure that exactly one is found or throw an error
|
||||||
DiagTask task = ServiceSelector.of(optype, ServiceLoader.load(DiagTask.class)).getOne();
|
DiagTask task = ServiceSelector.of(optype, ServiceLoader.load(DiagTask.class)).getOne();
|
||||||
|
task.setLabelsFrom(op);
|
||||||
|
task.setName(opname);
|
||||||
|
|
||||||
// Load the configuration model of the dynamically loaded task for type-safe configuration
|
// Load the configuration model of the dynamically loaded task for type-safe configuration
|
||||||
NBConfigModel cfgmodel = task.getConfigModel();
|
NBConfigModel cfgmodel = task.getConfigModel();
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 nosqlbench
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.nosqlbench.adapter.diag.optasks;
|
||||||
|
|
||||||
|
import io.nosqlbench.api.config.NBLabeledElement;
|
||||||
|
import io.nosqlbench.api.config.NBLabels;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class BaseDiagTask implements DiagTask {
|
||||||
|
private NBLabeledElement parentLabels;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract Map<String, Object> apply(Long cycle, Map<String, Object> opstate);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBLabels getLabels() {
|
||||||
|
return parentLabels.getLabels();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLabelsFrom(NBLabeledElement labeledElement) {
|
||||||
|
this.parentLabels = labeledElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBLabeledElement getParentLabels() {
|
||||||
|
return parentLabels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 nosqlbench
|
* Copyright (c) 2022-2023 nosqlbench
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
package io.nosqlbench.adapter.diag.optasks;
|
package io.nosqlbench.adapter.diag.optasks;
|
||||||
|
|
||||||
import io.nosqlbench.api.config.NBNamedElement;
|
import io.nosqlbench.api.config.NBLabeledElement;
|
||||||
import io.nosqlbench.api.config.standard.NBReconfigurable;
|
|
||||||
import io.nosqlbench.api.config.standard.NBConfigurable;
|
import io.nosqlbench.api.config.standard.NBConfigurable;
|
||||||
|
import io.nosqlbench.api.config.standard.NBReconfigurable;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@ -44,7 +44,13 @@ import java.util.function.BiFunction;
|
|||||||
public interface DiagTask extends
|
public interface DiagTask extends
|
||||||
BiFunction<Long,Map<String,Object>, Map<String,Object>>,
|
BiFunction<Long,Map<String,Object>, Map<String,Object>>,
|
||||||
NBConfigurable,
|
NBConfigurable,
|
||||||
NBNamedElement
|
NBLabeledElement
|
||||||
{
|
{
|
||||||
Map<String, Object> apply(Long cycle, Map<String, Object> opstate);
|
Map<String, Object> apply(Long cycle, Map<String, Object> opstate);
|
||||||
|
|
||||||
|
void setName(String opname);
|
||||||
|
|
||||||
|
void setLabelsFrom(NBLabeledElement labeledElement);
|
||||||
|
|
||||||
|
NBLabeledElement getParentLabels();
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package io.nosqlbench.adapter.diag.optasks;
|
package io.nosqlbench.adapter.diag.optasks;
|
||||||
|
|
||||||
import io.nosqlbench.api.config.NBLabeledElement;
|
|
||||||
import io.nosqlbench.api.config.NBLabels;
|
|
||||||
import io.nosqlbench.api.config.standard.*;
|
import io.nosqlbench.api.config.standard.*;
|
||||||
import io.nosqlbench.engine.api.activityapi.ratelimits.RateLimiter;
|
import io.nosqlbench.engine.api.activityapi.ratelimits.RateLimiter;
|
||||||
import io.nosqlbench.engine.api.activityapi.ratelimits.RateLimiters;
|
import io.nosqlbench.engine.api.activityapi.ratelimits.RateLimiters;
|
||||||
@ -27,7 +25,7 @@ import io.nosqlbench.nb.annotations.Service;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service(value = DiagTask.class, selector = "diagrate")
|
@Service(value = DiagTask.class, selector = "diagrate")
|
||||||
public class DiagTask_diagrate implements DiagTask, NBReconfigurable, NBLabeledElement {
|
public class DiagTask_diagrate extends BaseDiagTask implements NBReconfigurable {
|
||||||
private String name;
|
private String name;
|
||||||
private RateLimiter rateLimiter;
|
private RateLimiter rateLimiter;
|
||||||
private RateSpec rateSpec;
|
private RateSpec rateSpec;
|
||||||
@ -73,15 +71,4 @@ public class DiagTask_diagrate implements DiagTask, NBReconfigurable, NBLabeledE
|
|||||||
rateLimiter.maybeWaitForOp();
|
rateLimiter.maybeWaitForOp();
|
||||||
return stringObjectMap;
|
return stringObjectMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBLabels getLabels() {
|
|
||||||
return NBLabels.forKV("diagop", name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 nosqlbench
|
* Copyright (c) 2022-2023 nosqlbench
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -29,14 +29,12 @@ import java.util.Map;
|
|||||||
* of this owning operation for a number of milliseconds.
|
* of this owning operation for a number of milliseconds.
|
||||||
*/
|
*/
|
||||||
@Service(value = DiagTask.class, selector = "erroroncycle")
|
@Service(value = DiagTask.class, selector = "erroroncycle")
|
||||||
public class DiagTask_erroroncycle implements DiagTask {
|
public class DiagTask_erroroncycle extends BaseDiagTask {
|
||||||
|
|
||||||
private String name;
|
|
||||||
private long error_on_cycle;
|
private long error_on_cycle;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyConfig(NBConfiguration cfg) {
|
public void applyConfig(NBConfiguration cfg) {
|
||||||
this.name = cfg.get("name", String.class);
|
|
||||||
error_on_cycle = cfg.get("erroroncycle", long.class);
|
error_on_cycle = cfg.get("erroroncycle", long.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,9 +53,4 @@ public class DiagTask_erroroncycle implements DiagTask {
|
|||||||
}
|
}
|
||||||
return Map.of();
|
return Map.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 nosqlbench
|
* Copyright (c) 2022-2023 nosqlbench
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -29,13 +29,10 @@ import java.util.Map;
|
|||||||
* of this owning operation for a number of milliseconds.
|
* of this owning operation for a number of milliseconds.
|
||||||
*/
|
*/
|
||||||
@Service(value= DiagTask.class,selector = "initdelay")
|
@Service(value= DiagTask.class,selector = "initdelay")
|
||||||
public class DiagTask_initdelay implements DiagTask {
|
public class DiagTask_initdelay extends BaseDiagTask {
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyConfig(NBConfiguration cfg) {
|
public void applyConfig(NBConfiguration cfg) {
|
||||||
this.name = cfg.get("name",String.class);
|
|
||||||
long initdelay = cfg.get("initdelay",long.class);
|
long initdelay = cfg.get("initdelay",long.class);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(initdelay);
|
Thread.sleep(initdelay);
|
||||||
@ -54,12 +51,6 @@ public class DiagTask_initdelay implements DiagTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> apply(Long aLong, Map<String, Object> stringObjectMap) {
|
public Map<String, Object> apply(Long aLong, Map<String, Object> stringObjectMap) {
|
||||||
|
|
||||||
return Map.of();
|
return Map.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 nosqlbench
|
* Copyright (c) 2022-2023 nosqlbench
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -25,12 +25,11 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service(value= DiagTask.class,selector="log")
|
@Service(value= DiagTask.class,selector="log")
|
||||||
public class DiagTask_log implements DiagTask, NBConfigurable {
|
public class DiagTask_log extends BaseDiagTask {
|
||||||
private final static Logger logger = LogManager.getLogger("DIAG");
|
private final static Logger logger = LogManager.getLogger("DIAG");
|
||||||
private Level level;
|
private Level level;
|
||||||
private long modulo;
|
private long modulo;
|
||||||
private long interval;
|
private long interval;
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> apply(Long aLong, Map<String, Object> stringObjectMap) {
|
public Map<String, Object> apply(Long aLong, Map<String, Object> stringObjectMap) {
|
||||||
@ -43,7 +42,6 @@ public class DiagTask_log implements DiagTask, NBConfigurable {
|
|||||||
@Override
|
@Override
|
||||||
public void applyConfig(NBConfiguration cfg) {
|
public void applyConfig(NBConfiguration cfg) {
|
||||||
String level = cfg.getOptional("level").orElse("INFO");
|
String level = cfg.getOptional("level").orElse("INFO");
|
||||||
this.name = cfg.get("name");
|
|
||||||
this.level = Level.valueOf(level);
|
this.level = Level.valueOf(level);
|
||||||
this.modulo = cfg.get("modulo",long.class);
|
this.modulo = cfg.get("modulo",long.class);
|
||||||
this.interval = cfg.get("interval",long.class);
|
this.interval = cfg.get("interval",long.class);
|
||||||
@ -58,9 +56,4 @@ public class DiagTask_log implements DiagTask, NBConfigurable {
|
|||||||
.add(Param.defaultTo("interval",1000))
|
.add(Param.defaultTo("interval",1000))
|
||||||
.asReadOnly();
|
.asReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 nosqlbench
|
* Copyright (c) 2022-2023 nosqlbench
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -16,22 +16,21 @@
|
|||||||
|
|
||||||
package io.nosqlbench.adapter.diag.optasks;
|
package io.nosqlbench.adapter.diag.optasks;
|
||||||
|
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
|
||||||
import io.nosqlbench.api.config.standard.ConfigModel;
|
import io.nosqlbench.api.config.standard.ConfigModel;
|
||||||
import io.nosqlbench.api.config.standard.NBConfigModel;
|
import io.nosqlbench.api.config.standard.NBConfigModel;
|
||||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||||
import io.nosqlbench.api.config.standard.Param;
|
import io.nosqlbench.api.config.standard.Param;
|
||||||
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service(value= DiagTask.class,selector = "noop")
|
@Service(value= DiagTask.class,selector = "noop")
|
||||||
public class DiagTask_noop implements DiagTask {
|
public class DiagTask_noop extends BaseDiagTask {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyConfig(NBConfiguration cfg) {
|
public void applyConfig(NBConfiguration cfg) {
|
||||||
this.name = cfg.get("name",String.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,8 +45,4 @@ public class DiagTask_noop implements DiagTask {
|
|||||||
return Map.of();
|
return Map.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user