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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations