TagFilter Error Advisor (#2097)

* TagFilter Error Advisor

* Fix comment detection bug

* Fix the pattern
This commit is contained in:
Dave Fisher 2024-11-22 09:03:15 -08:00 committed by GitHub
parent 6e83655b57
commit 86b2495aed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 5 deletions

View File

@ -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<String, String> {
.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<String, String> {
multimap.add(basicMap);
}
public boolean isComment(String line) {
return line != null && COMMENT.matcher(line).matches();
}
// for testing
protected StrInterpolator(List<Map<String, String>> maps) {
maps.forEach(multimap::add);
@ -58,7 +64,7 @@ public class StrInterpolator implements Function<String, String> {
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;

View File

@ -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

View File

@ -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());