Search in sources :

Example 1 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class ProfileBuilderBolt method emitMeasurements.

/**
 * Handles the {@code ProfileMeasurement}s that are created when a profile is flushed.
 *
 * @param measurements The measurements to handle.
 */
private void emitMeasurements(List<ProfileMeasurement> measurements) {
    // flush each profile
    for (ProfileMeasurement measurement : measurements) {
        // allow each 'emitter' to emit the measurement
        for (ProfileMeasurementEmitter emitter : emitters) {
            emitter.emit(measurement, collector);
            LOG.debug("Measurement emitted; stream={}, profile={}, entity={}, value={}, start={}, end={}, duration={}, period={}", emitter.getStreamId(), measurement.getProfileName(), measurement.getEntity(), measurement.getProfileValue(), measurement.getPeriod().getStartTimeMillis(), measurement.getPeriod().getEndTimeMillis(), measurement.getPeriod().getDurationMillis(), measurement.getPeriod().getPeriod());
        }
    }
    LOG.debug("Emitted {} measurement(s).", measurements.size());
}
Also used : ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement)

Example 2 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class ProfileBuilderBolt method execute.

@Override
public void execute(TupleWindow window) {
    LOG.debug("Tuple window contains {} tuple(s), {} expired, {} new", CollectionUtils.size(window.get()), CollectionUtils.size(window.getExpired()), CollectionUtils.size(window.getNew()));
    try {
        // handle each tuple in the window
        for (Tuple tuple : window.get()) {
            if (TupleUtils.isTick(tuple)) {
                handleTick();
            } else {
                handleMessage(tuple);
            }
        }
        // time to flush?
        if (flushSignal.isTimeToFlush()) {
            flushSignal.reset();
            // flush the active profiles
            List<ProfileMeasurement> measurements = messageDistributor.flush();
            emitMeasurements(measurements);
            LOG.debug("Flushed active profiles and found {} measurement(s).", measurements.size());
        }
    } catch (Throwable e) {
        LOG.error("Unexpected error", e);
        collector.reportError(e);
    }
}
Also used : ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Tuple(org.apache.storm.tuple.Tuple)

Example 3 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class ProfileBuilderBoltTest method testEmitWhenFlush.

/**
 * If the {@code FlushSignal} tells the bolt to flush, it should flush the {@code MessageDistributor}
 * and emit the {@code ProfileMeasurement} values.
 */
@Test
public void testEmitWhenFlush() throws Exception {
    ProfileBuilderBolt bolt = createBolt();
    // create a profile measurement
    ProfileMeasurement m = new ProfileMeasurement().withEntity("entity1").withProfileName("profile1").withPeriod(1000, 500, TimeUnit.MILLISECONDS).withProfileValue(22);
    // create a mock that returns the profile measurement above
    MessageDistributor distributor = mock(MessageDistributor.class);
    when(distributor.flush()).thenReturn(Collections.singletonList(m));
    bolt.withMessageDistributor(distributor);
    // signal the bolt to flush
    flushSignal.setFlushNow(true);
    // execute the bolt
    Tuple tuple1 = createTuple("entity1", message1, profile1, 1000L);
    TupleWindow tupleWindow = createWindow(tuple1);
    bolt.execute(tupleWindow);
    // a profile measurement should be emitted by the bolt
    List<ProfileMeasurement> measurements = getProfileMeasurements(outputCollector, 1);
    assertEquals(1, measurements.size());
    assertEquals(m, measurements.get(0));
}
Also used : MessageDistributor(org.apache.metron.profiler.MessageDistributor) TupleWindow(org.apache.storm.windowing.TupleWindow) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Tuple(org.apache.storm.tuple.Tuple) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest) Test(org.junit.Test)

Example 4 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class ProfilerIntegrationTest method generateExpectedRowKey.

/**
 * Generates the expected row key.
 *
 * @param profileName The name of the profile.
 * @param entity The entity.
 * @param whenMillis A timestamp in epoch milliseconds.
 * @return A row key.
 */
private byte[] generateExpectedRowKey(String profileName, String entity, long whenMillis) {
    // only the profile name, entity, and period are used to generate the row key
    ProfileMeasurement measurement = new ProfileMeasurement().withProfileName(profileName).withEntity(entity).withPeriod(whenMillis, periodDurationMillis, TimeUnit.MILLISECONDS);
    // build the row key
    RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder(saltDivisor, periodDurationMillis, TimeUnit.MILLISECONDS);
    return rowKeyBuilder.rowKey(measurement);
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement)

Example 5 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class HBaseProfilerClientTest method testFetchWithDurationAgoAndOutsideTimeWindow.

/**
 * Profile data only within 'milliseconds ago' should be fetched.  Data outside of that time horizon should
 * not be fetched.
 */
@Test
public void testFetchWithDurationAgoAndOutsideTimeWindow() throws Exception {
    final int hours = 2;
    final List<Object> group = Arrays.asList("weekends");
    final long startTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1);
    // setup - write some values to read later
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile1").withEntity("entity1").withPeriod(startTime, periodDuration, periodUnits);
    profileWriter.write(m, hours * periodsPerHour, group, val -> 1000);
    // execute
    List<Integer> results = client.fetch(Integer.class, "profile1", "entity1", group, 2, TimeUnit.MILLISECONDS, Optional.empty());
    // validate - there should NOT be any results from just 2 milliseconds ago
    assertEquals(0, results.size());
}
Also used : ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Aggregations

ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)27 Test (org.junit.Test)19 List (java.util.List)6 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)6 ArrayList (java.util.ArrayList)5 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)5 Tuple (org.apache.storm.tuple.Tuple)5 Values (org.apache.storm.tuple.Values)4 JSONObject (org.json.simple.JSONObject)4 Before (org.junit.Before)4 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)3 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)3 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 TimeUnit (java.util.concurrent.TimeUnit)2 ProfileConfig (org.apache.metron.common.configuration.profiler.ProfileConfig)2 MockHTable (org.apache.metron.hbase.mock.MockHTable)2 MessageDistributor (org.apache.metron.profiler.MessageDistributor)2