use of org.apache.heron.healthmgr.HealthManagerMetrics in project heron by twitter.
the class BackPressureDetectorTest method testConfigAndFilter.
@Test
public void testConfigAndFilter() throws IOException {
HealthPolicyConfig config = mock(HealthPolicyConfig.class);
when(config.getConfig(CONF_NOISE_FILTER, 20)).thenReturn(50);
Measurement measurement1 = new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 55);
Measurement measurement2 = new Measurement("bolt", "i2", METRIC_BACK_PRESSURE.text(), now, 3);
Measurement measurement3 = new Measurement("bolt", "i3", METRIC_BACK_PRESSURE.text(), now, 0);
Collection<Measurement> metrics = new ArrayList<>();
metrics.add(measurement1);
metrics.add(measurement2);
metrics.add(measurement3);
HealthManagerMetrics publishingMetrics = mock(HealthManagerMetrics.class);
BackPressureDetector detector = new BackPressureDetector(config, publishingMetrics);
PoliciesExecutor.ExecutionContext context = mock(PoliciesExecutor.ExecutionContext.class);
when(context.checkpoint()).thenReturn(now);
detector.initialize(context);
Collection<Symptom> symptoms = detector.detect(metrics);
Assert.assertEquals(2, symptoms.size());
SymptomsTable compSymptom = SymptomsTable.of(symptoms).type(SYMPTOM_COMP_BACK_PRESSURE.text());
Assert.assertEquals(1, compSymptom.size());
Assert.assertEquals(1, compSymptom.get().iterator().next().assignments().size());
SymptomsTable instanceSymptom = SymptomsTable.of(symptoms).type(SYMPTOM_INSTANCE_BACK_PRESSURE.text());
Assert.assertEquals(1, instanceSymptom.size());
Assert.assertEquals(1, instanceSymptom.get().iterator().next().assignments().size());
Symptom symptom = symptoms.iterator().next();
measurement1 = new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 45);
measurement2 = new Measurement("bolt", "i2", METRIC_BACK_PRESSURE.text(), now, 3);
metrics = new ArrayList<>();
metrics.add(measurement1);
metrics.add(measurement2);
detector = new BackPressureDetector(config, publishingMetrics);
detector.initialize(context);
symptoms = detector.detect(metrics);
Assert.assertEquals(0, symptoms.size());
}
use of org.apache.heron.healthmgr.HealthManagerMetrics in project heron by twitter.
the class SlowInstanceDiagnoserTest method initTestData.
@Before
public void initTestData() throws IOException {
now = Instant.now();
measurements = new ArrayList<>();
context = mock(ExecutionContext.class);
when(context.checkpoint()).thenReturn(now);
HealthManagerMetrics publishingMetrics = mock(HealthManagerMetrics.class);
diagnoser = new SlowInstanceDiagnoser(publishingMetrics);
diagnoser.initialize(context);
}
use of org.apache.heron.healthmgr.HealthManagerMetrics 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);
}
Aggregations