Search in sources :

Example 1 with QueryContext

use of com.yahoo.search.query.context.QueryContext in project vespa by vespa-engine.

the class MetricsSearcher method search.

@Override
public Result search(Query query, Execution execution) {
    long timeMs = System.currentTimeMillis();
    /**
     * Backwards compatibility - convert metricsearcher.id to streaming.loadtype
     */
    String metricName = query.properties().getString(metricsearcherId);
    if (metricName != null) {
        query.properties().set(streamingLoadtype, metricName);
    }
    Result result = execution.search(query);
    long latency = System.currentTimeMillis() - timeMs;
    metricName = query.properties().getString(streamingLoadtype);
    if (metricName == null) {
        return result;
    }
    synchronized (this) {
        Stats stats = statMap.get(metricName);
        if (stats == null) {
            stats = new Stats();
            statMap.put(metricName, stats);
        }
        stats.count++;
        stats.latency += latency;
        if (result.hits().getError() != null && !result.hits().getErrorHit().hasOnlyErrorCode(ErrorMessage.NULL_QUERY) && !result.hits().getErrorHit().hasOnlyErrorCode(3)) {
            stats.failed++;
        } else {
            stats.ok++;
        }
        VisitorStatistics visitorstats = null;
        final QueryContext queryContext = query.getContext(false);
        if (queryContext != null) {
            visitorstats = (VisitorStatistics) queryContext.getProperty(STREAMING_STATISTICS);
        }
        if (visitorstats != null) {
            stats.dataStreamed += visitorstats.getBytesVisited();
            stats.documentsStreamed += visitorstats.getDocumentsVisited();
        } else {
            log.fine("No visitor statistics set in query! - don't use metrics searcher without streaming search");
        }
        if ((timeMs - lastMetricLog) > 60000) {
            for (Map.Entry<String, Stats> entry : statMap.entrySet()) {
                stats = entry.getValue();
                Event.value(entry.getKey() + "_latency", stats.count > 0 ? (double) stats.latency / (double) stats.count : 0);
                Event.value(entry.getKey() + "_ok", stats.ok);
                Event.value(entry.getKey() + "_failed", stats.failed);
                Event.value(entry.getKey() + "_bytesstreamed", stats.dataStreamed);
                Event.value(entry.getKey() + "_documentsstreamed", stats.documentsStreamed);
                stats.latency = 0;
                stats.count = 0;
            }
            lastMetricLog = timeMs;
        }
    }
    return result;
}
Also used : VisitorStatistics(com.yahoo.vdslib.VisitorStatistics) QueryContext(com.yahoo.search.query.context.QueryContext) TreeMap(java.util.TreeMap) Map(java.util.Map) Result(com.yahoo.search.Result)

Example 2 with QueryContext

use of com.yahoo.search.query.context.QueryContext in project vespa by vespa-engine.

the class LoggingTestCase method testLogging.

public void testLogging() {
    Query query = new Query();
    QueryContext queryContext = query.getContext(true);
    queryContext.logValue("a", "a1");
    queryContext.trace("first message", 2);
    queryContext.logValue("a", "a2");
    queryContext.logValue("b", "b1");
    QueryContext h2 = query.clone().getContext(true);
    h2.logValue("b", "b2");
    h2.trace("second message", 2);
    h2.logValue("b", "b3");
    queryContext.logValue("b", "b4");
    QueryContext h3 = query.clone().getContext(true);
    h3.logValue("b", "b5");
    h3.logValue("c", "c1");
    h3.trace("third message", 2);
    h2.logValue("c", "c2");
    queryContext.trace("fourth message", 2);
    queryContext.logValue("d", "d1");
    h2.trace("fifth message", 2);
    h2.logValue("c", "c3");
    queryContext.logValue("c", "c4");
    // Assert that all of the above is in the log, in some undefined order
    Set<String> logValues = new HashSet<>();
    for (Iterator<Execution.Trace.LogValue> logValueIterator = queryContext.logValueIterator(); logValueIterator.hasNext(); ) logValues.add(logValueIterator.next().toString());
    assertEquals(12, logValues.size());
    assertTrue(logValues.contains("a=a1"));
    assertTrue(logValues.contains("a=a2"));
    assertTrue(logValues.contains("b=b1"));
    assertTrue(logValues.contains("b=b2"));
    assertTrue(logValues.contains("b=b3"));
    assertTrue(logValues.contains("b=b4"));
    assertTrue(logValues.contains("b=b5"));
    assertTrue(logValues.contains("c=c1"));
    assertTrue(logValues.contains("c=c2"));
    assertTrue(logValues.contains("d=d1"));
    assertTrue(logValues.contains("c=c3"));
    assertTrue(logValues.contains("c=c4"));
}
Also used : Execution(com.yahoo.processing.execution.Execution) Query(com.yahoo.search.Query) QueryContext(com.yahoo.search.query.context.QueryContext) HashSet(java.util.HashSet)

