Search in sources :

Example 11 with Measurement

use of com.microsoft.dhalion.core.Measurement in project heron by twitter.

the class BackPressureSensorTest method providesBackPressureMetricForBolts.

@Test
public void providesBackPressureMetricForBolts() throws IOException {
    PhysicalPlanProvider topologyProvider = mock(PhysicalPlanProvider.class);
    when(topologyProvider.getBoltNames()).thenReturn(Arrays.asList(new String[] { "bolt-1", "bolt-2" }));
    String[] boltIds = new String[] { "container_1_bolt-1_1", "container_2_bolt-2_22", "container_1_bolt-2_333" };
    PackingPlanProvider packingPlanProvider = mock(PackingPlanProvider.class);
    when(packingPlanProvider.getBoltInstanceNames("bolt-1")).thenReturn(new String[] { boltIds[0] });
    when(packingPlanProvider.getBoltInstanceNames("bolt-2")).thenReturn(new String[] { boltIds[1], boltIds[2] });
    MetricsProvider metricsProvider = mock(MetricsProvider.class);
    for (String boltId : boltIds) {
        String metric = METRIC_BACK_PRESSURE + boltId;
        // the back pressure sensor will return average bp per second, so multiply by duration
        registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length() * DEFAULT_METRIC_DURATION.getSeconds());
    }
    HealthManagerMetrics publishingMetrics = mock(HealthManagerMetrics.class);
    BackPressureSensor backPressureSensor = new BackPressureSensor(packingPlanProvider, topologyProvider, null, metricsProvider, publishingMetrics);
    ExecutionContext context = mock(ExecutionContext.class);
    when(context.checkpoint()).thenReturn(Instant.now());
    backPressureSensor.initialize(context);
    Collection<Measurement> componentMetrics = backPressureSensor.fetch();
    assertEquals(3, componentMetrics.size());
    MeasurementsTable table = MeasurementsTable.of(componentMetrics);
    assertEquals(1, table.component("bolt-1").size());
    assertEquals(boltIds[0].length(), table.component("bolt-1").instance(boltIds[0]).type(METRIC_BACK_PRESSURE.text()).sum(), 0.01);
    assertEquals(2, table.component("bolt-2").size());
    assertEquals(boltIds[1].length(), table.component("bolt-2").instance(boltIds[1]).type(METRIC_BACK_PRESSURE.text()).sum(), 0.01);
    assertEquals(boltIds[2].length(), table.component("bolt-2").instance(boltIds[2]).type(METRIC_BACK_PRESSURE.text()).sum(), 0.01);
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) ExecutionContext(com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) PhysicalPlanProvider(org.apache.heron.healthmgr.common.PhysicalPlanProvider) HealthManagerMetrics(org.apache.heron.healthmgr.HealthManagerMetrics) PackingPlanProvider(org.apache.heron.healthmgr.common.PackingPlanProvider) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) Test(org.junit.Test)

Example 12 with Measurement

use of com.microsoft.dhalion.core.Measurement in project heron by twitter.

the class ExecuteCountSensorTest method providesBoltExecutionCountMetrics.

@Test
public void providesBoltExecutionCountMetrics() {
    Instant now = Instant.now();
    String metric = METRIC_EXE_COUNT.text();
    PhysicalPlanProvider topologyProvider = mock(PhysicalPlanProvider.class);
    when(topologyProvider.getBoltNames()).thenReturn(Arrays.asList(new String[] { "bolt-1", "bolt-2" }));
    MetricsProvider metricsProvider = mock(MetricsProvider.class);
    Collection<Measurement> result = new ArrayList<>();
    result.add(new Measurement("bolt-1", "container_1_bolt-1_1", metric, now, 123));
    result.add(new Measurement("bolt-1", "container_1_bolt-1_2", metric, now, 345));
    result.add(new Measurement("bolt-2", "container_1_bolt-2_3", metric, now, 321));
    result.add(new Measurement("bolt-2", "container_1_bolt-2_4", metric, now, 543));
    Collection<String> comps = Arrays.asList("bolt-1", "bolt-2");
    when(metricsProvider.getMeasurements(any(Instant.class), eq(DEFAULT_METRIC_DURATION), eq(Collections.singletonList(metric)), eq(comps))).thenReturn(result);
    ExecuteCountSensor executeCountSensor = new ExecuteCountSensor(topologyProvider, null, metricsProvider);
    PoliciesExecutor.ExecutionContext context = mock(PoliciesExecutor.ExecutionContext.class);
    when(context.checkpoint()).thenReturn(now);
    executeCountSensor.initialize(context);
    Collection<Measurement> componentMetrics = executeCountSensor.fetch();
    assertEquals(4, componentMetrics.size());
    MeasurementsTable table = MeasurementsTable.of(componentMetrics);
    assertEquals(123, table.component("bolt-1").instance("container_1_bolt-1_1").type(metric).sum(), 0.01);
    assertEquals(345, table.component("bolt-1").instance("container_1_bolt-1_2").type(metric).sum(), 0.01);
    assertEquals(321, table.component("bolt-2").instance("container_1_bolt-2_3").type(metric).sum(), 0.01);
    assertEquals(543, table.component("bolt-2").instance("container_1_bolt-2_4").type(metric).sum(), 0.01);
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) PhysicalPlanProvider(org.apache.heron.healthmgr.common.PhysicalPlanProvider) Instant(java.time.Instant) ArrayList(java.util.ArrayList) PoliciesExecutor(com.microsoft.dhalion.policy.PoliciesExecutor) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) Test(org.junit.Test)

