Search in sources :

Example 6 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class HBaseProfilerClientTest method testFetchWithStartEndAndNoGroup.

/**
 * Attempt to fetch a group that does not exist.
 */
@Test
public void testFetchWithStartEndAndNoGroup() {
    // setup
    final int periodsPerHour = 4;
    final int expectedValue = 2302;
    final int hours = 2;
    final int count = hours * periodsPerHour;
    final long endTime = System.currentTimeMillis();
    final long startTime = endTime - TimeUnit.HOURS.toMillis(hours);
    // create two groups of measurements - one on weekdays and one on weekends
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile1").withEntity("entity1").withPeriod(startTime, periodDuration, periodUnits);
    profileWriter.write(m, count, Arrays.asList("weekdays"), val -> expectedValue);
    profileWriter.write(m, count, Arrays.asList("weekends"), val -> 0);
    // execute
    List<Object> doesNotExist = Arrays.asList("does-not-exist");
    List<Integer> results = client.fetch(Integer.class, "profile1", "entity1", doesNotExist, startTime, endTime, Optional.empty());
    // validate
    assertEquals(0, results.size());
}
Also used : ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Example 7 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class HBaseProfilerClientTest method testFetchWithStartEndAndOutsideTimeWindow.

/**
 * Profile data only within 'milliseconds ago' should be fetched.  Data outside of that time horizon should
 * not be fetched.
 */
@Test
public void testFetchWithStartEndAndOutsideTimeWindow() throws Exception {
    final int hours = 2;
    int numberToWrite = hours * periodsPerHour;
    final List<Object> group = Arrays.asList("weekends");
    final long measurementTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1);
    // setup - write some values to read later
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile1").withEntity("entity1").withPeriod(measurementTime, periodDuration, periodUnits);
    profileWriter.write(m, numberToWrite, group, val -> 1000);
    // execute
    final long endFetchAt = System.currentTimeMillis();
    final long startFetchAt = endFetchAt - TimeUnit.MILLISECONDS.toMillis(30);
    List<Integer> results = client.fetch(Integer.class, "profile1", "entity1", group, startFetchAt, endFetchAt, Optional.empty());
    // validate - there should NOT be any results from just 2 milliseconds ago
    assertEquals(0, results.size());
}
Also used : ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Example 8 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class GetProfileTest method testWithConfigAndOneGroup.

/**
 * Values should be retrievable that have been stored within a 'group', with
 * configuration different than current global config.
 * This time put the config_override case before the non-override case.
 */
@Test
public void testWithConfigAndOneGroup() {
    final int periodsPerHour = 4;
    final int expectedValue = 2302;
    final int hours = 2;
    final long startTime = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(hours);
    final List<Object> group = Arrays.asList("weekends");
    // setup - write some measurements to be read later
    final int count = hours * periodsPerHour;
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile1").withEntity("entity1").withPeriod(startTime, periodDuration, periodUnits);
    profileWriter.write(m, count, group, val -> expectedValue);
    // create a variable that contains the groups to use
    state.put("groups", group);
    // now change the executor configuration
    Context context2 = setup2();
    // validate it is changed in significant way
    @SuppressWarnings("unchecked") Map<String, Object> global = (Map<String, Object>) context2.getCapability(Context.Capabilities.GLOBAL_CONFIG).get();
    Assert.assertEquals(global.get(PROFILER_PERIOD.getKey()), Long.toString(periodDuration2));
    Assert.assertNotEquals(periodDuration, periodDuration2);
    // execute - read the profile values - with config_override.
    // first two override values are strings, third is deliberately a number.
    String overrides = "{'profiler.client.period.duration' : '" + periodDuration + "', " + "'profiler.client.period.duration.units' : '" + periodUnits.toString() + "', " + "'profiler.client.salt.divisor' : " + saltDivisor + " }";
    String expr = "PROFILE_GET('profile1', 'entity1'" + ", PROFILE_FIXED(4, 'HOURS', " + overrides + "), ['weekends'], " + overrides + ")";
    @SuppressWarnings("unchecked") List<Integer> result = run(expr, List.class);
    // validate - expect to read all values from the past 4 hours
    Assert.assertEquals(count, result.size());
    // execute - read the profile values - with (wrong) default global config values.
    // No error message at this time, but returns empty results list, because
    // row keys are not correctly calculated.
    expr = "PROFILE_GET('profile1', 'entity1', PROFILE_FIXED(4, 'HOURS'), ['weekends'])";
    result = run(expr, List.class);
    // validate - expect to fail to read any values
    Assert.assertEquals(0, result.size());
}
Also used : Context(org.apache.metron.stellar.dsl.Context) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class SaltyRowKeyBuilderTest method setup.

@Before
public void setup() throws Exception {
    // a profile measurement
    measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(AUG2016, periodDuration, periodUnits);
    // the tuple will contain the original message
    tuple = mock(Tuple.class);
    when(tuple.getValueByField(eq("measurement"))).thenReturn(measurement);
    rowKeyBuilder = new SaltyRowKeyBuilder(saltDivisor, periodDuration, periodUnits);
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Tuple(org.apache.storm.tuple.Tuple) Before(org.junit.Before)

Example 10 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement 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)

Aggregations

ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)27 Test (org.junit.Test)19 List (java.util.List)6 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)6 ArrayList (java.util.ArrayList)5 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)5 Tuple (org.apache.storm.tuple.Tuple)5 Values (org.apache.storm.tuple.Values)4 JSONObject (org.json.simple.JSONObject)4 Before (org.junit.Before)4 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)3 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)3 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 TimeUnit (java.util.concurrent.TimeUnit)2 ProfileConfig (org.apache.metron.common.configuration.profiler.ProfileConfig)2 MockHTable (org.apache.metron.hbase.mock.MockHTable)2 MessageDistributor (org.apache.metron.profiler.MessageDistributor)2