Search in sources :

Example 11 with Event

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

the class JdbcEventRepository method getFeatureUsageHistory.

/**
 * {@inheritDoc}
 */
@Override
public TimeSeriesChart getFeatureUsageHistory(EventQueryDefinition query, TimeUnit units) {
    // Create the interval depending on units
    TimeSeriesChart tsc = new TimeSeriesChart(query.getFrom(), query.getTo(), units);
    // Search All events
    Iterator<Event> iterEvent = searchFeatureUsageEvents(query).iterator();
    // Dispatch events into time slots
    while (iterEvent.hasNext()) {
        tsc.addEvent(iterEvent.next());
    }
    return tsc;
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) Event(org.ff4j.audit.Event)

Example 12 with Event

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

the class JdbcEventMapper method mapEvent.

/**
 * Unmarshall a resultset to Event.
 *
 * @param rs
 *      current line
 * @return
 *      bean populated
 * @throws SQLException
 *      cannot read SQL result
 */
public Event mapEvent(ResultSet rs) throws SQLException {
    // Feature
    Event evt = new Event();
    evt.setUuid(rs.getString(COL_EVENT_UUID));
    evt.setTimestamp(rs.getTimestamp(COL_EVENT_TIME).getTime());
    evt.setType(rs.getString(COL_EVENT_TYPE));
    evt.setName(rs.getString(COL_EVENT_NAME));
    evt.setAction(rs.getString(COL_EVENT_ACTION));
    evt.setHostName(rs.getString(COL_EVENT_HOSTNAME));
    evt.setSource(rs.getString(COL_EVENT_SOURCE));
    evt.setDuration(rs.getLong(COL_EVENT_DURATION));
    evt.setUser(rs.getString(COL_EVENT_USER));
    evt.setValue(rs.getString(COL_EVENT_VALUE));
    evt.setCustomKeys(MappingUtil.toMap(rs.getString(COL_EVENT_KEYS)));
    return evt;
}
Also used : Event(org.ff4j.audit.Event)

Example 13 with Event

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

the class FF4jTest method monitoringAudit.

@Test
public void monitoringAudit() {
    // Given
    FF4j ff4j = new FF4j();
    ff4j.setEventPublisher(new EventPublisher());
    ff4j.setEventRepository(new InMemoryEventRepository());
    ff4j.removeCurrentContext();
    ff4j.getCurrentContext();
    // When
    ff4j.stop();
    // When
    ff4j.setEventPublisher(null);
    ff4j.getEventPublisher();
    ff4j.stop();
    // When
    Event evt = new Event("f1", EventConstants.TARGET_FEATURE, "f2", EventConstants.ACTION_CHECK_OK);
    Assert.assertNotNull(evt.toJson());
    Assert.assertNotNull(evt.toString());
    // When
    EventPublisher ep = new EventPublisher();
    new EventPublisher(ep.getRepository(), null);
    ep.setRepository(new InMemoryEventRepository());
    // Then
    Assert.assertNotNull(ep.getRepository());
}
Also used : EventPublisher(org.ff4j.audit.EventPublisher) FF4j(org.ff4j.FF4j) InMemoryEventRepository(org.ff4j.audit.repository.InMemoryEventRepository) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 14 with Event

use of org.ff4j.audit.Event 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)

Example 15 with Event

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

the class AbstractEventRepositoryTest method testFeatureUsageBarCharts.

@Test
public void testFeatureUsageBarCharts() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Create Event
    repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", EventConstants.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));
    }
    // Assert bar chart (2 bars with 8 and 8)
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 10, System.currentTimeMillis() + 10);
    BarChart bChart = repo.getFeatureUsageBarChart(testQuery);
    Assert.assertEquals(2, bChart.getChartBars().size());
    Assert.assertEquals(new Integer(8), bChart.getChartBars().get(0).getValue());
    Assert.assertEquals(new Integer(8), bChart.getChartBars().get(1).getValue());
    Assert.assertNotNull(bChart.getChartBars().get(0).getColor());
    Assert.assertNotNull(bChart.getChartBars().get(1).getColor());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) BarChart(org.ff4j.audit.chart.BarChart) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Aggregations

Event (org.ff4j.audit.Event)56 Test (org.junit.Test)32 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)22 MutableHitCount (org.ff4j.audit.MutableHitCount)15 EventSeries (org.ff4j.audit.EventSeries)8 TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)8 JestResult (io.searchbox.client.JestResult)6 HashMap (java.util.HashMap)5 EventRepository (org.ff4j.audit.repository.EventRepository)4 InMemoryEventRepository (org.ff4j.audit.repository.InMemoryEventRepository)4 Date (java.util.Date)2 TreeMap (java.util.TreeMap)2 EventPublisher (org.ff4j.audit.EventPublisher)2 EventWorker (org.ff4j.audit.EventWorker)2 BarChart (org.ff4j.audit.chart.BarChart)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 FF4j (org.ff4j.FF4j)1 Serie (org.ff4j.audit.chart.Serie)1 MongoEventMapper (org.ff4j.mongo.mapper.MongoEventMapper)1