From 46978e23be3ff84929ee9c8a345fc9dadbef0bec Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 19 Mar 2019 09:32:54 +0100 Subject: Add &explainleve= --- container-search/abi-spec.json | 3 ++ .../src/main/java/com/yahoo/search/Query.java | 34 +++++++++++++++++++++- .../com/yahoo/search/handler/SearchHandler.java | 3 +- .../search/query/properties/QueryProperties.java | 3 ++ .../java/com/yahoo/search/test/QueryTestCase.java | 7 +++++ 5 files changed, 48 insertions(+), 2 deletions(-) (limited to 'container-search') diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json index 02f82762d57..885b157b4c3 100644 --- a/container-search/abi-spec.json +++ b/container-search/abi-spec.json @@ -1737,7 +1737,9 @@ "public void setTimeout(java.lang.String)", "public void resetTimeout()", "public void setTraceLevel(int)", + "public void setExplainLevel(int)", "public int getTraceLevel()", + "public int getExplainLevel()", "public final boolean isTraceable(int)", "public boolean getNoCache()", "public void setNoCache(boolean)", @@ -1784,6 +1786,7 @@ "public static final com.yahoo.processing.request.CompoundName QUERY_PROFILE", "public static final com.yahoo.processing.request.CompoundName SEARCH_CHAIN", "public static final com.yahoo.processing.request.CompoundName TRACE_LEVEL", + "public static final com.yahoo.processing.request.CompoundName EXPLAIN_LEVEL", "public static final com.yahoo.processing.request.CompoundName NO_CACHE", "public static final com.yahoo.processing.request.CompoundName GROUPING_SESSION_CACHE", "public static final com.yahoo.processing.request.CompoundName TIMEOUT", diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java index 97a8c35bfa3..b292dec4bfc 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -137,6 +137,9 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { /** The query context level, 0 means no tracing */ private int traceLevel = 0; + /** The query explain level, 0 means no explaining */ + private int explainLevel = 0; + // The timeout to be used when dumping rank features private static final long dumpTimeout = (6 * 60 * 1000); // 6 minutes private static final long defaultTimeout = 500; @@ -190,6 +193,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { public static final CompoundName QUERY_PROFILE = new CompoundName("queryProfile"); public static final CompoundName SEARCH_CHAIN = new CompoundName("searchChain"); public static final CompoundName TRACE_LEVEL = new CompoundName("traceLevel"); + public static final CompoundName EXPLAIN_LEVEL = new CompoundName("explainLevel"); public static final CompoundName NO_CACHE = new CompoundName("noCache"); public static final CompoundName GROUPING_SESSION_CACHE = new CompoundName("groupingSessionCache"); public static final CompoundName TIMEOUT = new CompoundName("timeout"); @@ -205,6 +209,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { argumentType.addField(new FieldDescription(QUERY_PROFILE.toString(), "string")); argumentType.addField(new FieldDescription(SEARCH_CHAIN.toString(), "string")); argumentType.addField(new FieldDescription(TRACE_LEVEL.toString(), "integer", "tracelevel")); + argumentType.addField(new FieldDescription(EXPLAIN_LEVEL.toString(), "integer", "explainlevel")); argumentType.addField(new FieldDescription(NO_CACHE.toString(), "boolean", "nocache")); argumentType.addField(new FieldDescription(GROUPING_SESSION_CACHE.toString(), "boolean", "groupingSessionCache")); argumentType.addField(new FieldDescription(TIMEOUT.toString(), "string", "timeout")); @@ -565,6 +570,11 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { * Higher numbers means increasingly more tracing */ public void setTraceLevel(int traceLevel) { this.traceLevel = traceLevel; } + /** + * Sets the explain level of this query, 0 means no tracing + * Higher numbers means increasingly more explaining + */ + public void setExplainLevel(int explainLevel) { this.explainLevel = explainLevel; } /** * Returns the context level of this query, 0 means no tracing @@ -572,6 +582,12 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { */ public int getTraceLevel() { return traceLevel; } + /** + * Returns the explain level of this query, 0 means no tracing + * Higher numbers means increasingly more explaining + */ + public int getExplainLevel() { return explainLevel; } + /** * Returns the context level of this query, 0 means no tracing * Higher numbers means increasingly more tracing @@ -747,6 +763,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { */ public void attachContext(Query query) throws IllegalStateException { query.setTraceLevel(getTraceLevel()); + query.setExplainLevel(getExplainLevel()); if (context == null) { // Nothing to attach to. This is about the same as // getTraceLevel() == 0, @@ -962,6 +979,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { assert (clone.properties().getParentQuery() == clone); clone.setTraceLevel(getTraceLevel()); + clone.setExplainLevel(getExplainLevel()); clone.setHits(getHits()); clone.setOffset(getOffset()); clone.setNoCache(getNoCache()); @@ -1066,10 +1084,24 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { return Collections.emptyMap(); } + private int computeTraceLevelForBackend() { + int traceLevel = getTraceLevel(); + if (model.getExecution().trace().getForceTimestamps()) { + traceLevel = Math.max(traceLevel, 5); // Backend produces timing information on level 4 and 5 + } + if (getExplainLevel() > 0) { + traceLevel = Math.max(traceLevel, getExplainLevel() + 5); + } + return traceLevel; + } + private Map createModelMap() { Map m = new HashMap<>(); if (model.getSearchPath() != null) m.put("searchpath", model.getSearchPath()); - if (getTraceLevel() > 0) m.put("tracelevel", String.valueOf(getTraceLevel())); + + int traceLevel = computeTraceLevelForBackend(); + if (traceLevel > 0) m.put("tracelevel", String.valueOf(traceLevel)); + return m; } diff --git a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java index 14a15e71bf7..cb69f2abd07 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java +++ b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java @@ -81,6 +81,8 @@ public class SearchHandler extends LoggingRequestHandler { private final int maxThreads; private static final CompoundName DETAILED_TIMING_LOGGING = new CompoundName("trace.timingDetails"); + private static final CompoundName FORCE_TIMESTAMPS = new CompoundName("trace.timestamps"); + /** Event name for number of connections to the search subsystem */ private static final String SEARCH_CONNECTIONS = "search_connections"; @@ -101,7 +103,6 @@ public class SearchHandler extends LoggingRequestHandler { public static final String defaultSearchChainName = "default"; private static final String fallbackSearchChain = "vespa"; - private static final CompoundName FORCE_TIMESTAMPS = new CompoundName("trace.timestamps");; private final Linguistics linguistics; diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java index ac0e715abd2..a510c5f9564 100644 --- a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java @@ -126,6 +126,7 @@ public class QueryProperties extends Properties { if (key.equals(Query.HITS)) return query.getHits(); if (key.equals(Query.OFFSET)) return query.getOffset(); if (key.equals(Query.TRACE_LEVEL)) return query.getTraceLevel(); + if (key.equals(Query.EXPLAIN_LEVEL)) return query.getExplainLevel(); if (key.equals(Query.TIMEOUT)) return query.getTimeout(); if (key.equals(Query.NO_CACHE)) return query.getNoCache(); if (key.equals(Query.GROUPING_SESSION_CACHE)) return query.getGroupingSessionCache(); @@ -266,6 +267,8 @@ public class QueryProperties extends Properties { query.setOffset(asInteger(value,0)); else if (key.equals(Query.TRACE_LEVEL)) query.setTraceLevel(asInteger(value,0)); + else if (key.equals(Query.EXPLAIN_LEVEL)) + query.setExplainLevel(asInteger(value,0)); else if (key.equals(Query.TIMEOUT)) query.setTimeout(value.toString()); else if (key.equals(Query.NO_CACHE)) diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index 2c094272410..da4b657aca2 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -490,6 +490,13 @@ public class QueryTestCase { assertTrue(traces.contains("trace2 null")); } + @Test + public void testExplain() { + Query q = new Query("?query=foo&explainLevel=2"); + assertEquals(2, q.getExplainLevel()); + assertEquals(0, q.getTraceLevel()); + } + @Test public void testQueryPropertyResolveTracing() { QueryProfile testProfile = new QueryProfile("test"); -- cgit v1.2.3