enable label filtering and validation

This commit is contained in:
Jonathan Shook 2023-09-10 17:37:57 -05:00
parent 2d1f23a8d8
commit 17fa8500ab
7 changed files with 54 additions and 10 deletions

View File

@ -282,6 +282,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
NBIO.addGlobalIncludes(options.wantsIncludes()); NBIO.addGlobalIncludes(options.wantsIncludes());
ActivityMetrics.setHdrDigits(options.getHdrDigits()); ActivityMetrics.setHdrDigits(options.getHdrDigits());
ActivityMetrics.setLabelValidator(options.getAnnotateLabelSpec());
if (options.wantsBasicHelp()) { if (options.wantsBasicHelp()) {
System.out.println(this.loadHelpFile("basic.md")); System.out.println(this.loadHelpFile("basic.md"));

View File

@ -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.
@ -466,6 +466,11 @@ public class NBCLIArgsFile {
} else { } else {
args.add(line); 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; return args;
} }

View File

@ -54,6 +54,8 @@ public class NBCLIOptions {
private static final String ANNOTATE_EVENTS = "--annotate"; private static final String ANNOTATE_EVENTS = "--annotate";
private static final String ANNOTATE_LABELSPEC = "--annotate-labelspec"; 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 ANNOTATORS_CONFIG = "--annotators";
private static final String PROMPUSH_CONFIG = "--prompush"; 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 SET_LABELS = "--set-labels";
private static final String ADD_LABELS = "--add-labels"; private static final String ADD_LABELS = "--add-labels";
private static final String ADD_LABEL = "--add-label";
// Execution // Execution
private static final String EXPORT_CYCLE_LOG = "--export-cycle-log"; private static final String EXPORT_CYCLE_LOG = "--export-cycle-log";
@ -201,10 +204,14 @@ public class NBCLIOptions {
private boolean wantsListCommands; private boolean wantsListCommands;
private boolean wantsListApps; private boolean wantsListApps;
private boolean dedicatedVerificationLogger; private boolean dedicatedVerificationLogger;
private boolean wantsConsoleMetrics =true; private boolean wantsConsoleMetrics = true;
private String annotateLabelSpec=""; private String annotateLabelSpec = "";
private String metricsLabelSpec = "";
public boolean wantsLoggedMetrics() {
return this.wantsConsoleMetrics;
}
public boolean wantsLoggedMetrics() { return this.wantsConsoleMetrics; }
public boolean isWantsListApps() { public boolean isWantsListApps() {
return this.wantsListApps; return this.wantsListApps;
} }
@ -265,6 +272,10 @@ public class NBCLIOptions {
return annotateLabelSpec; return annotateLabelSpec;
} }
public String getMetricsLabelSpec() {
return metricsLabelSpec;
}
public enum Mode { public enum Mode {
ParseGlobalsOnly, ParseGlobalsOnly,
ParseAllOptions ParseAllOptions
@ -491,22 +502,34 @@ public class NBCLIOptions {
String setLabelData = arglist.removeFirst(); String setLabelData = arglist.removeFirst();
setLabels(setLabelData); setLabels(setLabelData);
break; break;
case NBCLIOptions.ADD_LABELS: case ADD_LABELS:
case ADD_LABEL:
arglist.removeFirst(); arglist.removeFirst();
String addLabeldata = arglist.removeFirst(); String addLabeldata = arglist.removeFirst();
addLabels(addLabeldata); addLabels(addLabeldata);
break; break;
case NBCLIOptions.ENABLE_LOGGED_METRICS: case NBCLIOptions.ENABLE_LOGGED_METRICS:
arglist.removeFirst(); arglist.removeFirst();
this.wantsConsoleMetrics =true; this.wantsConsoleMetrics = true;
break; break;
case NBCLIOptions.DISABLE_LOGGED_METRICS: case NBCLIOptions.DISABLE_LOGGED_METRICS:
arglist.removeFirst(); arglist.removeFirst();
this.wantsConsoleMetrics =false; 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; break;
case ANNOTATE_LABELSPEC: case ANNOTATE_LABELSPEC:
arglist.removeFirst(); 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: default:
nonincludes.addLast(arglist.removeFirst()); nonincludes.addLast(arglist.removeFirst());
} }

View File

@ -53,6 +53,8 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
@Override @Override
public void recordAnnotation(Annotation annotation) { public void recordAnnotation(Annotation annotation) {
// sanity check here first, before going into the error policy
try { try {
GAnnotation ga = new GAnnotation(); GAnnotation ga = new GAnnotation();

View File

@ -124,6 +124,8 @@ public class Annotators {
public static synchronized void recordAnnotation(Annotation annotation) { public static synchronized void recordAnnotation(Annotation annotation) {
annotation.applyLabelFunction(filter); annotation.applyLabelFunction(filter);
annotation.applyLabelFunction(validator); annotation.applyLabelFunction(validator);
// sanity check here first
annotation.getLabels();
for (Annotator annotator : getAnnotators()) { for (Annotator annotator : getAnnotators()) {
try { try {
logger.trace(() -> "calling annotator " + annotator.getClass().getAnnotation(Service.class).selector()); logger.trace(() -> "calling annotator " + annotator.getClass().getAnnotation(Service.class).selector());

View File

@ -49,7 +49,7 @@ public class NBLabelsValidator implements Function<NBLabels, NBLabels> {
missingFields.removeIf(keyset::contains); missingFields.removeIf(keyset::contains);
extraneousFields.removeIf(extra -> !keyset.contains(extra)); extraneousFields.removeIf(extra -> !keyset.contains(extra));
Result result = new Result(config, missingFields, extraneousFields); Result result = new Result(labels, config, missingFields, extraneousFields);
if (!result.isError()) { if (!result.isError()) {
return labels; 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() { public boolean isError() {
return !missingFields.isEmpty() || !extraneousFields.isEmpty(); return !missingFields.isEmpty() || !extraneousFields.isEmpty();
} }

View File

@ -20,6 +20,7 @@ import com.codahale.metrics.*;
import io.nosqlbench.api.config.NBLabeledElement; import io.nosqlbench.api.config.NBLabeledElement;
import io.nosqlbench.api.config.NBLabels; import io.nosqlbench.api.config.NBLabels;
import io.nosqlbench.api.config.NBNamedElement; 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.activityapi.core.MetricRegistryService;
import io.nosqlbench.api.engine.metrics.instruments.*; import io.nosqlbench.api.engine.metrics.instruments.*;
import io.nosqlbench.api.engine.util.Unit; import io.nosqlbench.api.engine.util.Unit;
@ -49,6 +50,8 @@ public class ActivityMetrics {
return true; return true;
}; };
private static final List<MetricsCloseable> metricsCloseables = new ArrayList<>(); private static final List<MetricsCloseable> metricsCloseables = new ArrayList<>();
private static NBLabelsFilter labelValidator;
private static NBLabelsFilter labelFilter;
public static int getHdrDigits() { public static int getHdrDigits() {
@ -73,6 +76,9 @@ public class ActivityMetrics {
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private static Metric register(NBLabels labels, MetricProvider metricProvider) { 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"); final String graphiteName = labels.linearizeValues('.',"[activity]","[space]","[op]","name");
Metric metric = get().getMetrics().get(graphiteName); 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 { private interface MetricProvider {
Metric getMetric(); Metric getMetric();
} }