use of com.microsoft.dhalion.metrics.ComponentMetrics in project incubator-heron by apache.
the class WaitQueueDisparityDetectorTest method testConfigAndFilter.
@Test
public void testConfigAndFilter() {
HealthPolicyConfig config = mock(HealthPolicyConfig.class);
when(config.getConfig(CONF_DISPARITY_RATIO, 20.0)).thenReturn(15.0);
ComponentMetrics compMetrics = new ComponentMetrics("bolt");
compMetrics.addInstanceMetric(new InstanceMetrics("i1", METRIC_BUFFER_SIZE.text(), 1501));
compMetrics.addInstanceMetric(new InstanceMetrics("i2", METRIC_BUFFER_SIZE.text(), 100));
Map<String, ComponentMetrics> topologyMetrics = new HashMap<>();
topologyMetrics.put("bolt", compMetrics);
BufferSizeSensor sensor = mock(BufferSizeSensor.class);
when(sensor.get()).thenReturn(topologyMetrics);
when(sensor.getMetricName()).thenReturn(METRIC_BUFFER_SIZE.text());
WaitQueueDisparityDetector detector = new WaitQueueDisparityDetector(sensor, config);
List<Symptom> symptoms = detector.detect();
assertEquals(1, symptoms.size());
compMetrics = new ComponentMetrics("bolt");
compMetrics.addInstanceMetric(new InstanceMetrics("i1", METRIC_BUFFER_SIZE.text(), 1500));
compMetrics.addInstanceMetric(new InstanceMetrics("i2", METRIC_BUFFER_SIZE.text(), 110));
topologyMetrics.put("bolt", compMetrics);
sensor = mock(BufferSizeSensor.class);
when(sensor.get()).thenReturn(topologyMetrics);
detector = new WaitQueueDisparityDetector(sensor, config);
symptoms = detector.detect();
assertEquals(0, symptoms.size());
}
use of com.microsoft.dhalion.metrics.ComponentMetrics in project incubator-heron by apache.
the class ScaleUpResolverTest method testScaleUpFactorComputation.
@Test
public void testScaleUpFactorComputation() {
ScaleUpResolver resolver = new ScaleUpResolver(null, null, null, eventManager, null);
ComponentMetrics metrics = new ComponentMetrics("bolt");
metrics.addInstanceMetric(new InstanceMetrics("i1", METRIC_BACK_PRESSURE.text(), 500));
metrics.addInstanceMetric(new InstanceMetrics("i2", METRIC_BACK_PRESSURE.text(), 0));
int result = resolver.computeScaleUpFactor(metrics);
assertEquals(4, result);
metrics = new ComponentMetrics("bolt");
metrics.addInstanceMetric(new InstanceMetrics("i1", METRIC_BACK_PRESSURE.text(), 750));
metrics.addInstanceMetric(new InstanceMetrics("i2", METRIC_BACK_PRESSURE.text(), 0));
result = resolver.computeScaleUpFactor(metrics);
assertEquals(8, result);
metrics = new ComponentMetrics("bolt");
metrics.addInstanceMetric(new InstanceMetrics("i1", METRIC_BACK_PRESSURE.text(), 400));
metrics.addInstanceMetric(new InstanceMetrics("i2", METRIC_BACK_PRESSURE.text(), 100));
metrics.addInstanceMetric(new InstanceMetrics("i3", METRIC_BACK_PRESSURE.text(), 0));
result = resolver.computeScaleUpFactor(metrics);
assertEquals(6, result);
}
use of com.microsoft.dhalion.metrics.ComponentMetrics 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());
}
use of com.microsoft.dhalion.metrics.ComponentMetrics in project incubator-heron by apache.
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));
Map<String, ComponentMetrics> metrics = spyMetricsProvider.getComponentMetrics(metric, Instant.ofEpochSecond(10), Duration.ofSeconds(60), comp);
assertEquals(1, metrics.size());
ComponentMetrics componentMetrics = metrics.get(comp);
assertNotNull(componentMetrics);
assertEquals(2, componentMetrics.getMetrics().size());
InstanceMetrics instanceMetrics = componentMetrics.getMetrics("container_1_bolt_1");
assertNotNull(instanceMetrics);
assertEquals(1, instanceMetrics.getMetrics().size());
Map<Instant, Double> metricValues = instanceMetrics.getMetrics().get(metric);
assertEquals(1, metricValues.size());
assertEquals(104, metricValues.get(Instant.ofEpochSecond(1497481288)).intValue());
instanceMetrics = componentMetrics.getMetrics("container_1_bolt_2");
assertNotNull(instanceMetrics);
assertEquals(1, instanceMetrics.getMetrics().size());
metricValues = instanceMetrics.getMetrics().get(metric);
assertEquals(3, metricValues.size());
assertEquals(12, metricValues.get(Instant.ofEpochSecond(1497481228L)).intValue());
assertEquals(2, metricValues.get(Instant.ofEpochSecond(1497481348L)).intValue());
assertEquals(3, metricValues.get(Instant.ofEpochSecond(1497481168L)).intValue());
}
Aggregations