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