Example 3 with QueryContext

use of com.yahoo.search.query.context.QueryContext in project vespa by vespa-engine.

the class TraceTestCase method testEmptySubSequence.

public void testEmptySubSequence() {
    Query query = new Query();
    QueryContext h = query.getContext(true);
    query.clone().getContext(true);
    Writer w = new StringWriter();
    try {
        h.render(w);
    } catch (IOException e) {
        assertTrue("rendering empty subsequence crashed", false);
    }
}
Also used : Query(com.yahoo.search.Query) StringWriter(java.io.StringWriter) QueryContext(com.yahoo.search.query.context.QueryContext) IOException(java.io.IOException) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 4 with QueryContext

use of com.yahoo.search.query.context.QueryContext in project vespa by vespa-engine.

the class TraceTestCase method testEmpty.

public void testEmpty() throws IOException {
    Query query = new Query();
    QueryContext h = query.getContext(true);
    Writer w = new StringWriter();
    h.render(w);
    assertEquals("", w.toString());
}
Also used : Query(com.yahoo.search.Query) StringWriter(java.io.StringWriter) QueryContext(com.yahoo.search.query.context.QueryContext) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 5 with QueryContext

use of com.yahoo.search.query.context.QueryContext in project vespa by vespa-engine.

the class TraceTestCase method testCloning.

public void testCloning() throws IOException {
    Query query = new Query();
    QueryContext h = query.getContext(true);
    h.trace("first message", 0);
    QueryContext h2 = query.clone().getContext(true);
    h2.trace("second message", 0);
    QueryContext h3 = query.clone().getContext(true);
    h3.trace("third message", 0);
    h.trace("fourth message", 0);
    h2.trace("fifth message", 0);
    Writer w = new StringWriter();
    Writer w2 = new StringWriter();
    h2.render(w2);
    String finishedBelow = w2.toString();
    h.render(w);
    String toplevel = w.toString();
    // check no matter which QueryContext ends up in the final Result,
    // all context info is rendered
    assertEquals(toplevel, finishedBelow);
    // basic sanity test
    assertEquals("trace: [ [ " + "first message second message third message " + "fourth message fifth message ] ]", h.toString());
    Iterator<String> i = h.getTrace().traceNode().root().descendants(String.class).iterator();
    assertEquals("first message", i.next());
    assertEquals("second message", i.next());
    assertEquals("third message", i.next());
    assertEquals("fourth message", i.next());
    assertEquals("fifth message", i.next());
}
Also used : Query(com.yahoo.search.Query) StringWriter(java.io.StringWriter) QueryContext(com.yahoo.search.query.context.QueryContext) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

QueryContext (com.yahoo.search.query.context.QueryContext)7 Query (com.yahoo.search.Query)6 StringWriter (java.io.StringWriter)3 Writer (java.io.Writer)3 Execution (com.yahoo.processing.execution.Execution)1 Result (com.yahoo.search.Result)1 VisitorStatistics (com.yahoo.vdslib.VisitorStatistics)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1