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;
}
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"));
}
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);
}
}
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());
}
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());
}
Aggregations