From 86b2495aed63c07bd105198ce42fb3b17019b79f Mon Sep 17 00:00:00 2001 From: Dave Fisher Date: Fri, 22 Nov 2024 09:03:15 -0800 Subject: [PATCH] TagFilter Error Advisor (#2097) * TagFilter Error Advisor * Fix comment detection bug * Fix the pattern --- .../api/templating/StrInterpolator.java | 8 +++++++- .../api/templating/StrInterpolatorTest.java | 18 ++++++++++++++++-- .../api/activityimpl/SimpleActivity.java | 7 +++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/nb-apis/adapters-api/src/main/java/io/nosqlbench/adapters/api/templating/StrInterpolator.java b/nb-apis/adapters-api/src/main/java/io/nosqlbench/adapters/api/templating/StrInterpolator.java index f78de1a25..c2e6403ef 100644 --- a/nb-apis/adapters-api/src/main/java/io/nosqlbench/adapters/api/templating/StrInterpolator.java +++ b/nb-apis/adapters-api/src/main/java/io/nosqlbench/adapters/api/templating/StrInterpolator.java @@ -24,6 +24,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Level; +import java.util.regex.Pattern; import java.util.*; import java.util.function.Function; @@ -36,6 +37,7 @@ public class StrInterpolator implements Function { .setEnableSubstitutionInVariables(true) .setEnableUndefinedVariableException(true) .setDisableSubstitutionInValues(true); + private final Pattern COMMENT = Pattern.compile("^\\s*#.*"); public StrInterpolator(ActivityDef... activityDefs) { Arrays.stream(activityDefs) @@ -47,6 +49,10 @@ public class StrInterpolator implements Function { multimap.add(basicMap); } + public boolean isComment(String line) { + return line != null && COMMENT.matcher(line).matches(); + } + // for testing protected StrInterpolator(List> maps) { maps.forEach(multimap::add); @@ -58,7 +64,7 @@ public class StrInterpolator implements Function { boolean endsWithNewline = raw.endsWith("\n"); int i = 0; for (String line : lines) { - if (!line.startsWith("#")) { + if (!isComment(line)) { String result = matchTemplates(line); if (!result.equals(line)) { lines[i] = result; diff --git a/nb-apis/adapters-api/src/test/java/io/nosqlbench/adapters/api/templating/StrInterpolatorTest.java b/nb-apis/adapters-api/src/test/java/io/nosqlbench/adapters/api/templating/StrInterpolatorTest.java index 17cf95ce8..42a10aa4a 100644 --- a/nb-apis/adapters-api/src/test/java/io/nosqlbench/adapters/api/templating/StrInterpolatorTest.java +++ b/nb-apis/adapters-api/src/test/java/io/nosqlbench/adapters/api/templating/StrInterpolatorTest.java @@ -113,8 +113,18 @@ public class StrInterpolatorTest { @Test public void shouldMatchWithComments() { StrInterpolator interp = new StrInterpolator(abcd); - String a = interp.apply("TEMPLATE(start,START)\n# TEMPLATE(blahblah,blah)\nTEMPLATE(keydist,Uniform(0,1000000000)->int);"); - assertThat(a).isEqualTo("START\n# TEMPLATE(blahblah,blah)\nUniform(0,1000000000)->int;"); + String a = interp.apply(""" + TEMPLATE(start,START) + # TEMPLATE(blahblah,blah) + TEMPLATE(keydist,Uniform(0,1000000000)->int); + # TEMPLATE(blahblah,blah) + """); + assertThat(a).isEqualTo(""" + START + # TEMPLATE(blahblah,blah) + Uniform(0,1000000000)->int; + # TEMPLATE(blahblah,blah) + """); } @Test @@ -126,6 +136,10 @@ public class StrInterpolatorTest { assertThat(b).isEqualTo("-setme-setyou-"); String c = interp.apply("-${setkey:=setme}-${setkey3:+setme}-${setkey:+setyou}-"); assertThat(c).isEqualTo("-setme-setme-setyou-"); + String d = interp.apply("-${setkey:+${setkey3:+setme}}-"); + assertThat(d).isEqualTo("-setme-"); + String e = interp.apply("-${${setkey3:+setkey}}-"); + assertThat(e).isEqualTo("-setme-"); } @Test diff --git a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java index 99af27680..61cba931e 100644 --- a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java +++ b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java @@ -41,6 +41,7 @@ import io.nosqlbench.engine.api.activityapi.planning.SequencerType; import io.nosqlbench.engine.api.activityapi.simrate.*; import io.nosqlbench.engine.api.activityimpl.motor.RunStateTally; import io.nosqlbench.engine.core.lifecycle.scenario.container.InvokableResult; +import io.nosqlbench.nb.api.advisor.NBAdvisorOutput; import io.nosqlbench.nb.api.components.core.NBComponent; import io.nosqlbench.nb.api.components.events.ParamChange; import io.nosqlbench.nb.api.components.status.NBStatusComponent; @@ -467,8 +468,10 @@ public class SimpleActivity extends NBStatusComponent implements Activity, Invok // But if there were no ops, and there was no default driver provided, we can't continue // There were no ops, and it was because they were all filtered out if (!unfilteredOps.isEmpty()) { - throw new BasicError("There were no active op templates with tag filter '" - + tagfilter + "', since all " + unfilteredOps.size() + " were filtered out."); + String message = "There were no active op templates with tag filter '"+ tagfilter + "', since all " + + unfilteredOps.size() + " were filtered out. Examine the session log for details"; + NBAdvisorOutput.test(message); + //throw new BasicError(message); } if (defaultDriverAdapter instanceof SyntheticOpTemplateProvider sotp) { filteredOps = sotp.getSyntheticOpTemplates(opsDocList, this.activityDef.getParams());