Search in sources :

Example 6 with MeasurementsTable

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

the class BufferSizeSensorTest method providesBufferSizeMetricForBolts.

@Test
public void providesBufferSizeMetricForBolts() {
    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_WAIT_Q_SIZE + boltId + MetricName.METRIC_WAIT_Q_SIZE_SUFFIX;
        BackPressureSensorTest.registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length());
    }
    BufferSizeSensor bufferSizeSensor = new BufferSizeSensor(null, packingPlanProvider, topologyProvider, metricsProvider);
    PoliciesExecutor.ExecutionContext context = mock(PoliciesExecutor.ExecutionContext.class);
    when(context.checkpoint()).thenReturn(Instant.now());
    bufferSizeSensor.initialize(context);
    Collection<Measurement> componentMetrics = bufferSizeSensor.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_WAIT_Q_SIZE.text()).sum(), 0.01);
    assertEquals(2, table.component("bolt-2").size());
    assertEquals(boltIds[1].length(), table.component("bolt-2").instance(boltIds[1]).type(METRIC_WAIT_Q_SIZE.text()).sum(), 0.01);
    assertEquals(boltIds[2].length(), table.component("bolt-2").instance(boltIds[2]).type(METRIC_WAIT_Q_SIZE.text()).sum(), 0.01);
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) PhysicalPlanProvider(org.apache.heron.healthmgr.common.PhysicalPlanProvider) PackingPlanProvider(org.apache.heron.healthmgr.common.PackingPlanProvider) PoliciesExecutor(com.microsoft.dhalion.policy.PoliciesExecutor) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) Test(org.junit.Test)

Example 7 with MeasurementsTable

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

the class MetricsCacheMetricsProviderTest method provides1Comp2InstanceMetricsFromMetricsCache.

@Test
public void provides1Comp2InstanceMetricsFromMetricsCache() {
    MetricsCacheMetricsProvider spyMetricsProvider = createMetricsProviderSpy();
    String metric = "count";
    String comp = "bolt";
    TopologyManager.MetricResponse response = TopologyManager.MetricResponse.newBuilder().setStatus(Status.newBuilder().setStatus(StatusCode.OK)).addMetric(TaskMetric.newBuilder().setInstanceId("container_1_bolt_1").addMetric(IndividualMetric.newBuilder().setName(metric).addIntervalValues(IntervalValue.newBuilder().setValue("104").setInterval(MetricInterval.newBuilder().setStart(1497481288).setEnd(1497481288))))).addMetric(TaskMetric.newBuilder().setInstanceId("container_1_bolt_2").addMetric(IndividualMetric.newBuilder().setName(metric).addIntervalValues(IntervalValue.newBuilder().setValue("12").setInterval(MetricInterval.newBuilder().setStart(1497481228).setEnd(1497481228))).addIntervalValues(IntervalValue.newBuilder().setValue("2").setInterval(MetricInterval.newBuilder().setStart(1497481348).setEnd(1497481348))).addIntervalValues(IntervalValue.newBuilder().setValue("3").setInterval(MetricInterval.newBuilder().setStart(1497481168).setEnd(1497481168))))).build();
    doReturn(response).when(spyMetricsProvider).getMetricsFromMetricsCache(metric, comp, Instant.ofEpochSecond(10), Duration.ofSeconds(60));
    Collection<Measurement> metrics = spyMetricsProvider.getMeasurements(Instant.ofEpochSecond(10), Duration.ofSeconds(60), metric, comp);
    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 : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) Measurement(com.microsoft.dhalion.core.Measurement) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) Test(org.junit.Test)

Example 8 with MeasurementsTable

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

the class MetricsCacheMetricsProviderTest method testGetTimeLineMetrics.

