Search in sources :

Example 1 with TopologyProvider

use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.

the class BufferSizeSensorTest method providesBufferSizeMetricForBolts.

@Test
public void providesBufferSizeMetricForBolts() {
    TopologyProvider topologyProvider = mock(TopologyProvider.class);
    when(topologyProvider.getBoltNames()).thenReturn(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 = MetricName.METRIC_BUFFER_SIZE + boltId + MetricName.METRIC_BUFFER_SIZE_SUFFIX;
        registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length());
    }
    BufferSizeSensor bufferSizeSensor = new BufferSizeSensor(null, packingPlanProvider, topologyProvider, metricsProvider);
    Map<String, ComponentMetrics> componentMetrics = bufferSizeSensor.get();
    assertEquals(2, componentMetrics.size());
    assertEquals(1, componentMetrics.get("bolt-1").getMetrics().size());
    assertEquals(boltIds[0].length(), componentMetrics.get("bolt-1").getMetrics(boltIds[0]).getMetricValueSum(MetricName.METRIC_BUFFER_SIZE.text()).intValue());
    assertEquals(2, componentMetrics.get("bolt-2").getMetrics().size());
    assertEquals(boltIds[1].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[1]).getMetricValueSum(MetricName.METRIC_BUFFER_SIZE.text()).intValue());
    assertEquals(boltIds[2].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[2]).getMetricValueSum(MetricName.METRIC_BUFFER_SIZE.text()).intValue());
}
Also used : TopologyProvider(com.twitter.heron.healthmgr.common.TopologyProvider) PackingPlanProvider(com.twitter.heron.healthmgr.common.PackingPlanProvider) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) ComponentMetrics(com.microsoft.dhalion.metrics.ComponentMetrics) Test(org.junit.Test)

Example 2 with TopologyProvider

use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.

the class BackPressureSensorTest method providesBackPressureMetricForBolts.

@Test
public void providesBackPressureMetricForBolts() {
    TopologyProvider topologyProvider = mock(TopologyProvider.class);
    when(topologyProvider.getBoltNames()).thenReturn(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 = MetricName.METRIC_BACK_PRESSURE + boltId;
        // the back pressure sensor will return average bp per second, so multiply by duration
        BufferSizeSensorTest.registerStMgrInstanceMetricResponse(metricsProvider, metric, boltId.length() * DEFAULT_METRIC_DURATION.getSeconds());
    }
    BackPressureSensor backPressureSensor = new BackPressureSensor(packingPlanProvider, topologyProvider, null, metricsProvider);
    Map<String, ComponentMetrics> componentMetrics = backPressureSensor.get();
    assertEquals(2, componentMetrics.size());
    assertEquals(1, componentMetrics.get("bolt-1").getMetrics().size());
    assertEquals(boltIds[0].length(), componentMetrics.get("bolt-1").getMetrics(boltIds[0]).getMetricValueSum(MetricName.METRIC_BACK_PRESSURE.text()).intValue());
    assertEquals(2, componentMetrics.get("bolt-2").getMetrics().size());
    assertEquals(boltIds[1].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[1]).getMetricValueSum(MetricName.METRIC_BACK_PRESSURE.text()).intValue());
    assertEquals(boltIds[2].length(), componentMetrics.get("bolt-2").getMetrics(boltIds[2]).getMetricValueSum(MetricName.METRIC_BACK_PRESSURE.text()).intValue());
}
Also used : TopologyProvider(com.twitter.heron.healthmgr.common.TopologyProvider) PackingPlanProvider(com.twitter.heron.healthmgr.common.PackingPlanProvider) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) ComponentMetrics(com.microsoft.dhalion.metrics.ComponentMetrics) Test(org.junit.Test)

Example 3 with TopologyProvider

use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.

the class ScaleUpResolverTest method createTopologyProvider.

private TopologyProvider createTopologyProvider(TopologyAPI.Topology topology) {
    TopologyProvider topologyProvider = mock(TopologyProvider.class);
    when(topologyProvider.get()).thenReturn(topology);
    return topologyProvider;
}
Also used : TopologyProvider(com.twitter.heron.healthmgr.common.TopologyProvider)

Example 4 with TopologyProvider

use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.

the class ScaleUpResolverTest method testBuildPackingPlan.

