mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
align test name to file
This commit is contained in:
parent
df15137999
commit
745d203766
@ -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.
|
||||||
@ -17,14 +17,16 @@
|
|||||||
package io.nosqlbench.engine.core.lifecycle.scenario.script.bindings;
|
package io.nosqlbench.engine.core.lifecycle.scenario.script.bindings;
|
||||||
|
|
||||||
import com.codahale.metrics.*;
|
import com.codahale.metrics.*;
|
||||||
import com.codahale.metrics.Timer;
|
|
||||||
import io.nosqlbench.engine.core.metrics.MetricMap;
|
import io.nosqlbench.engine.core.metrics.MetricMap;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.graalvm.polyglot.Value;
|
import org.graalvm.polyglot.Value;
|
||||||
import org.graalvm.polyglot.proxy.ProxyObject;
|
import org.graalvm.polyglot.proxy.ProxyObject;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A view of metrics objects as an object tree.
|
* A view of metrics objects as an object tree.
|
||||||
@ -82,7 +84,7 @@ public class PolyglotMetricRegistryBindings implements ProxyObject, MetricRegist
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGaugeRemoved(String name) {
|
public void onGaugeRemoved(String name) {
|
||||||
metrics.findOwner(name).remove(name);
|
metrics.findOrCreateDottedParentPath(name).remove(name);
|
||||||
logger.debug("gauge removed: " + name);
|
logger.debug("gauge removed: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +96,7 @@ public class PolyglotMetricRegistryBindings implements ProxyObject, MetricRegist
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCounterRemoved(String name) {
|
public void onCounterRemoved(String name) {
|
||||||
metrics.findOwner(name).remove(name);
|
metrics.findOrCreateDottedParentPath(name).remove(name);
|
||||||
logger.debug("counter removed: " + name);
|
logger.debug("counter removed: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +108,7 @@ public class PolyglotMetricRegistryBindings implements ProxyObject, MetricRegist
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHistogramRemoved(String name) {
|
public void onHistogramRemoved(String name) {
|
||||||
metrics.findOwner(name).remove(name);
|
metrics.findOrCreateDottedParentPath(name).remove(name);
|
||||||
logger.debug("histogram removed: " + name);
|
logger.debug("histogram removed: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +120,7 @@ public class PolyglotMetricRegistryBindings implements ProxyObject, MetricRegist
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMeterRemoved(String name) {
|
public void onMeterRemoved(String name) {
|
||||||
metrics.findOwner(name).remove(name);
|
metrics.findOrCreateDottedParentPath(name).remove(name);
|
||||||
logger.debug("meter removed: " + name);
|
logger.debug("meter removed: " + name);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -131,7 +133,7 @@ public class PolyglotMetricRegistryBindings implements ProxyObject, MetricRegist
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTimerRemoved(String name) {
|
public void onTimerRemoved(String name) {
|
||||||
metrics.findOwner(name).remove(name);
|
metrics.findOrCreateDottedParentPath(name).remove(name);
|
||||||
logger.debug("timer removed: " + name);
|
logger.debug("timer removed: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,4 +156,21 @@ public class PolyglotMetricRegistryBindings implements ProxyObject, MetricRegist
|
|||||||
return totalMap;
|
return totalMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
PolyglotMetricRegistryBindings that = (PolyglotMetricRegistryBindings) o;
|
||||||
|
|
||||||
|
if (!registry.equals(that.registry)) return false;
|
||||||
|
return Objects.equals(metrics, that.metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = registry.hashCode();
|
||||||
|
result = 31 * result + (metrics != null ? metrics.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
@ -17,10 +17,12 @@
|
|||||||
package io.nosqlbench.engine.core.metrics;
|
package io.nosqlbench.engine.core.metrics;
|
||||||
|
|
||||||
import com.codahale.metrics.Metric;
|
import com.codahale.metrics.Metric;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.graalvm.polyglot.Value;
|
import org.graalvm.polyglot.Value;
|
||||||
import org.graalvm.polyglot.proxy.ProxyObject;
|
import org.graalvm.polyglot.proxy.ProxyObject;
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import java.security.InvalidParameterException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class MetricMap implements ProxyObject {
|
public class MetricMap implements ProxyObject {
|
||||||
@ -30,56 +32,62 @@ public class MetricMap implements ProxyObject {
|
|||||||
private final String parent_name;
|
private final String parent_name;
|
||||||
private final HashMap<String, Object> map = new HashMap<>();
|
private final HashMap<String, Object> map = new HashMap<>();
|
||||||
|
|
||||||
|
public final static char DELIM = '.';
|
||||||
|
|
||||||
public MetricMap(String name, String parent) {
|
public MetricMap(String name, String parent) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parent_name = parent;
|
this.parent_name = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetricMap findOwner(String metricName) {
|
public MetricMap() {
|
||||||
|
this("ROOT", "ROOT"); // because of auto-intern, the root node is the only one with parent==parent
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetricMap findOrCreateDottedParentPath(String metricName) {
|
||||||
String[] names = metricName.split("\\.");
|
String[] names = metricName.split("\\.");
|
||||||
String[] pathTraversal = Arrays.copyOfRange(names, 0, names.length - 1);
|
String[] pathTraversal = Arrays.copyOfRange(names, 0, names.length - 1);
|
||||||
MetricMap owner = findPath(pathTraversal);
|
MetricMap owner = findOrCreateNodePath(pathTraversal);
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MetricMap findOrCreateDottedNodePath(String nodeName) {
|
||||||
|
String[] names = nodeName.split("\\.");
|
||||||
|
MetricMap owner = findOrCreateNodePath(names);
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "MetricMap{" +
|
return "MetricMap{" +
|
||||||
"name='" + name + '\'' +
|
"name='" + name + '\'' +
|
||||||
", map=" + map +
|
", map=" + map +
|
||||||
(parent_name!=null ? ", parent=" + parent_name : "") +
|
(parent_name != null ? ", parent=" + parent_name : "") +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetricMap findPath(String... names) {
|
/**
|
||||||
MetricMap current = this;
|
* Given an array of non-delimited component names, walk from the root node to each name, creating any needed nodes
|
||||||
for (int i = 0; i < names.length; i++) {
|
* along the way.
|
||||||
String edgeName = names[i];
|
*
|
||||||
|
* @param names the names of the nodes to traverse or create
|
||||||
if (current.map.containsKey(edgeName)) {
|
* @return The MetricMap node in the node tree with the given path-wise address.
|
||||||
Object element = current.map.get(edgeName);
|
* @throws InvalidParameterException if any of the component names includes a delimiter
|
||||||
if (element instanceof MetricMap) {
|
*/
|
||||||
current = (MetricMap) element;
|
public MetricMap findOrCreateNodePath(String... names) {
|
||||||
logger.trace(() -> "traversing edge:" + edgeName);
|
if (names.length == 0) {
|
||||||
} else {
|
return this;
|
||||||
String error = "edge exists at level:" + i;
|
|
||||||
logger.error(error);
|
|
||||||
throw new RuntimeException(error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MetricMap newMap = new MetricMap(edgeName,this.name);
|
|
||||||
current.map.put(edgeName, newMap);
|
|
||||||
current = newMap;
|
|
||||||
logger.trace(() -> "adding edge:" + edgeName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return current;
|
String nodeName = names[0];
|
||||||
|
if (nodeName.contains(String.valueOf(DELIM))) {
|
||||||
|
throw new InvalidParameterException("Path components must not include interior delimiters. (" + DELIM + ").");
|
||||||
|
}
|
||||||
|
MetricMap childNode = (MetricMap) map.computeIfAbsent(nodeName, name -> new MetricMap(names[0], this.name));
|
||||||
|
return childNode.findOrCreateNodePath(Arrays.copyOfRange(names, 1, names.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(String name, Metric metric) {
|
public void add(String name, Metric metric) {
|
||||||
MetricMap owner = findOwner(name);
|
MetricMap owner = findOrCreateDottedParentPath(name);
|
||||||
String leafName = name.substring(name.lastIndexOf(".")+1);
|
String leafName = name.substring(name.lastIndexOf(".") + 1);
|
||||||
owner.map.put(leafName,metric);
|
owner.map.put(leafName, metric);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(String name) {
|
public void remove(String name) {
|
||||||
@ -100,6 +108,9 @@ public class MetricMap implements ProxyObject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getMember(String key) {
|
public Object getMember(String key) {
|
||||||
|
if (key.contains(".")) {
|
||||||
|
throw new InvalidParameterException("Members of the metrics registry tree must have names which do not include the '.' delimiter.");
|
||||||
|
}
|
||||||
Object got = get(key);
|
Object got = get(key);
|
||||||
return got;
|
return got;
|
||||||
}
|
}
|
||||||
@ -120,4 +131,13 @@ public class MetricMap implements ProxyObject {
|
|||||||
public void putMember(String key, Value value) {
|
public void putMember(String key, Value value) {
|
||||||
throw new RuntimeException("Not allowed here");
|
throw new RuntimeException("Not allowed here");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = name != null ? name.hashCode() : 0;
|
||||||
|
result = 31 * result + (parent_name != null ? parent_name.hashCode() : 0);
|
||||||
|
result = 31 * result + map.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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.engine.core.metrics;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class MetricMapTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNodeByNodeConstruction() {
|
||||||
|
MetricMap root = new MetricMap();
|
||||||
|
MetricMap alpha = root.findOrCreateNodePath("alpha");
|
||||||
|
MetricMap beta = alpha.findOrCreateNodePath("beta");
|
||||||
|
MetricMap gamma = beta.findOrCreateNodePath("gamma");
|
||||||
|
|
||||||
|
assertThat(root.containsKey("alpha")).isTrue();
|
||||||
|
assertThat(root.findOrCreateNodePath("alpha","beta","gamma")==gamma).isTrue();
|
||||||
|
assertThat(root.findOrCreateDottedNodePath("alpha.beta.gamma")==gamma).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConcatenatedConstruction() {
|
||||||
|
MetricMap root = new MetricMap();
|
||||||
|
MetricMap gamma = root.findOrCreateDottedNodePath("alpha.beta.gamma");
|
||||||
|
assertThat(root.findOrCreateDottedParentPath("alpha.beta.gamma.abstract_leaf_node")).isEqualTo(gamma);
|
||||||
|
MetricMap alpha = root.findOrCreateDottedParentPath("alpha.beta");
|
||||||
|
MetricMap beta = alpha.findOrCreateDottedParentPath("beta.gamma");
|
||||||
|
MetricMap betaToo = beta.findOrCreateDottedParentPath("gamma");
|
||||||
|
assertThat(beta).isEqualTo(betaToo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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.
|
||||||
@ -22,6 +22,7 @@ import com.codahale.metrics.MetricRegistry;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class CSVMetrics {
|
public class CSVMetrics {
|
||||||
@ -80,6 +81,7 @@ public class CSVMetrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CSVMetrics add(Metric metric) {
|
public CSVMetrics add(Metric metric) {
|
||||||
|
Objects.requireNonNull(metric);
|
||||||
filter.add(metric);
|
filter.add(metric);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
@ -40,7 +40,7 @@ public class CSVMetricsPlugin {
|
|||||||
*/
|
*/
|
||||||
public CSVMetrics log(String filename) {
|
public CSVMetrics log(String filename) {
|
||||||
CSVMetrics csvMetrics = new CSVMetrics(filename, logger, metricRegistry);
|
CSVMetrics csvMetrics = new CSVMetrics(filename, logger, metricRegistry);
|
||||||
writeStdout("started new csvlogger: " + filename + "\n");
|
writeStdout("started new csvmetrics: " + filename + "\n");
|
||||||
return csvMetrics;
|
return csvMetrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,4 +87,9 @@ public class NBMetricTimer extends Timer implements DeltaSnapshotter, HdrDeltaHi
|
|||||||
public NBLabels getLabels() {
|
public NBLabels getLabels() {
|
||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "NBTIMER:"+this.getLabels().toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
@ -20,11 +20,13 @@ activitydef = {
|
|||||||
"alias" : "csvmetrics",
|
"alias" : "csvmetrics",
|
||||||
"driver" : "diag",
|
"driver" : "diag",
|
||||||
"cycles" : "50000",
|
"cycles" : "50000",
|
||||||
"threads" : "20",
|
"threads" : "1",
|
||||||
"op": '{"log":"level=debug,interval=1000"}',
|
"op": "log: level=debug",
|
||||||
"targetrate" : "10000.0"
|
"rate" : "100.0"
|
||||||
};
|
};
|
||||||
scenario.start(activitydef);
|
scenario.start(activitydef);
|
||||||
|
scenario.waitMillis(500);
|
||||||
|
|
||||||
csvlogger.add(metrics.csvmetrics.cycles.servicetime);
|
csvlogger.add(metrics.csvmetrics.cycles.servicetime);
|
||||||
csvlogger.start(500,"MILLISECONDS");
|
csvlogger.start(500,"MILLISECONDS");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user