mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-01-11 00:12:04 -06:00
enable label filtering and validation
This commit is contained in:
parent
2d1f23a8d8
commit
17fa8500ab
@ -282,6 +282,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
|
||||
NBIO.addGlobalIncludes(options.wantsIncludes());
|
||||
|
||||
ActivityMetrics.setHdrDigits(options.getHdrDigits());
|
||||
ActivityMetrics.setLabelValidator(options.getAnnotateLabelSpec());
|
||||
|
||||
if (options.wantsBasicHelp()) {
|
||||
System.out.println(this.loadHelpFile("basic.md"));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* 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.
|
||||
@ -466,6 +466,11 @@ public class NBCLIArgsFile {
|
||||
} else {
|
||||
args.add(line);
|
||||
}
|
||||
if ((args.peekLast().startsWith("\"") && args.peekLast().endsWith("\""))||(
|
||||
(args.peekLast().startsWith("'") && args.peekLast().endsWith("'")))) {
|
||||
String unquote = args.removeLast();
|
||||
args.addLast(unquote.substring(1, unquote.length()-1));
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
@ -54,6 +54,8 @@ public class NBCLIOptions {
|
||||
private static final String ANNOTATE_EVENTS = "--annotate";
|
||||
|
||||
private static final String ANNOTATE_LABELSPEC = "--annotate-labelspec";
|
||||
private static final String METRICS_LABELSPEC = "--metrics-labelspec";
|
||||
private static final String LABELSPEC = "--labelspec";
|
||||
private static final String ANNOTATORS_CONFIG = "--annotators";
|
||||
private static final String PROMPUSH_CONFIG = "--prompush";
|
||||
|
||||
@ -86,6 +88,7 @@ public class NBCLIOptions {
|
||||
|
||||
private static final String SET_LABELS = "--set-labels";
|
||||
private static final String ADD_LABELS = "--add-labels";
|
||||
private static final String ADD_LABEL = "--add-label";
|
||||
|
||||
// Execution
|
||||
private static final String EXPORT_CYCLE_LOG = "--export-cycle-log";
|
||||
@ -203,8 +206,12 @@ public class NBCLIOptions {
|
||||
private boolean dedicatedVerificationLogger;
|
||||
private boolean wantsConsoleMetrics = true;
|
||||
private String annotateLabelSpec = "";
|
||||
private String metricsLabelSpec = "";
|
||||
|
||||
public boolean wantsLoggedMetrics() {
|
||||
return this.wantsConsoleMetrics;
|
||||
}
|
||||
|
||||
public boolean wantsLoggedMetrics() { return this.wantsConsoleMetrics; }
|
||||
public boolean isWantsListApps() {
|
||||
return this.wantsListApps;
|
||||
}
|
||||
@ -265,6 +272,10 @@ public class NBCLIOptions {
|
||||
return annotateLabelSpec;
|
||||
}
|
||||
|
||||
public String getMetricsLabelSpec() {
|
||||
return metricsLabelSpec;
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
ParseGlobalsOnly,
|
||||
ParseAllOptions
|
||||
@ -491,7 +502,8 @@ public class NBCLIOptions {
|
||||
String setLabelData = arglist.removeFirst();
|
||||
setLabels(setLabelData);
|
||||
break;
|
||||
case NBCLIOptions.ADD_LABELS:
|
||||
case ADD_LABELS:
|
||||
case ADD_LABEL:
|
||||
arglist.removeFirst();
|
||||
String addLabeldata = arglist.removeFirst();
|
||||
addLabels(addLabeldata);
|
||||
@ -504,9 +516,20 @@ public class NBCLIOptions {
|
||||
arglist.removeFirst();
|
||||
this.wantsConsoleMetrics = false;
|
||||
break;
|
||||
case LABELSPEC:
|
||||
arglist.removeFirst();
|
||||
String labelspec = this.readWordOrThrow(arglist, "label validator specification for metric labels and annotation tags");
|
||||
this.annotateLabelSpec = labelspec;
|
||||
this.metricsLabelSpec = labelspec;
|
||||
break;
|
||||
case ANNOTATE_LABELSPEC:
|
||||
arglist.removeFirst();
|
||||
this.annotateLabelSpec = this.readWordOrThrow(arglist, "labels validator specification");
|
||||
this.annotateLabelSpec = this.readWordOrThrow(arglist, "labels validator specification for annotation tags from labels");
|
||||
break;
|
||||
case METRICS_LABELSPEC:
|
||||
arglist.remove();
|
||||
this.metricsLabelSpec = this.readWordOrThrow(arglist, "labels validator specification for metric labels");
|
||||
break;
|
||||
default:
|
||||
nonincludes.addLast(arglist.removeFirst());
|
||||
}
|
||||
|
@ -53,6 +53,8 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
|
||||
|
||||
@Override
|
||||
public void recordAnnotation(Annotation annotation) {
|
||||
// sanity check here first, before going into the error policy
|
||||
|
||||
try {
|
||||
GAnnotation ga = new GAnnotation();
|
||||
|
||||
|
@ -124,6 +124,8 @@ public class Annotators {
|
||||
public static synchronized void recordAnnotation(Annotation annotation) {
|
||||
annotation.applyLabelFunction(filter);
|
||||
annotation.applyLabelFunction(validator);
|
||||
// sanity check here first
|
||||
annotation.getLabels();
|
||||
for (Annotator annotator : getAnnotators()) {
|
||||
try {
|
||||
logger.trace(() -> "calling annotator " + annotator.getClass().getAnnotation(Service.class).selector());
|
||||
|
@ -49,7 +49,7 @@ public class NBLabelsValidator implements Function<NBLabels, NBLabels> {
|
||||
missingFields.removeIf(keyset::contains);
|
||||
extraneousFields.removeIf(extra -> !keyset.contains(extra));
|
||||
|
||||
Result result = new Result(config, missingFields, extraneousFields);
|
||||
Result result = new Result(labels, config, missingFields, extraneousFields);
|
||||
if (!result.isError()) {
|
||||
return labels;
|
||||
}
|
||||
@ -58,7 +58,7 @@ public class NBLabelsValidator implements Function<NBLabels, NBLabels> {
|
||||
}
|
||||
|
||||
|
||||
record Result(String config, LinkedList<String> missingFields, LinkedList<String> extraneousFields) {
|
||||
record Result(NBLabels labels, String config, LinkedList<String> missingFields, LinkedList<String> extraneousFields) {
|
||||
public boolean isError() {
|
||||
return !missingFields.isEmpty() || !extraneousFields.isEmpty();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import com.codahale.metrics.*;
|
||||
import io.nosqlbench.api.config.NBLabeledElement;
|
||||
import io.nosqlbench.api.config.NBLabels;
|
||||
import io.nosqlbench.api.config.NBNamedElement;
|
||||
import io.nosqlbench.api.config.standard.NBLabelsFilter;
|
||||
import io.nosqlbench.api.engine.activityapi.core.MetricRegistryService;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.*;
|
||||
import io.nosqlbench.api.engine.util.Unit;
|
||||
@ -49,6 +50,8 @@ public class ActivityMetrics {
|
||||
return true;
|
||||
};
|
||||
private static final List<MetricsCloseable> metricsCloseables = new ArrayList<>();
|
||||
private static NBLabelsFilter labelValidator;
|
||||
private static NBLabelsFilter labelFilter;
|
||||
|
||||
|
||||
public static int getHdrDigits() {
|
||||
@ -73,6 +76,9 @@ public class ActivityMetrics {
|
||||
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
|
||||
private static Metric register(NBLabels labels, MetricProvider metricProvider) {
|
||||
|
||||
labels = labelFilter.apply(labels);
|
||||
labels = labelValidator.apply(labels);
|
||||
|
||||
final String graphiteName = labels.linearizeValues('.',"[activity]","[space]","[op]","name");
|
||||
Metric metric = get().getMetrics().get(graphiteName);
|
||||
|
||||
@ -339,6 +345,11 @@ public class ActivityMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLabelValidator(String annotateLabelSpec) {
|
||||
labelValidator = new NBLabelsFilter(annotateLabelSpec);
|
||||
labelFilter = new NBLabelsFilter(annotateLabelSpec);
|
||||
}
|
||||
|
||||
private interface MetricProvider {
|
||||
Metric getMetric();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user