Search in sources :

Example 1 with EventQueryDefinition

use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.

the class ConsoleRenderer method renderAuditRows.

private static final String renderAuditRows(FF4j ff4j, HttpServletRequest req) {
    StringBuilder sb = new StringBuilder();
    EventRepository er = ff4j.getEventRepository();
    EventQueryDefinition query = new EventQueryDefinition();
    for (Event event : er.searchFeatureUsageEvents(query)) {
        sb.append("<tr>" + END_OF_LINE);
        sb.append("<td>" + SDF.format(new Date(event.getTimestamp())) + "</td>");
        sb.append("<td>" + event.getType() + "</td>");
        sb.append("<td>" + event.getName() + "</td>");
        sb.append("<td>" + event.getAction() + "</td>");
        sb.append("</tr>");
    }
    return sb.toString();
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) EventRepository(org.ff4j.audit.repository.EventRepository) Date(java.util.Date)

Example 2 with EventQueryDefinition

use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.

the class OperationsController method graphFeatureUsageHitCountasJson.

/**
 * Generation of JSON to render Features.
 *
 * @param req
 *      current request
 * @param res
 *      current response
 * @throws IOException
 */
private void graphFeatureUsageHitCountasJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
    res.setContentType(CONTENT_TYPE_JSON);
    String[] pathParts = req.getPathInfo().split("/");
    EventQueryDefinition query = parseQuery(req);
    if (pathParts.length > 3) {
        String graphName = pathParts[3];
        if (GRAPH_PIE_HITRATIO.equalsIgnoreCase(graphName)) {
            PieChart pc = getFf4j().getEventRepository().getFeatureUsagePieChart(query);
            res.getWriter().println(pc.toJson());
        } else if (GRAPH_BAR_HITRATIO.equalsIgnoreCase(graphName)) {
            BarChart bc = getFf4j().getEventRepository().getFeatureUsageBarChart(query);
            res.getWriter().println(bc.toJson());
        } else if (GRAPH_PIE_HOST.equalsIgnoreCase(graphName)) {
            PieChart pc = getFf4j().getEventRepository().getHostPieChart(query);
            res.getWriter().println(pc.toJson());
        } else if (GRAPH_PIE_SOURCE.equalsIgnoreCase(graphName)) {
            PieChart pc = getFf4j().getEventRepository().getSourcePieChart(query);
            res.getWriter().println(pc.toJson());
        } else if (GRAPH_PIE_USER.equalsIgnoreCase(graphName)) {
            PieChart pc = getFf4j().getEventRepository().getUserPieChart(query);
            res.getWriter().println(pc.toJson());
        }
    }
}
Also used : PieChart(org.ff4j.audit.chart.PieChart) EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) BarChart(org.ff4j.audit.chart.BarChart)

Example 3 with EventQueryDefinition

use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.

the class OperationsController method graphTimeSeriesasJson.

/**
 * Generation of JSON to render Features.
 *
 * @param req
 *      current request
 * @param res
 *      current response
 * @throws IOException
 */
private void graphTimeSeriesasJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
    res.setContentType(CONTENT_TYPE_JSON);
    EventQueryDefinition query = parseQuery(req);
    TimeSeriesChart tsc = getFf4j().getEventRepository().getFeatureUsageHistory(query, TimeUnit.HOURS);
    res.getWriter().println(tsc.toString());
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) EventQueryDefinition(org.ff4j.audit.EventQueryDefinition)

Example 4 with EventQueryDefinition

use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.

the class AbstractEventRepository method toString.

/**
 * {@inheritDoc}
 */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder("{");
    sb.append("\"type\":\"" + this.getClass().getName() + "\"");
    EventQueryDefinition q = new EventQueryDefinition();
    sb.append(",\"todayHitsPieChart\": " + getFeatureUsagePieChart(q).toJson());
    sb.append(",\"todayHitsBarChart\": " + getFeatureUsageBarChart(q).toJson());
    getFeatureUsageHistory(q, TimeUnit.HOURS);
    sb.append(",\"todayTotalHitCount\":" + getFeatureUsageTotalHitCount(q));
    sb.append("}");
    return sb.toString();
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition)

Example 5 with EventQueryDefinition

use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.

the class AbstractEventRepositoryTest method testSearchFeatureUsageEvents.

@Test
public void testSearchFeatureUsageEvents() throws InterruptedException {
    long start = System.currentTimeMillis();
    repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE));
    for (int i = 0; i < 8; i++) {
        Thread.sleep(100);
        repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
        repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
    }
    Thread.sleep(100);
    // Then
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
    EventSeries es = repo.searchFeatureUsageEvents(testQuery);
    Assert.assertEquals(16, es.size());
// Then
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) EventSeries(org.ff4j.audit.EventSeries) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Aggregations

EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)31 Test (org.junit.Test)25 Event (org.ff4j.audit.Event)22 MutableHitCount (org.ff4j.audit.MutableHitCount)8 BarChart (org.ff4j.audit.chart.BarChart)3 TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)3 Date (java.util.Date)2 EventSeries (org.ff4j.audit.EventSeries)2 ParseException (java.text.ParseException)1 PieChart (org.ff4j.audit.chart.PieChart)1 EventRepository (org.ff4j.audit.repository.EventRepository)1 JdbcQueryBuilder (org.ff4j.store.JdbcQueryBuilder)1