use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class DefaultMessageDistributorTest method testExpiredProfilesShouldBeRemoved.
/**
* An expired profile is only kept around for a fixed period of time. It should be removed, if it
* has been on the expired cache for too long.
*/
@Test
public void testExpiredProfilesShouldBeRemoved() throws Exception {
// the ticker drives time to allow us to test cache expiration
FixedTicker ticker = new FixedTicker();
// setup
ProfileConfig definition = createDefinition(profileOne);
String entity = (String) messageOne.get("ip_src_addr");
MessageRoute route = new MessageRoute(definition, entity);
distributor = new DefaultMessageDistributor(periodDurationMillis, profileTimeToLiveMillis, maxNumberOfRoutes, ticker);
// distribute one message
distributor.distribute(messageOne, 1000000, route, context);
// advance time a couple of hours
ticker.advanceTime(2, HOURS);
// the profile should have been expired
assertEquals(0, distributor.flush().size());
// advance time a couple of hours
ticker.advanceTime(2, HOURS);
// the profile should have been removed from the expired cache
assertEquals(0, distributor.flushExpired().size());
}
use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class ProfileBuilderBolt method handleMessage.
/**
* Handles the processing of a single tuple.
*
* @param input The tuple containing a telemetry message.
*/
private void handleMessage(Tuple input) {
// crack open the tuple
JSONObject message = getField(MESSAGE_TUPLE_FIELD, input, JSONObject.class);
ProfileConfig definition = getField(PROFILE_TUPLE_FIELD, input, ProfileConfig.class);
String entity = getField(ENTITY_TUPLE_FIELD, input, String.class);
Long timestamp = getField(TIMESTAMP_TUPLE_FIELD, input, Long.class);
// keep track of time
flushSignal.update(timestamp);
// distribute the message
MessageRoute route = new MessageRoute(definition, entity);
messageDistributor.distribute(message, timestamp, route, getStellarContext());
LOG.debug("Message distributed: profile={}, entity={}, timestamp={}", definition.getProfile(), entity, timestamp);
}
use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class ProfileHBaseMapper method getTTL.
/**
* Defines the TTL (time-to-live) that will be used when writing the data
* from a tuple to HBase. After the TTL, the data will expire and will be
* purged.
*
* @param tuple The tuple to map to HBase.
* @return The TTL in milliseconds.
*/
@Override
public Optional<Long> getTTL(Tuple tuple) {
Optional<Long> expiresMillis = Optional.empty();
ProfileMeasurement measurement = (ProfileMeasurement) tuple.getValueByField("measurement");
ProfileConfig profileConfig = measurement.getDefinition();
if (profileConfig.getExpires() != null) {
// a profile's `expires` field is in days, but hbase expects milliseconds
long expiresDays = profileConfig.getExpires();
expiresMillis = Optional.of(TimeUnit.DAYS.toMillis(expiresDays));
}
return expiresMillis;
}
use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class ProfileHBaseMapperTest method setup.
@Before
public void setup() {
rowKeyBuilder = mock(RowKeyBuilder.class);
mapper = new ProfileHBaseMapper();
mapper.setRowKeyBuilder(rowKeyBuilder);
profile = new ProfileConfig("profile", "ip_src_addr", new ProfileResult("2 + 2"));
measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withProfileValue(22).withDefinition(profile);
// the tuple will contain the original message
tuple = mock(Tuple.class);
when(tuple.getValueByField(eq("measurement"))).thenReturn(measurement);
}
use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class ProfileSplitterBoltTest method testResolveEntityName.
/**
* The entity associated with a profile is defined with a Stellar expression. That expression
* can refer to any field within the message.
*
* In this case the entity is defined as 'ip_src_addr' which is resolved to '10.0.0.1' based on
* the data contained within the message.
*/
@Test
public void testResolveEntityName() throws Exception {
ProfilerConfig config = toProfilerConfig(profileWithOnlyIfTrue);
ProfileSplitterBolt bolt = createBolt(config);
bolt.execute(tuple);
// expected values
String expectedEntity = "10.0.0.1";
ProfileConfig expectedConfig = config.getProfiles().get(0);
Values expected = new Values(message, timestamp, expectedEntity, expectedConfig);
// a tuple should be emitted for the downstream profile builder
verify(outputCollector, times(1)).emit(eq(tuple), eq(expected));
// the original tuple should be ack'd
verify(outputCollector, times(1)).ack(eq(tuple));
}
Aggregations