use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave by NationalSecurityAgency.
the class QueryMetricsReporter method getQueryTime.
private long getQueryTime(BaseQueryMetric metric) {
long time = metric.getSetupTime();
List<PageMetric> pageTimes = metric.getPageTimes();
if (useAllQueryPages) {
for (PageMetric pageTime : pageTimes) {
time += pageTime.getReturnTime();
}
} else {
if (pageTimes.size() >= 1) {
time += pageTimes.get(0).getReturnTime();
}
}
return time;
}
use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave by NationalSecurityAgency.
the class QueryExecutorBean method executeAsync.
@Asynchronous
public Future<?> executeAsync(String logicName, MultivaluedMap<String, String> queryParameters, Long startTime, Long loginTime, AsyncQueryStatusObserver observer) {
Collection<String> proxyServers = null;
Principal p = ctx.getCallerPrincipal();
DatawavePrincipal dp;
if (p instanceof DatawavePrincipal) {
dp = (DatawavePrincipal) p;
proxyServers = dp.getProxyServers();
}
long start = (startTime != null) ? startTime : System.nanoTime();
GenericResponse<String> createResponse;
try {
createResponse = createQuery(logicName, queryParameters);
observer.queryCreated(createResponse);
} catch (DatawaveWebApplicationException e) {
observer.queryCreateException(new QueryException(e));
return new AsyncResult<>(e);
}
if (sessionContext.wasCancelCalled())
return new AsyncResult<>("cancelled");
long createCallTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
final String queryId = createResponse.getResult();
// We created the query and put into cache, get the RunningQuery object
// and update the query metric for call time.
final RunningQuery rq = queryCache.get(queryId);
try {
rq.getMetric().setCreateCallTime(createCallTime);
if (loginTime != null) {
rq.getMetric().setLoginTime(loginTime);
}
try {
metrics.updateMetric(rq.getMetric());
} catch (Exception e) {
log.error("Error updating query metric", e);
}
boolean done = false;
Span span = null;
List<PageMetric> pageMetrics = rq.getMetric().getPageTimes();
// If we get any exception, then break out of the loop and notify the observer about the problem.
do {
long callStart = System.nanoTime();
rq.setActiveCall(true);
try {
BaseQueryResponse page = _next(rq, queryId, proxyServers, span);
long serializationStart = System.nanoTime();
observer.queryResultsAvailable(page);
long serializationTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - serializationStart);
if (rq.getLogic().getCollectQueryMetrics()) {
PageMetric pm = pageMetrics.get(pageMetrics.size() - 1);
pm.setSerializationTime(serializationTime);
long pageCallTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - callStart);
pm.setCallTime(pageCallTime);
}
} catch (Exception e) {
if (e instanceof NoResultsException || e.getCause() instanceof NoResultsException) {
// No more results, break out of loop
done = true;
} else if (sessionContext.wasCancelCalled() && e instanceof CancellationException) {
// We were cancelled by the originating user, so just break out of the loop.
// If we were cancelled due to an admin cancel, we'll report the exception to the user.
done = true;
} else {
// We had a real problem. Update the query metric with the error and then notify the observer.
if (rq.getLogic().getCollectQueryMetrics()) {
rq.getMetric().setError(e);
}
QueryException qe = (e instanceof QueryException) ? (QueryException) e : new QueryException(e);
observer.queryException(qe);
done = true;
break;
}
} finally {
rq.setActiveCall(false);
// Update the query metrics for the completion of this page (either successfully or due to error)
if (rq.getLogic().getCollectQueryMetrics()) {
try {
metrics.updateMetric(rq.getMetric());
} catch (Exception e) {
log.error("Error updating query metric", e);
}
}
}
} while (!done && !sessionContext.wasCancelCalled());
} finally {
// Close the query now that we're done with it.
try {
close(rq);
} catch (Exception e) {
log.error("Error closing query", e);
}
}
observer.queryFinished(queryId);
return new AsyncResult<>(queryId);
}
use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave by NationalSecurityAgency.
the class QueryMetricsEnrichmentInterceptor method aroundWriteTo.
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
ResponseMethodStats stats = doWrite(context);
QueryCall queryCall = (QueryCall) context.getProperty(QueryCall.class.getName());
if (queryCall != null) {
if (queryCache != null) {
RunningQuery rq = queryCache.get(queryCall.queryID);
if (rq != null) {
BaseQueryLogic<?> baseLogic = null;
QueryLogic<?> logic = rq.getLogic();
if (logic != null && logic instanceof BaseQueryLogic) {
baseLogic = (BaseQueryLogic) logic;
}
if (baseLogic != null && baseLogic.getCollectQueryMetrics()) {
try {
BaseQueryMetric metric = rq.getMetric();
switch(queryCall.methodType) {
case CREATE:
metric.setCreateCallTime(stats.getCallTime());
metric.setLoginTime(stats.getLoginTime());
break;
case CREATE_AND_NEXT:
metric.setCreateCallTime(stats.getCallTime());
metric.setLoginTime(stats.getLoginTime());
List<PageMetric> pageTimes = metric.getPageTimes();
if (pageTimes != null && !pageTimes.isEmpty()) {
PageMetric pm = pageTimes.get(pageTimes.size() - 1);
pm.setCallTime(stats.getCallTime());
pm.setLoginTime(stats.getLoginTime());
pm.setSerializationTime(stats.getSerializationTime());
pm.setBytesWritten(stats.getBytesWritten());
}
break;
case NEXT:
pageTimes = metric.getPageTimes();
if (pageTimes != null && !pageTimes.isEmpty()) {
PageMetric pm = pageTimes.get(pageTimes.size() - 1);
pm.setCallTime(stats.getCallTime());
pm.setLoginTime(stats.getLoginTime());
pm.setSerializationTime(stats.getSerializationTime());
pm.setBytesWritten(stats.getBytesWritten());
}
break;
}
if (queryMetricsBean != null)
queryMetricsBean.updateMetric(metric);
else
log.error("QueryMetricsBean JNDI lookup returned null");
} catch (Exception e) {
log.error("Unable to record metrics for " + queryCall.methodType + " method: " + e.getLocalizedMessage(), e);
}
}
} else {
log.error("RunningQuery instance not in the cache!, queryId: " + queryCall.queryID);
}
} else {
log.error("Query cache not injected! No metrics will be recorded for serialization times.");
}
}
}
use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave-query-metric-service by NationalSecurityAgency.
the class QueryMetricTest method testPageMetricParsing2.
@Test
public void testPageMetricParsing2() {
PageMetric pmRef1 = new PageMetric(null, "aa-bb-cc-dd", 2500, 2000, 3500, 3600, 1000, 2200, 3000, 10000);
// /pageUuid/pageSize/returnTime/callTime/serializationTime/bytesWritten/pageRequested/pageReturned/loginTime
String pmText1 = "/aa-bb-cc-dd/2500/2000/2200/3000/10000/3500/3600/1000";
PageMetric pm1 = PageMetric.parse(pmText1);
assertEquals("page metrics not equal", pmRef1, pm1);
}
use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave-query-metric-service by NationalSecurityAgency.
the class QueryMetricTest method setup.
@BeforeClass
public static void setup() {
queryMetric = new QueryMetric();
markings = new HashMap<>();
markings.put(MarkingFunctions.Default.COLUMN_VISIBILITY, "PUBLIC");
queryMetric.setMarkings(markings);
negativeSelectors = new ArrayList<>();
negativeSelectors.add("negativeSelector1");
positiveSelectors = new ArrayList<>();
positiveSelectors.add("positiveSelector1");
pageTimes = new ArrayList<>();
PageMetric pageMetric = new PageMetric();
pageMetric.setCallTime(0);
pageTimes.add(pageMetric);
proxyServers = new ArrayList<>();
proxyServers.add("proxyServer1");
}
Aggregations