Search in sources :

Example 26 with ProfileMeasurement

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

the class GetProfileTest method testWithConfigOverride.

/**
 * Values should be retrievable that were written with configuration different than current global config.
 */
@Test
public void testWithConfigOverride() {
    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 = Collections.emptyList();
    // 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);
    // 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(PROFILER_PERIOD.get(global), periodDuration2);
    Assert.assertNotEquals(periodDuration, periodDuration2);
    // 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.
    String expr = "PROFILE_GET('profile1', 'entity1', PROFILE_FIXED(4, 'HOURS'))";
    @SuppressWarnings("unchecked") List<Integer> result = run(expr, List.class);
    // validate - expect to fail to read any values
    Assert.assertEquals(0, result.size());
    // 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 + " }";
    expr = "PROFILE_GET('profile1', 'entity1', PROFILE_FIXED(4, 'HOURS', " + overrides + "), [], " + overrides + ")";
    result = run(expr, List.class);
    // validate - expect to read all values from the past 4 hours
    Assert.assertEquals(count, 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 27 with ProfileMeasurement

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

the class SaltyRowKeyBuilderTest method testRowKeys.

/**
 * `rowKeys` should return all of the row keys needed to retrieve the profile values over a given time horizon.
 */
@Test
public void testRowKeys() throws Exception {
    int hoursAgo = 1;
    // setup
    List<Object> groups = Collections.emptyList();
    rowKeyBuilder = new SaltyRowKeyBuilder(saltDivisor, periodDuration, periodUnits);
    // a dummy profile measurement
    long now = System.currentTimeMillis();
    long oldest = now - TimeUnit.HOURS.toMillis(hoursAgo);
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(oldest, periodDuration, periodUnits).withProfileValue(22);
    // generate a list of expected keys
    List<byte[]> expectedKeys = new ArrayList<>();
    for (int i = 0; i < (hoursAgo * 4) + 1; i++) {
        // generate the expected key
        byte[] rk = rowKeyBuilder.rowKey(m);
        expectedKeys.add(rk);
        // advance to the next period
        ProfilePeriod next = m.getPeriod().next();
        m = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(next.getStartTimeMillis(), periodDuration, periodUnits);
    }
    // execute
    List<byte[]> actualKeys = rowKeyBuilder.rowKeys(measurement.getProfileName(), measurement.getEntity(), groups, oldest, now);
    // validate - expectedKeys == actualKeys
    for (int i = 0; i < actualKeys.size(); i++) {
        byte[] actual = actualKeys.get(i);
        byte[] expected = expectedKeys.get(i);
        assertThat(actual, equalTo(expected));
    }
}
Also used : ProfilePeriod(org.apache.metron.profiler.ProfilePeriod) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) ArrayList(java.util.ArrayList) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

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