diff --git a/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLI.java b/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLI.java index 67544afbe..5937bc347 100644 --- a/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLI.java +++ b/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLI.java @@ -282,6 +282,7 @@ public class NBCLI implements Function, NBLabeledElement { NBIO.addGlobalIncludes(options.wantsIncludes()); ActivityMetrics.setHdrDigits(options.getHdrDigits()); + ActivityMetrics.setLabelValidator(options.getAnnotateLabelSpec()); if (options.wantsBasicHelp()) { System.out.println(this.loadHelpFile("basic.md")); diff --git a/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLIArgsFile.java b/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLIArgsFile.java index 1788e5fe6..fe2835368 100644 --- a/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLIArgsFile.java +++ b/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLIArgsFile.java @@ -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; } diff --git a/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLIOptions.java b/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLIOptions.java index 97ad8d355..bf7026f03 100644 --- a/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLIOptions.java +++ b/engine-cli/src/main/java/io/nosqlbench/engine/cli/NBCLIOptions.java @@ -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"; @@ -201,10 +204,14 @@ public class NBCLIOptions { private boolean wantsListCommands; private boolean wantsListApps; private boolean dedicatedVerificationLogger; - private boolean wantsConsoleMetrics =true; - private String annotateLabelSpec=""; + 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,22 +502,34 @@ 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); break; case NBCLIOptions.ENABLE_LOGGED_METRICS: arglist.removeFirst(); - this.wantsConsoleMetrics =true; + this.wantsConsoleMetrics = true; break; case NBCLIOptions.DISABLE_LOGGED_METRICS: 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; 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()); } diff --git a/engine-clients/src/main/java/io/nosqlbench/engine/clients/grafana/annotator/GrafanaMetricsAnnotator.java b/engine-clients/src/main/java/io/nosqlbench/engine/clients/grafana/annotator/GrafanaMetricsAnnotator.java index be7977400..57185ebd7 100644 --- a/engine-clients/src/main/java/io/nosqlbench/engine/clients/grafana/annotator/GrafanaMetricsAnnotator.java +++ b/engine-clients/src/main/java/io/nosqlbench/engine/clients/grafana/annotator/GrafanaMetricsAnnotator.java @@ -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(); diff --git a/engine-core/src/main/java/io/nosqlbench/engine/core/annotation/Annotators.java b/engine-core/src/main/java/io/nosqlbench/engine/core/annotation/Annotators.java index bd39be295..41d8e451d 100644 --- a/engine-core/src/main/java/io/nosqlbench/engine/core/annotation/Annotators.java +++ b/engine-core/src/main/java/io/nosqlbench/engine/core/annotation/Annotators.java @@ -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()); diff --git a/nb-api/src/main/java/io/nosqlbench/api/config/standard/NBLabelsValidator.java b/nb-api/src/main/java/io/nosqlbench/api/config/standard/NBLabelsValidator.java index 0e97872a8..ffe1192d9 100644 --- a/nb-api/src/main/java/io/nosqlbench/api/config/standard/NBLabelsValidator.java +++ b/nb-api/src/main/java/io/nosqlbench/api/config/standard/NBLabelsValidator.java @@ -49,7 +49,7 @@ public class NBLabelsValidator implements Function { 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 { } - record Result(String config, LinkedList missingFields, LinkedList extraneousFields) { + record Result(NBLabels labels, String config, LinkedList missingFields, LinkedList extraneousFields) { public boolean isError() { return !missingFields.isEmpty() || !extraneousFields.isEmpty(); } diff --git a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/ActivityMetrics.java b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/ActivityMetrics.java index 0c371d212..464f078a0 100644 --- a/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/ActivityMetrics.java +++ b/nb-api/src/main/java/io/nosqlbench/api/engine/metrics/ActivityMetrics.java @@ -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 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(); }