Search in sources :

Example 6 with ProfileConfig

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

Example 7 with ProfileConfig

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);
}
Also used : JSONObject(org.json.simple.JSONObject) MessageRoute(org.apache.metron.profiler.MessageRoute) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig)

Example 8 with ProfileConfig

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

Example 9 with ProfileConfig

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);
}
Also used : ProfileResult(org.apache.metron.common.configuration.profiler.ProfileResult) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Tuple(org.apache.storm.tuple.Tuple) ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) Before(org.junit.Before)

Example 10 with ProfileConfig

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

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