Search in sources :

Example 6 with Event

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

the class EventRepositoryElastic method getUserHitCount.

@Override
public Map<String, MutableHitCount> getUserHitCount(EventQueryDefinition query) {
    JestResult result = getConnection().execute(getBuilder().queryGetEventQueryDefinition(query, EventConstants.ACTION_CHECK_OK));
    List<Event> events = result.getSourceAsObjectList(Event.class);
    Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
    for (Event event : events) {
        String user = event.getUser();
        if (hitCount.containsKey(user)) {
            hitCount.get(user).inc();
        } else {
            hitCount.put(user, new MutableHitCount(1));
        }
    }
    return hitCount;
}
Also used : HashMap(java.util.HashMap) Event(org.ff4j.audit.Event) JestResult(io.searchbox.client.JestResult) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 7 with Event

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

the class MongoEventMapper method fromStore.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "unchecked" })
@Override
public Event fromStore(Document bean) {
    Event evt = new Event();
    evt.setAction(bean.getString(ATTRIBUTE_ACTION));
    evt.setDuration(bean.getInteger(ATTRIBUTE_DURATION));
    evt.setHostName(bean.getString(ATTRIBUTE_HOST));
    evt.setName(bean.getString(ATTRIBUTE_NAME));
    evt.setSource(bean.getString(ATTRIBUTE_SOURCE));
    evt.setTimestamp(bean.getLong(ATTRIBUTE_TIME));
    evt.setType(bean.getString(ATTRIBUTE_TYPE));
    evt.setUuid(bean.getString(ATTRIBUTE_ID));
    evt.setUser(bean.getString(ATTRIBUTE_USER));
    if (bean.containsKey(ATTRIBUTE_KEYS)) {
        evt.setCustomKeys((Map<String, String>) JSON.parse(bean.getString(ATTRIBUTE_KEYS)));
    }
    return evt;
}
Also used : Event(org.ff4j.audit.Event)

Example 8 with Event

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

the class DBObjectBuilderTest method testMongoEventMapper.

@Test
public void testMongoEventMapper() {
    Event evt = new Event("JAVA", EventConstants.TARGET_FEATURE, "toto", EventConstants.ACTION_CHECK_OFF);
    MongoEventMapper mem = new MongoEventMapper();
    Event evt2 = mem.fromStore(mem.toStore(evt));
    Assert.assertEquals(evt.getUuid(), evt2.getUuid());
}
Also used : MongoEventMapper(org.ff4j.mongo.mapper.MongoEventMapper) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 9 with Event

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

the class InMemoryEventRepository method getUserHitCount.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, MutableHitCount> getUserHitCount(EventQueryDefinition query) {
    Map<String, MutableHitCount> hitRatio = new TreeMap<String, MutableHitCount>();
    for (Event event : searchFeatureUsageEvents(query)) {
        String user = Util.hasLength(event.getUser()) ? event.getUser() : "anonymous";
        if (!hitRatio.containsKey(user)) {
            hitRatio.put(user, new MutableHitCount());
        }
        hitRatio.get(user).inc();
    }
    return hitRatio;
}
Also used : Event(org.ff4j.audit.Event) TreeMap(java.util.TreeMap) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 10 with Event

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

the class InMemoryEventRepository 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);
    for (String currentDay : getCandidateDays(query.getFrom(), query.getTo())) {
        // There are some event this day
        if (featureUsageEvents.containsKey(currentDay)) {
            for (Map.Entry<String, EventSeries> entry : featureUsageEvents.get(currentDay).entrySet()) {
                String currentFeatureName = entry.getKey();
                // Filter feature names if required
                Set<String> filteredFeatures = query.getNamesFilter();
                if (filteredFeatures == null || filteredFeatures.isEmpty() || filteredFeatures.contains(currentFeatureName)) {
                    // Loop over events
                    for (Event evt : entry.getValue()) {
                        // Between bounds (keydate not enough)
                        if (isEventInInterval(evt, query.getFrom(), query.getTo())) {
                            // Create new serie if new feature Name
                            if (!tsc.getSeries().containsKey((currentFeatureName))) {
                                tsc.createNewSerie(currentFeatureName);
                            }
                            // Match FeatureName
                            Serie<Map<String, MutableHitCount>> serie = tsc.getSeries().get(currentFeatureName);
                            // Match SlotName
                            String slotName = tsc.getSdf().format(new Date(evt.getTimestamp()));
                            // Should be always 'true' as the tsc.getsdf().format() will get a slotName.
                            if (serie.getValue().containsKey(slotName)) {
                                // Fast Increment
                                serie.getValue().get(slotName).inc();
                            }
                        }
                    }
                }
            }
        }
    }
    // Recolor series
    List<String> colors = Util.generateHSVGradient("ee1100", "442299", tsc.getSeries().size());
    int idxColor = 0;
    for (Map.Entry<String, Serie<Map<String, MutableHitCount>>> serie : tsc.getSeries().entrySet()) {
        serie.getValue().setColor(colors.get(idxColor));
        idxColor++;
    }
    return tsc;
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) EventSeries(org.ff4j.audit.EventSeries) Date(java.util.Date) MutableHitCount(org.ff4j.audit.MutableHitCount) Event(org.ff4j.audit.Event) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Serie(org.ff4j.audit.chart.Serie)

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