Allow Plural for Types in TagFilters (#2085)

* Allow Plural for Types in TagFilters

* Moved the plural trick into flow. Add advisor output

* Previous logging of TagFilter is sufficient

* Add in Advisor
This commit is contained in:
Dave Fisher 2024-11-19 13:35:01 -08:00 committed by GitHub
parent 68b148575f
commit 8a3e849ff1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 12 deletions

View File

@ -31,20 +31,21 @@ public class NBAdvisorOutput {
} }
public static void test(String message) { public static void test(String message) {
output(Level.WARN, message);
if (NBAdvisorLevel.get() == NBAdvisorLevel.enforce) { if (NBAdvisorLevel.get() == NBAdvisorLevel.enforce) {
throw new NBAdvisorException(message, 2); output(Level.ERROR, message);
throw new NBAdvisorException(message, 2);
} }
output(Level.WARN, message);
} }
public static void output(Level level,String message) { public static void output(Level level,String message) {
if (level == Level.INFO) { if (level == Level.INFO) {
logger.info(message); NBAdvisorOutput.logger.info(message);
} else if (level == Level.WARN) { } else if (level == Level.WARN) {
logger.warn(message); NBAdvisorOutput.logger.warn(message);
} else if (level == Level.ERROR) { } else if (level == Level.ERROR) {
logger.error(message); NBAdvisorOutput.logger.error(message);
} }
} }
} }

View File

@ -19,6 +19,9 @@ package io.nosqlbench.nb.api.tagging;
import io.nosqlbench.nb.api.engine.util.Tagged; import io.nosqlbench.nb.api.engine.util.Tagged;
import io.nosqlbench.nb.api.labels.NBLabeledElement; import io.nosqlbench.nb.api.labels.NBLabeledElement;
import io.nosqlbench.nb.api.components.core.NBComponent; import io.nosqlbench.nb.api.components.core.NBComponent;
import io.nosqlbench.nb.api.advisor.NBAdvisorOutput;
import org.apache.logging.log4j.Level;
import java.util.*; import java.util.*;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@ -198,7 +201,17 @@ public class TagFilter {
boolean matchedKey = true; boolean matchedKey = true;
String filterval = filter.get(filterkey); String filterval = filter.get(filterkey);
String itemval = tags.get(filterkey); String itemval = tags.get(filterkey);
if ( itemval == null ) {
// tag category not found, if ends in an 's' then try singular
if (filterkey.endsWith("s")) {
String filterkey2 = filterkey.substring(0, filterkey.length() - 1);
itemval = tags.get(filterkey2);
String message = "'" + filterkey + "' tags do not exist: try '" + filterkey2 + "'";
NBAdvisorOutput.test(message);
log.add("(☐, ) " + message);
filterkey = filterkey2;
}
}
String detail = "filter(" + filterkey + String detail = "filter(" + filterkey +
((filterval != null) ? ":" + filterval : "") + ") " + ((filterval != null) ? ":" + filterval : "") + ") " +

View File

@ -77,6 +77,21 @@ public class TagFilterTest {
assertThat(tf.matches(itemtags2).matched()).isTrue(); assertThat(tf.matches(itemtags2).matched()).isTrue();
} }
@Test
public void testMatchingTagKeysValueDoesMatch() {
Map<String, String> itemtags = new HashMap<>() {{
put("one", "two");
}};
TagFilter tf = new TagFilter("ones");
TagFilter.Result result = tf.matches(itemtags);
assertThat(result.matched()).isTrue();
Map<String, String> itemtags2 = new HashMap<>() {{
put("one", null);
}};
assertThat(tf.matches(itemtags2).matched()).isTrue();
}
@Test @Test
public void testMatchingKeyMismatchingValueDoesNotMatch() { public void testMatchingKeyMismatchingValueDoesNotMatch() {
Map<String, String> itemtags = new HashMap<>() {{ Map<String, String> itemtags = new HashMap<>() {{

View File

@ -416,7 +416,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
"progress", options.getProgressSpec(), "progress", options.getProgressSpec(),
"prompush_cache", "prompush_cache.txt", "prompush_cache", "prompush_cache.txt",
"heartbeat", String.valueOf(options.wantsHeartbeatIntervalMs()), "heartbeat", String.valueOf(options.wantsHeartbeatIntervalMs()),
"advisor", String.valueOf(options.getAdvisor()) "advisor", String.valueOf(options.getAdvisor())
); );
try ( try (