@Test
public void testGetTimeLineMetrics() {
    MetricsCacheMetricsProvider spyMetricsProvider = createMetricsProviderSpy();
    String metric = "count";
    String comp = "bolt";
    TopologyManager.MetricResponse response = TopologyManager.MetricResponse.newBuilder().setStatus(Status.newBuilder().setStatus(StatusCode.OK)).addMetric(TaskMetric.newBuilder().setInstanceId("container_1_bolt_1").addMetric(IndividualMetric.newBuilder().setName(metric).addIntervalValues(IntervalValue.newBuilder().setValue("104").setInterval(MetricInterval.newBuilder().setStart(1497481288).setEnd(1497481288))))).addMetric(TaskMetric.newBuilder().setInstanceId("container_1_bolt_2").addMetric(IndividualMetric.newBuilder().setName(metric).addIntervalValues(IntervalValue.newBuilder().setValue("12").setInterval(MetricInterval.newBuilder().setStart(1497481228).setEnd(1497481228))).addIntervalValues(IntervalValue.newBuilder().setValue("2").setInterval(MetricInterval.newBuilder().setStart(1497481348).setEnd(1497481348))).addIntervalValues(IntervalValue.newBuilder().setValue("3").setInterval(MetricInterval.newBuilder().setStart(1497481168).setEnd(1497481168))))).build();
    doReturn(response).when(spyMetricsProvider).getMetricsFromMetricsCache(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 : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) Measurement(com.microsoft.dhalion.core.Measurement) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) Test(org.junit.Test)

Example 9 with MeasurementsTable

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

the class ProcessingRateSkewDetectorTest method testGetMaxMin.

@Test
public void testGetMaxMin() {
    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", "i1", METRIC_EXE_COUNT.text(), Instant.ofEpochSecond(1497892122), 3000);
    Measurement measurement3 = new Measurement("bolt", "i2", METRIC_EXE_COUNT.text(), Instant.ofEpochSecond(1497892222), 200.0);
    Measurement measurement4 = new Measurement("bolt", "i2", METRIC_EXE_COUNT.text(), Instant.ofEpochSecond(1497892222), 400.0);
    Collection<Measurement> metrics = new ArrayList<>();
    metrics.add(measurement1);
    metrics.add(measurement2);
    metrics.add(measurement3);
    metrics.add(measurement4);
    MeasurementsTable metricsTable = MeasurementsTable.of(metrics);
    ProcessingRateSkewDetector detector = new ProcessingRateSkewDetector(config);
    assertEquals(2000, (int) detector.getMaxOfAverage(metricsTable));
    assertEquals(300, (int) detector.getMinOfAverage(metricsTable));
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) HealthPolicyConfig(org.apache.heron.healthmgr.HealthPolicyConfig) MeasurementsTable(com.microsoft.dhalion.core.MeasurementsTable) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with MeasurementsTable

use of com.microsoft.dhalion.core.MeasurementsTable 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)

Aggregations

MeasurementsTable (com.microsoft.dhalion.core.MeasurementsTable)21 Measurement (com.microsoft.dhalion.core.Measurement)14 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 Instant (java.time.Instant)8 Symptom (com.microsoft.dhalion.core.Symptom)4 TopologyManager (org.apache.heron.proto.tmanager.TopologyManager)4 MetricsProvider (com.microsoft.dhalion.api.MetricsProvider)3 PhysicalPlanProvider (org.apache.heron.healthmgr.common.PhysicalPlanProvider)3 Diagnosis (com.microsoft.dhalion.core.Diagnosis)2 SymptomsTable (com.microsoft.dhalion.core.SymptomsTable)2 PoliciesExecutor (com.microsoft.dhalion.policy.PoliciesExecutor)2 Duration (java.time.Duration)2 HashSet (java.util.HashSet)2 PackingPlanProvider (org.apache.heron.healthmgr.common.PackingPlanProvider)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ExecutionContext (com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext)1 HealthManagerMetrics (org.apache.heron.healthmgr.HealthManagerMetrics)1 HealthPolicyConfig (org.apache.heron.healthmgr.HealthPolicyConfig)1