Example 13 with Measurement

use of com.microsoft.dhalion.core.Measurement in project heron by twitter.

the class TrackerMetricsProviderTest method provides1Comp2InstanceMetricsFromTracker.

@Test
public void provides1Comp2InstanceMetricsFromTracker() {
    TrackerMetricsProvider spyMetricsProvider = createMetricsProviderSpy();
    String metric = "count";
    String comp = "bolt";
    String response = "{\"status\": \"success\", \"executiontime\": 0.002241849899291992, " + "\"message\": \"\", \"version\": \"ver\", \"result\": " + "{\"timeline\": {\"count\": " + "{\"container_1_bolt_1\": {\"1497481288\": \"104\"}, " + "\"container_1_bolt_2\": {\"1497481228\": \"12\", \"1497481348\": \"2\", " + "\"1497481168\": \"3\"}}}, " + "\"endtime\": 1497481388, \"component\": \"bolt\", \"starttime\": 1497481208}}";
    doReturn(response).when(spyMetricsProvider).getMetricsFromTracker(metric, comp, Instant.ofEpochSecond(10), Duration.ofSeconds(60));
    Collection<Measurement> metrics = spyMetricsProvider.getMeasurements(Instant.ofEpochSecond(10), Duration.ofSeconds(60), metric, comp);
    assertEquals(4, metrics.size());
    MeasurementsTable table = MeasurementsTable.of(metrics);
    assertEquals(4, table.component(comp).size());
    assertEquals(2, table.uniqueInstances().size());
    assertEquals(1, table.uniqueTypes().size());
    assertEquals(1, table.instance("container_1_bolt_1").size());
    assertEquals(104, table.instance("container_1_bolt_1").sum(), 0.01);
    assertEquals(3, table.instance("container_1_bolt_2").size());
    assertEquals(17, table.instance("container_1_bolt_2").sum(), 0.01);
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) Test(org.junit.Test)

Example 14 with Measurement

use of com.microsoft.dhalion.core.Measurement in project heron by twitter.

the class TrackerMetricsProviderTest method testGetTimeLineMetrics.

@Test
public void testGetTimeLineMetrics() {
    TrackerMetricsProvider spyMetricsProvider = createMetricsProviderSpy();
    String metric = "count";
    String comp = "bolt";
    String response = "{\"status\": \"success\", \"executiontime\": 0.002241849899291992, " + "\"message\": \"\", \"version\": \"ver\", \"result\": " + "{\"timeline\": {\"count\": " + "{\"container_1_bolt_1\": {\"1497481288\": \"104\"}, " + "\"container_1_bolt_2\": {\"1497481228\": \"12\", \"1497481348\": \"2\", " + "\"1497481168\": \"3\"}}}, " + "\"endtime\": 1497481388, \"component\": \"bolt\", \"starttime\": 1497481208}}";
    doReturn(response).when(spyMetricsProvider).getMetricsFromTracker(metric, comp, Instant.ofEpochSecond(10), Duration.ofSeconds(60));
    Collection<Measurement> metrics = spyMetricsProvider.getMeasurements(Instant.ofEpochSecond(10), Duration.ofSeconds(60), metric, comp);
    assertEquals(4, metrics.size());
    MeasurementsTable table = MeasurementsTable.of(metrics);
    assertEquals(4, table.component(comp).size());
    MeasurementsTable result = table.instance("container_1_bolt_1");
    assertEquals(1, result.size());
    assertEquals(104, result.instant(Instant.ofEpochSecond(1497481288)).sum(), 0.01);
    result = table.instance("container_1_bolt_2");
    assertEquals(3, result.size());
    assertEquals(12, result.instant(Instant.ofEpochSecond(1497481228L)).sum(), 0.01);
    assertEquals(2, result.instant(Instant.ofEpochSecond(1497481348L)).sum(), 0.01);
    assertEquals(3, result.instant(Instant.ofEpochSecond(1497481168L)).sum(), 0.01);
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) Test(org.junit.Test)

