Search in sources :

Example 1 with PageMetric

use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave by NationalSecurityAgency.

the class HudBean method getRunningQueries.

/**
 * Return true if there is at least one log in the last 60 minutes.
 *
 * @return
 * @throws org.apache.accumulo.core.client.TableNotFoundException
 */
@Path("/runningqueries/{userid}")
@GET
public String getRunningQueries(@PathParam("userid") String userId) throws Exception {
    DatawavePrincipal principal = getPrincipal();
    boolean isAnAdmin = isAnAdmin(principal);
    QueryImplListResponse runningQueries = null;
    if (isAnAdmin) {
        runningQueries = queryExecutor.listQueriesForUser(userId);
    } else {
        runningQueries = queryExecutor.listUserQueries();
    }
    List<Query> queryList = runningQueries.getQuery();
    List<HudQuerySummary> querySummaryList = new ArrayList<>();
    for (Query query : queryList) {
        HudQuerySummary summary = summaryBuilder.build(query);
        String queryId = query.getId().toString();
        List<? extends BaseQueryMetric> queryMetricsList;
        queryMetricsList = queryMetrics.query(queryId).getResult();
        if (queryMetricsList != null && !queryMetricsList.isEmpty()) {
            BaseQueryMetric qm = queryMetricsList.get(0);
            List<PageMetric> pageMetrics = qm.getPageTimes();
            summary.setPageMetrics(pageMetrics);
            summary.setCreateDate(qm.getCreateDate().getTime());
            summary.setNumPages(qm.getNumPages());
            summary.setNumResults(qm.getNumResults());
            summary.setLastUpdated(qm.getLastUpdated().getTime());
            summary.setLifeCycle(qm.getLifecycle().toString());
        }
        querySummaryList.add(summary);
    }
    return gson.toJson(querySummaryList);
}
Also used : QueryImplListResponse(datawave.webservice.result.QueryImplListResponse) Query(datawave.webservice.query.Query) PageMetric(datawave.microservice.querymetric.BaseQueryMetric.PageMetric) ArrayList(java.util.ArrayList) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) BaseQueryMetric(datawave.microservice.querymetric.BaseQueryMetric) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with PageMetric

use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave by NationalSecurityAgency.

the class QueryMetricsBean method updateMetric.

/*
     * @PermitAll is necessary because this method is called indirectly from the @PreDestroy method of the QueryExpirationBean and the QueryExpirationBean's
     * 
     * @RunAs annotation is not being honored in the @PreDestroy hook
     */
@PermitAll
public void updateMetric(BaseQueryMetric metric) throws Exception {
    DatawavePrincipal dp = getPrincipal();
    if (metric.getLastWrittenHash() != metric.hashCode()) {
        metric.setLastWrittenHash(metric.hashCode());
        try {
            metric.setLastUpdated(new Date());
            sendQueryMetric(dp, metric);
            // PageMetrics now know their own page numbers
            // this should keep large queries from blowing up the queue
            // Leave the last page on the list so that interceptors can update it.
            Iterator<PageMetric> itr = metric.getPageTimes().iterator();
            while (metric.getPageTimes().size() > 1) {
                itr.next();
                itr.remove();
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : PageMetric(datawave.microservice.querymetric.BaseQueryMetric.PageMetric) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) Date(java.util.Date) PermitAll(javax.annotation.security.PermitAll)

Example 3 with PageMetric

use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave-query-metric-service by NationalSecurityAgency.

the class QueryMetricTest method testPageMetricParsingLegacy1.

@Test
public void testPageMetricParsingLegacy1() {
    PageMetric pmRef1 = new PageMetric(null, null, 2500, 2000, 3500, 3600, -1, 2200, 3000, 10000);
    // pageSize/returnTime/callTime/serializationTime/bytesWritten/pageRequested/pageReturned
    String pmText1 = "2500/2000/2200/3000/10000/3500/3600";
    PageMetric pm1 = PageMetric.parse(pmText1);
    assertEquals("page metrics not equal", pmRef1, pm1);
}
Also used : PageMetric(datawave.microservice.querymetric.BaseQueryMetric.PageMetric) Test(org.junit.Test)

Example 4 with PageMetric

use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave-query-metric-service by NationalSecurityAgency.

the class QueryMetricTest method testPageMetricParsingLegacy3.

@Test
public void testPageMetricParsingLegacy3() {
    PageMetric pmRef1 = new PageMetric(null, null, 2500, 2000, 0, 0, -1, 0, 0, -1);
    // pageSize/returnTime
    String pmText1 = "2500/2000";
    PageMetric pm1 = PageMetric.parse(pmText1);
    assertEquals("page metrics not equal", pmRef1, pm1);
}
Also used : PageMetric(datawave.microservice.querymetric.BaseQueryMetric.PageMetric) Test(org.junit.Test)

Example 5 with PageMetric

use of datawave.microservice.querymetric.BaseQueryMetric.PageMetric in project datawave-query-metric-service by NationalSecurityAgency.

the class QueryMetricTest method testPageMetricParsingLegacy2.

@Test
public void testPageMetricParsingLegacy2() {
    PageMetric pmRef1 = new PageMetric(null, null, 2500, 2000, 0, 0, -1, 2200, 3000, 10000);
    // pageSize/returnTime/callTime/serializationTime/bytesWritten
    String pmText1 = "2500/2000/2200/3000/10000";
    PageMetric pm1 = PageMetric.parse(pmText1);
    assertEquals("page metrics not equal", pmRef1, pm1);
}
Also used : PageMetric(datawave.microservice.querymetric.BaseQueryMetric.PageMetric) Test(org.junit.Test)

Aggregations

PageMetric (datawave.microservice.querymetric.BaseQueryMetric.PageMetric)16 Date (java.util.Date)4 Test (org.junit.Test)4 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)3 IOException (java.io.IOException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 BaseQueryMetric (datawave.microservice.querymetric.BaseQueryMetric)2 Prediction (datawave.microservice.querymetric.BaseQueryMetric.Prediction)2 QueryException (datawave.webservice.query.exception.QueryException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 BadRequestException (datawave.webservice.common.exception.BadRequestException)1 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)1 NoResultsException (datawave.webservice.common.exception.NoResultsException)1 UnauthorizedException (datawave.webservice.common.exception.UnauthorizedException)1 Query (datawave.webservice.query.Query)1 Parameter (datawave.webservice.query.QueryImpl.Parameter)1 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)1 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)1