use of com.microsoft.dhalion.metrics.InstanceMetrics in project incubator-heron by apache.
the class TrackerMetricsProvider method parse.
@SuppressWarnings("unchecked")
private Map<String, InstanceMetrics> parse(String response, String component, String metric) {
Map<String, InstanceMetrics> metricsData = new HashMap<>();
if (response == null || response.isEmpty()) {
return metricsData;
}
DocumentContext result = JsonPath.parse(response);
JSONArray jsonArray = result.read("$.." + metric);
if (jsonArray.size() != 1) {
LOG.info(String.format("Did not get any metrics from tracker for %s:%s ", component, metric));
return metricsData;
}
Map<String, Object> metricsMap = (Map<String, Object>) jsonArray.get(0);
if (metricsMap == null || metricsMap.isEmpty()) {
LOG.info(String.format("Did not get any metrics from tracker for %s:%s ", component, metric));
return metricsData;
}
for (String instanceName : metricsMap.keySet()) {
Map<String, String> tmpValues = (Map<String, String>) metricsMap.get(instanceName);
Map<Instant, Double> values = new HashMap<>();
for (String timeStamp : tmpValues.keySet()) {
values.put(Instant.ofEpochSecond(Long.parseLong(timeStamp)), Double.parseDouble(tmpValues.get(timeStamp)));
}
InstanceMetrics instanceMetrics = new InstanceMetrics(instanceName);
instanceMetrics.addMetric(metric, values);
metricsData.put(instanceName, instanceMetrics);
}
return metricsData;
}
use of com.microsoft.dhalion.metrics.InstanceMetrics in project incubator-heron by apache.
the class GrowingWaitQueueDetectorTest method testDetector.
@Test
public void testDetector() {
HealthPolicyConfig config = mock(HealthPolicyConfig.class);
when(config.getConfig(CONF_LIMIT, 10.0)).thenReturn(5.0);
ComponentMetrics compMetrics;
InstanceMetrics instanceMetrics;
Map<Instant, Double> bufferSizes;
Map<String, ComponentMetrics> topologyMetrics = new HashMap<>();
instanceMetrics = new InstanceMetrics("i1");
bufferSizes = new HashMap<>();
bufferSizes.put(Instant.ofEpochSecond(1497892222), 0.0);
bufferSizes.put(Instant.ofEpochSecond(1497892270), 300.0);
bufferSizes.put(Instant.ofEpochSecond(1497892330), 700.0);
bufferSizes.put(Instant.ofEpochSecond(1497892390), 1000.0);
bufferSizes.put(Instant.ofEpochSecond(1497892450), 1300.0);
instanceMetrics.addMetric(METRIC_BUFFER_SIZE.text(), bufferSizes);
compMetrics = new ComponentMetrics("bolt");
compMetrics.addInstanceMetric(instanceMetrics);
topologyMetrics.put("bolt", compMetrics);
BufferSizeSensor sensor = mock(BufferSizeSensor.class);
when(sensor.get()).thenReturn(topologyMetrics);
GrowingWaitQueueDetector detector = new GrowingWaitQueueDetector(sensor, config);
List<Symptom> symptoms = detector.detect();
assertEquals(1, symptoms.size());
instanceMetrics = new InstanceMetrics("i1");
bufferSizes = new HashMap<>();
bufferSizes.put(Instant.ofEpochSecond(1497892222), 0.0);
bufferSizes.put(Instant.ofEpochSecond(1497892270), 200.0);
bufferSizes.put(Instant.ofEpochSecond(1497892330), 400.0);
bufferSizes.put(Instant.ofEpochSecond(1497892390), 600.0);
bufferSizes.put(Instant.ofEpochSecond(1497892450), 800.0);
instanceMetrics.addMetric(METRIC_BUFFER_SIZE.text(), bufferSizes);
compMetrics = new ComponentMetrics("bolt");
compMetrics.addInstanceMetric(instanceMetrics);
topologyMetrics.put("bolt", compMetrics);
sensor = mock(BufferSizeSensor.class);
when(sensor.get()).thenReturn(topologyMetrics);
detector = new GrowingWaitQueueDetector(sensor, config);
symptoms = detector.detect();
assertEquals(0, symptoms.size());
}
use of com.microsoft.dhalion.metrics.InstanceMetrics in project incubator-heron by apache.
the class ProcessingRateSkewDetectorTest method testConfigAndFilter.
@Test
public void testConfigAndFilter() {
HealthPolicyConfig config = mock(HealthPolicyConfig.class);
when(config.getConfig(CONF_SKEW_RATIO, 1.5)).thenReturn(2.5);
ComponentMetrics compMetrics = new ComponentMetrics("bolt");
compMetrics.addInstanceMetric(new InstanceMetrics("i1", METRIC_EXE_COUNT.text(), 1000));
compMetrics.addInstanceMetric(new InstanceMetrics("i2", METRIC_EXE_COUNT.text(), 200));
Map<String, ComponentMetrics> topologyMetrics = new HashMap<>();
topologyMetrics.put("bolt", compMetrics);
ExecuteCountSensor sensor = mock(ExecuteCountSensor.class);
when(sensor.get()).thenReturn(topologyMetrics);
when(sensor.getMetricName()).thenReturn(METRIC_EXE_COUNT.text());
ProcessingRateSkewDetector detector = new ProcessingRateSkewDetector(sensor, config);
List<Symptom> symptoms = detector.detect();
assertEquals(1, symptoms.size());
compMetrics = new ComponentMetrics("bolt");
compMetrics.addInstanceMetric(new InstanceMetrics("i1", METRIC_EXE_COUNT.text(), 1000));
compMetrics.addInstanceMetric(new InstanceMetrics("i2", METRIC_EXE_COUNT.text(), 500));
topologyMetrics.put("bolt", compMetrics);
sensor = mock(ExecuteCountSensor.class);
when(sensor.get()).thenReturn(topologyMetrics);
detector = new ProcessingRateSkewDetector(sensor, config);
symptoms = detector.detect();
assertEquals(0, symptoms.size());
}
use of com.microsoft.dhalion.metrics.InstanceMetrics in project incubator-heron by apache.
the class ProcessingRateSkewDetectorTest method testReturnsMultipleComponents.
@Test
public void testReturnsMultipleComponents() {
HealthPolicyConfig config = mock(HealthPolicyConfig.class);
when(config.getConfig(CONF_SKEW_RATIO, 1.5)).thenReturn(2.5);
ComponentMetrics compMetrics1 = new ComponentMetrics("bolt-1");
compMetrics1.addInstanceMetric(new InstanceMetrics("i1", METRIC_EXE_COUNT.text(), 1000));
compMetrics1.addInstanceMetric(new InstanceMetrics("i2", METRIC_EXE_COUNT.text(), 200));
ComponentMetrics compMetrics2 = new ComponentMetrics("bolt-2");
compMetrics2.addInstanceMetric(new InstanceMetrics("i1", METRIC_EXE_COUNT.text(), 1000));
compMetrics2.addInstanceMetric(new InstanceMetrics("i2", METRIC_EXE_COUNT.text(), 200));
ComponentMetrics compMetrics3 = new ComponentMetrics("bolt-3");
compMetrics3.addInstanceMetric(new InstanceMetrics("i1", METRIC_EXE_COUNT.text(), 1000));
compMetrics3.addInstanceMetric(new InstanceMetrics("i2", METRIC_EXE_COUNT.text(), 500));
Map<String, ComponentMetrics> topologyMetrics = new HashMap<>();
topologyMetrics.put("bolt-1", compMetrics1);
topologyMetrics.put("bolt-2", compMetrics2);
topologyMetrics.put("bolt-3", compMetrics3);
ExecuteCountSensor sensor = mock(ExecuteCountSensor.class);
when(sensor.get()).thenReturn(topologyMetrics);
when(sensor.getMetricName()).thenReturn(METRIC_EXE_COUNT.text());
ProcessingRateSkewDetector detector = new ProcessingRateSkewDetector(sensor, config);
List<Symptom> symptoms = detector.detect();
assertEquals(2, symptoms.size());
for (Symptom symptom : symptoms) {
if (symptom.getComponent().getName().equals("bolt-1")) {
compMetrics1 = null;
} else if (symptom.getComponent().getName().equals("bolt-2")) {
compMetrics2 = null;
} else if (symptom.getComponent().getName().equals("bolt-3")) {
compMetrics3 = null;
}
}
assertNull(compMetrics1);
assertNull(compMetrics2);
assertNotNull(compMetrics3);
}
use of com.microsoft.dhalion.metrics.InstanceMetrics in project incubator-heron by apache.
the class ScaleUpResolver method computeScaleUpFactor.
@VisibleForTesting
int computeScaleUpFactor(ComponentMetrics componentMetrics) {
double totalCompBpTime = 0;
String compName = componentMetrics.getName();
for (InstanceMetrics instanceMetrics : componentMetrics.getMetrics().values()) {
double instanceBp = instanceMetrics.getMetricValueSum(METRIC_BACK_PRESSURE.text());
LOG.info(String.format("Instance:%s, bpTime:%.0f", instanceMetrics.getName(), instanceBp));
totalCompBpTime += instanceBp;
}
LOG.info(String.format("Component: %s, bpTime: %.0f", compName, totalCompBpTime));
if (totalCompBpTime >= 1000) {
totalCompBpTime = 999;
}
LOG.warning(String.format("Comp:%s, bpTime after filter: %.0f", compName, totalCompBpTime));
double unusedCapacity = (1.0 * totalCompBpTime) / (1000 - totalCompBpTime);
// scale up fencing: do not scale more than 4 times the current size
unusedCapacity = unusedCapacity > 4.0 ? 4.0 : unusedCapacity;
int parallelism = (int) Math.ceil(componentMetrics.getMetrics().size() * (1 + unusedCapacity));
LOG.info(String.format("Component's, %s, unused capacity is: %.3f. New parallelism: %d", compName, unusedCapacity, parallelism));
return parallelism;
}
Aggregations