@Test
public void testBuildPackingPlan() {
    TopologyAPI.Topology topology = createTestTopology();
    TopologyProvider topologyProvider = createTopologyProvider(topology);
    Config config = createConfig(topology);
    PackingPlan currentPlan = createPacking(topology, config);
    Map<String, Integer> changeRequest = new HashMap<>();
    changeRequest.put("bolt-2", 4);
    Map<String, Integer> deltaChange = new HashMap<>();
    deltaChange.put("bolt-2", 3);
    IRepacking repacking = mock(IRepacking.class);
    when(repacking.repack(currentPlan, deltaChange)).thenReturn(currentPlan);
    ScaleUpResolver resolver = new ScaleUpResolver(topologyProvider, null, null, eventManager, config);
    ScaleUpResolver spyResolver = spy(resolver);
    doReturn(repacking).when(spyResolver).getRepackingClass("Repacking");
    PackingPlan newPlan = spyResolver.buildNewPackingPlan(changeRequest, currentPlan);
    assertEquals(currentPlan, newPlan);
}
Also used : HashMap(java.util.HashMap) IRepacking(com.twitter.heron.spi.packing.IRepacking) TopologyProvider(com.twitter.heron.healthmgr.common.TopologyProvider) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Example 5 with TopologyProvider

use of com.twitter.heron.healthmgr.common.TopologyProvider in project incubator-heron by apache.

the class ExecuteCountSensorTest method providesBoltExecutionCountMetrics.

@Test
public void providesBoltExecutionCountMetrics() {
    TopologyProvider topologyProvider = mock(TopologyProvider.class);
    when(topologyProvider.getBoltNames()).thenReturn(new String[] { "bolt-1", "bolt-2" });
    MetricsProvider metricsProvider = mock(MetricsProvider.class);
    Map<String, ComponentMetrics> result = new HashMap<>();
    ComponentMetrics metrics = new ComponentMetrics("bolt-1");
    metrics.addInstanceMetric(createTestInstanceMetric("container_1_bolt-1_1", 123));
    metrics.addInstanceMetric(createTestInstanceMetric("container_1_bolt-1_2", 345));
    result.put("bolt-1", metrics);
    metrics = new ComponentMetrics("bolt-2");
    metrics.addInstanceMetric(createTestInstanceMetric("container_1_bolt-2_3", 321));
    metrics.addInstanceMetric(createTestInstanceMetric("container_1_bolt-2_4", 543));
    result.put("bolt-2", metrics);
    when(metricsProvider.getComponentMetrics(METRIC_EXE_COUNT.text(), DEFAULT_METRIC_DURATION, "bolt-1", "bolt-2")).thenReturn(result);
    ExecuteCountSensor executeCountSensor = new ExecuteCountSensor(topologyProvider, null, metricsProvider);
    Map<String, ComponentMetrics> componentMetrics = executeCountSensor.get();
    assertEquals(2, componentMetrics.size());
    assertEquals(123, componentMetrics.get("bolt-1").getMetrics("container_1_bolt-1_1").getMetricValueSum(METRIC_EXE_COUNT.text()).intValue());
    assertEquals(345, componentMetrics.get("bolt-1").getMetrics("container_1_bolt-1_2").getMetricValueSum(METRIC_EXE_COUNT.text()).intValue());
    assertEquals(321, componentMetrics.get("bolt-2").getMetrics("container_1_bolt-2_3").getMetricValueSum(METRIC_EXE_COUNT.text()).intValue());
    assertEquals(543, componentMetrics.get("bolt-2").getMetrics("container_1_bolt-2_4").getMetricValueSum(METRIC_EXE_COUNT.text()).intValue());
}
Also used : HashMap(java.util.HashMap) TopologyProvider(com.twitter.heron.healthmgr.common.TopologyProvider) MetricsProvider(com.microsoft.dhalion.api.MetricsProvider) ComponentMetrics(com.microsoft.dhalion.metrics.ComponentMetrics) Test(org.junit.Test)

Aggregations

TopologyProvider (com.twitter.heron.healthmgr.common.TopologyProvider)5 Test (org.junit.Test)4 MetricsProvider (com.microsoft.dhalion.api.MetricsProvider)3 ComponentMetrics (com.microsoft.dhalion.metrics.ComponentMetrics)3 PackingPlanProvider (com.twitter.heron.healthmgr.common.PackingPlanProvider)2 HashMap (java.util.HashMap)2 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)1 Config (com.twitter.heron.spi.common.Config)1 IRepacking (com.twitter.heron.spi.packing.IRepacking)1 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)1