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());
}
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);
}
}
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));
}
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);
}
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());
}
Aggregations