Search in sources :

Example 11 with ProfileMeasurement

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

the class KafkaEmitterTest method testStringIsValidType.

/**
 * Values destined for Kafka can only be serialized into text, which limits the types of values
 * that can result from a triage expression.  Only primitive types and Strings are allowed.
 */
@Test
public void testStringIsValidType() throws Exception {
    ProfileMeasurement measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withTriageValues(Collections.singletonMap("triage-key", "value")).withDefinition(profile);
    handler.emit(measurement, collector);
    ArgumentCaptor<Values> arg = ArgumentCaptor.forClass(Values.class);
    verify(collector, times(1)).emit(eq(handler.getStreamId()), arg.capture());
    Values values = arg.getValue();
    assertTrue(values.get(0) instanceof JSONObject);
    JSONObject actual = (JSONObject) values.get(0);
    // the triage expression is valid
    assertEquals(measurement.getTriageValues().get("triage-key"), actual.get("triage-key"));
}
Also used : JSONObject(org.json.simple.JSONObject) Values(org.apache.storm.tuple.Values) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Example 12 with ProfileMeasurement

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

the class KafkaEmitterTest method testSerialization.

/**
 * The handler must serialize the ProfileMeasurement into a JSONObject.
 */
@Test
public void testSerialization() throws Exception {
    ProfileMeasurement measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withTriageValues(Collections.singletonMap("triage-key", "triage-value")).withDefinition(profile);
    handler.emit(measurement, collector);
    ArgumentCaptor<Values> arg = ArgumentCaptor.forClass(Values.class);
    verify(collector, times(1)).emit(eq(handler.getStreamId()), arg.capture());
    // expect a JSONObject
    Values values = arg.getValue();
    assertTrue(values.get(0) instanceof JSONObject);
    // validate the json
    JSONObject actual = (JSONObject) values.get(0);
    assertEquals(measurement.getDefinition().getProfile(), actual.get("profile"));
    assertEquals(measurement.getEntity(), actual.get("entity"));
    assertEquals(measurement.getPeriod().getPeriod(), actual.get("period"));
    assertEquals(measurement.getPeriod().getStartTimeMillis(), actual.get("period.start"));
    assertEquals(measurement.getPeriod().getEndTimeMillis(), actual.get("period.end"));
    assertEquals(measurement.getTriageValues().get("triage-key"), actual.get("triage-key"));
    assertNotNull(actual.get("timestamp"));
    assertEquals("profiler", actual.get("source.type"));
}
Also used : JSONObject(org.json.simple.JSONObject) Values(org.apache.storm.tuple.Values) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Example 13 with ProfileMeasurement

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

the class KafkaEmitterTest method testInvalidType.

/**
 * Values destined for Kafka can only be serialized into text, which limits the types of values
 * that can result from a triage expression.  Only primitive types and Strings are allowed.
 */
@Test
public void testInvalidType() throws Exception {
    // create one invalid expression and one valid expression
    Map<String, Object> triageValues = ImmutableMap.of("invalid", new OnlineStatisticsProvider(), "valid", 4);
    ProfileMeasurement measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withTriageValues(triageValues).withDefinition(profile);
    handler.emit(measurement, collector);
    ArgumentCaptor<Values> arg = ArgumentCaptor.forClass(Values.class);
    verify(collector, times(1)).emit(eq(handler.getStreamId()), arg.capture());
    Values values = arg.getValue();
    assertTrue(values.get(0) instanceof JSONObject);
    // only the triage expression value itself should have been skipped, all others should be there
    JSONObject actual = (JSONObject) values.get(0);
    assertEquals(measurement.getDefinition().getProfile(), actual.get("profile"));
    assertEquals(measurement.getEntity(), actual.get("entity"));
    assertEquals(measurement.getPeriod().getPeriod(), actual.get("period"));
    assertEquals(measurement.getPeriod().getStartTimeMillis(), actual.get("period.start"));
    assertEquals(measurement.getPeriod().getEndTimeMillis(), actual.get("period.end"));
    assertNotNull(actual.get("timestamp"));
    assertEquals("profiler", actual.get("source.type"));
    // the invalid expression should be skipped due to invalid type
    assertFalse(actual.containsKey("invalid"));
    // but the valid expression should still be there
    assertEquals(triageValues.get("valid"), actual.get("valid"));
}
Also used : JSONObject(org.json.simple.JSONObject) Values(org.apache.storm.tuple.Values) OnlineStatisticsProvider(org.apache.metron.statistics.OnlineStatisticsProvider) JSONObject(org.json.simple.JSONObject) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Example 14 with ProfileMeasurement

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

the class KafkaEmitterTest method testIntegerIsValidType.

/**
 * Values destined for Kafka can only be serialized into text, which limits the types of values
 * that can result from a triage expression.  Only primitive types and Strings are allowed.
 */
@Test
public void testIntegerIsValidType() throws Exception {
    ProfileMeasurement measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withTriageValues(Collections.singletonMap("triage-key", 123)).withDefinition(profile);
    handler.emit(measurement, collector);
    ArgumentCaptor<Values> arg = ArgumentCaptor.forClass(Values.class);
    verify(collector, times(1)).emit(eq(handler.getStreamId()), arg.capture());
    Values values = arg.getValue();
    assertTrue(values.get(0) instanceof JSONObject);
    JSONObject actual = (JSONObject) values.get(0);
    // the triage expression is valid
    assertEquals(measurement.getTriageValues().get("triage-key"), actual.get("triage-key"));
}
Also used : JSONObject(org.json.simple.JSONObject) Values(org.apache.storm.tuple.Values) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Example 15 with ProfileMeasurement

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

the class ProfileBuilderBoltTest method testDoNotEmitWhenNoFlush.

/**
 * If the {@code FlushSignal} tells the bolt NOT to flush, nothing should be emitted.
 */
@Test
public void testDoNotEmitWhenNoFlush() throws Exception {
    ProfileBuilderBolt bolt = createBolt();
    // create a profile measurement
    ProfileMeasurement m = new ProfileMeasurement().withEntity("entity1").withProfileName("profile1").withPeriod(1000, 500, TimeUnit.MILLISECONDS).withProfileValue(22);
    // create a mock that returns the profile measurement above
    MessageDistributor distributor = mock(MessageDistributor.class);
    when(distributor.flush()).thenReturn(Collections.singletonList(m));
    bolt.withMessageDistributor(distributor);
    // no flush signal
    flushSignal.setFlushNow(false);
    // execute the bolt
    Tuple tuple1 = createTuple("entity1", message1, profile1, 1000L);
    TupleWindow tupleWindow = createWindow(tuple1);
    bolt.execute(tupleWindow);
    // nothing should have been emitted
    getProfileMeasurements(outputCollector, 0);
}
Also used : MessageDistributor(org.apache.metron.profiler.MessageDistributor) TupleWindow(org.apache.storm.windowing.TupleWindow) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Tuple(org.apache.storm.tuple.Tuple) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest) 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