Example 15 with Measurement

use of com.microsoft.dhalion.core.Measurement in project heron by twitter.

the class ProcessingRateSkewDetectorTest method testConfigAndFilter.

@Test
public void testConfigAndFilter() {
    HealthPolicyConfig config = mock(HealthPolicyConfig.class);
    when(config.getConfig(CONF_SKEW_RATIO, 1.5)).thenReturn(2.5);
    Measurement measurement1 = new Measurement("bolt", "i1", METRIC_EXE_COUNT.text(), Instant.ofEpochSecond(1497892222), 1000);
    Measurement measurement2 = new Measurement("bolt", "i2", METRIC_EXE_COUNT.text(), Instant.ofEpochSecond(1497892222), 200.0);
    Collection<Measurement> metrics = new ArrayList<>();
    metrics.add(measurement1);
    metrics.add(measurement2);
    ProcessingRateSkewDetector detector = new ProcessingRateSkewDetector(config);
    PoliciesExecutor.ExecutionContext context = mock(PoliciesExecutor.ExecutionContext.class);
    when(context.checkpoint()).thenReturn(Instant.now());
    detector.initialize(context);
    Collection<Symptom> symptoms = detector.detect(metrics);
    assertEquals(3, symptoms.size());
    SymptomsTable symptomsTable = SymptomsTable.of(symptoms);
    assertEquals(1, symptomsTable.type("POSITIVE " + BaseDetector.SymptomType.SYMPTOM_PROCESSING_RATE_SKEW).size());
    assertEquals(1, symptomsTable.type("NEGATIVE " + BaseDetector.SymptomType.SYMPTOM_PROCESSING_RATE_SKEW).size());
    assertEquals(1, symptomsTable.type("POSITIVE " + BaseDetector.SymptomType.SYMPTOM_PROCESSING_RATE_SKEW).assignment("i1").size());
    assertEquals(1, symptomsTable.type("NEGATIVE " + BaseDetector.SymptomType.SYMPTOM_PROCESSING_RATE_SKEW).assignment("i2").size());
    measurement1 = new Measurement("bolt", "i1", METRIC_EXE_COUNT.text(), Instant.ofEpochSecond(1497892222), 1000);
    measurement2 = new Measurement("bolt", "i2", METRIC_EXE_COUNT.text(), Instant.ofEpochSecond(1497892222), 500.0);
    metrics = new ArrayList<>();
    metrics.add(measurement1);
    metrics.add(measurement2);
    detector = new ProcessingRateSkewDetector(config);
    detector.initialize(context);
    symptoms = detector.detect(metrics);
    assertEquals(0, symptoms.size());
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) HealthPolicyConfig(org.apache.heron.healthmgr.HealthPolicyConfig) ArrayList(java.util.ArrayList) PoliciesExecutor(com.microsoft.dhalion.policy.PoliciesExecutor) Symptom(com.microsoft.dhalion.core.Symptom) SymptomsTable(com.microsoft.dhalion.core.SymptomsTable) Test(org.junit.Test)

Aggregations

Measurement (com.microsoft.dhalion.core.Measurement)28 Test (org.junit.Test)20 MeasurementsTable (com.microsoft.dhalion.core.MeasurementsTable)14 ArrayList (java.util.ArrayList)13 PoliciesExecutor (com.microsoft.dhalion.policy.PoliciesExecutor)8 HealthPolicyConfig (org.apache.heron.healthmgr.HealthPolicyConfig)7 Symptom (com.microsoft.dhalion.core.Symptom)6 Instant (java.time.Instant)6 SymptomsTable (com.microsoft.dhalion.core.SymptomsTable)4 TopologyManager (org.apache.heron.proto.tmanager.TopologyManager)4 MetricsProvider (com.microsoft.dhalion.api.MetricsProvider)3 ExecutionContext (com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext)3 PackingPlanProvider (org.apache.heron.healthmgr.common.PackingPlanProvider)3 PhysicalPlanProvider (org.apache.heron.healthmgr.common.PhysicalPlanProvider)3 Duration (java.time.Duration)2 HealthManagerMetrics (org.apache.heron.healthmgr.HealthManagerMetrics)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DocumentContext (com.jayway.jsonpath.DocumentContext)1 Action (com.microsoft.dhalion.core.Action)1 Diagnosis (com.microsoft.dhalion.core.Diagnosis)1