Search in sources :

Example 1 with ProfileConfig

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));
}
Also used : ProfilerConfig(org.apache.metron.common.configuration.profiler.ProfilerConfig) Values(org.apache.storm.tuple.Values) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) Test(org.junit.Test) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest)

Example 2 with ProfileConfig

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));
}
Also used : ProfilerConfig(org.apache.metron.common.configuration.profiler.ProfilerConfig) Values(org.apache.storm.tuple.Values) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) Test(org.junit.Test) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest)

Example 3 with ProfileConfig

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());
}
Also used : CacheBuilder(com.google.common.cache.CacheBuilder) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig)

Example 4 with ProfileConfig

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;
}
Also used : ArrayList(java.util.ArrayList) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig)

Example 5 with ProfileConfig

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());
}
Also used : ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) Test(org.junit.Test)

Aggregations

ProfileConfig (org.apache.metron.common.configuration.profiler.ProfileConfig)12 Test (org.junit.Test)7 ProfilerConfig (org.apache.metron.common.configuration.profiler.ProfilerConfig)3 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)3 Values (org.apache.storm.tuple.Values)3 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 ArrayList (java.util.ArrayList)1 ProfileResult (org.apache.metron.common.configuration.profiler.ProfileResult)1 MessageRoute (org.apache.metron.profiler.MessageRoute)1 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)1 Tuple (org.apache.storm.tuple.Tuple)1 JSONObject (org.json.simple.JSONObject)1 Before (org.junit.Before)1