use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class ProfileSplitterBoltTest method testEmitTupleWithTwoProfiles.
/**
* If there are two profiles that need the same message, then two tuples should
* be emitted. One tuple for each profile.
*/
@Test
public void testEmitTupleWithTwoProfiles() throws Exception {
// setup the bolt and execute a tuple
ProfilerConfig config = toProfilerConfig(twoProfilesDefined);
ProfileSplitterBolt bolt = createBolt(config);
bolt.execute(tuple);
// the expected tuple fields
final String expectedEntity = "global";
{
// a tuple should be emitted for the first profile
ProfileConfig profile1 = config.getProfiles().get(0);
Values expected = new Values(message, timestamp, expectedEntity, profile1);
verify(outputCollector, times(1)).emit(eq(tuple), eq(expected));
}
{
// a tuple should be emitted for the second profile
ProfileConfig profile2 = config.getProfiles().get(1);
Values expected = new Values(message, timestamp, expectedEntity, profile2);
verify(outputCollector, times(1)).emit(eq(tuple), eq(expected));
}
// the original tuple should be ack'd
verify(outputCollector, times(1)).ack(eq(tuple));
}
use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class ProfileSplitterBoltTest method testEmitTupleWithOneProfile.
/**
* Ensure that a tuple with the correct fields is emitted to downstream bolts
* when a profile is defined.
*/
@Test
public void testEmitTupleWithOneProfile() throws Exception {
// setup the bolt and execute a tuple
ProfilerConfig config = toProfilerConfig(profileWithOnlyIfTrue);
ProfileSplitterBolt bolt = createBolt(config);
bolt.execute(tuple);
// the expected tuple fields
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));
}
use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class DefaultMessageDistributor method getBuilder.
/**
* Retrieves the cached ProfileBuilder that is used to build and maintain the Profile. If none exists,
* one will be created and returned.
*
* @param route The message route.
* @param context The Stellar execution context.
*/
public ProfileBuilder getBuilder(MessageRoute route, Context context) throws ExecutionException {
ProfileConfig profile = route.getProfileDefinition();
String entity = route.getEntity();
return activeCache.get(cacheKey(profile, entity), () -> new DefaultProfileBuilder.Builder().withDefinition(profile).withEntity(entity).withPeriodDurationMillis(periodDurationMillis).withContext(context).build());
}
use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class DefaultMessageRouter method route.
/**
* Route a telemetry message. Finds all routes for a given telemetry message.
*
* @param message The telemetry message that needs routed.
* @param config The configuration for the Profiler.
* @param context The Stellar execution context.
* @return A list of all the routes for the message.
*/
@Override
public List<MessageRoute> route(JSONObject message, ProfilerConfig config, Context context) {
List<MessageRoute> routes = new ArrayList<>();
// attempt to route the message to each of the profiles
for (ProfileConfig profile : config.getProfiles()) {
Optional<MessageRoute> route = routeToProfile(message, profile);
route.ifPresent(routes::add);
}
return routes;
}
use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.
the class DefaultMessageDistributorTest method testNotYetTimeToExpireProfiles.
/**
* A profile should expire after a fixed period of time. This test ensures that
* profiles are not expired before they are supposed to be.
*/
@Test
public void testNotYetTimeToExpireProfiles() 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 to just shy of the profile TTL
ticker.advanceTime(profileTimeToLiveMillis - 1000, MILLISECONDS);
// the profile should NOT have expired yet
assertEquals(0, distributor.flushExpired().size());
assertEquals(1, distributor.flush().size());
}
Aggregations