use of com.microsoft.dhalion.core.Measurement in project heron by twitter.
the class MetricsCacheMetricsProviderTest method parsesBackPressureMetric.
@Test
public void parsesBackPressureMetric() {
MetricsCacheMetricsProvider spyMetricsProvider = createMetricsProviderSpy();
String metric = "__time_spent_back_pressure_by_compid/container_1_split_1";
String comp = "__stmgr__";
TopologyManager.MetricResponse response = TopologyManager.MetricResponse.newBuilder().setStatus(Status.newBuilder().setStatus(StatusCode.OK)).addMetric(TaskMetric.newBuilder().setInstanceId("stmgr-1").addMetric(IndividualMetric.newBuilder().setName(metric).addIntervalValues(IntervalValue.newBuilder().setValue("601").setInterval(MetricInterval.newBuilder().setStart(0).setEnd(0))))).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(1, metrics.size());
MeasurementsTable table = MeasurementsTable.of(metrics);
assertEquals(1, table.component(comp).size());
assertEquals(601, table.instance("stmgr-1").type(metric).sum(), 0.01);
}
use of com.microsoft.dhalion.core.Measurement in project heron by twitter.
the class TrackerMetricsProviderTest method providesMultipleComponentMetricsFromTracker.
@Test
public void providesMultipleComponentMetricsFromTracker() {
TrackerMetricsProvider spyMetricsProvider = createMetricsProviderSpy();
String metric = "count";
String comp1 = "bolt-1";
String response1 = "{\"status\": \"success\", \"executiontime\": 0.002241849899291992, " + "\"message\": \"\", \"version\": \"ver\", \"result\": " + "{\"timeline\": {\"count\": " + "{\"container_1_bolt-1_2\": {\"1497481288\": \"104\"}" + "}}, " + "\"endtime\": 1497481388, \"component\": \"bolt\", \"starttime\": 1497481208}}";
doReturn(response1).when(spyMetricsProvider).getMetricsFromTracker(metric, comp1, Instant.ofEpochSecond(10), Duration.ofSeconds(60));
String comp2 = "bolt-2";
String response2 = "{\"status\": \"\", " + "\"executiontime\": 0.0026040077209472656, " + "\"message\": \"\", \"version\": \"\", " + "\"result\": {\"timeline\": {\"count\": " + "{\"container_1_bolt-2_1\": {\"1497481228\": \"12\", \"1497481348\": \"2\", " + "\"1497481168\": \"3\"}}}, " + "\"interval\": 60, \"component\": \"bolt-2\"}}";
doReturn(response2).when(spyMetricsProvider).getMetricsFromTracker(metric, comp2, Instant.ofEpochSecond(10), Duration.ofSeconds(60));
Collection<Measurement> metrics = spyMetricsProvider.getMeasurements(Instant.ofEpochSecond(10), Duration.ofSeconds(60), Collections.singletonList(metric), Arrays.asList(comp1, comp2));
assertEquals(4, metrics.size());
MeasurementsTable table = MeasurementsTable.of(metrics);
assertEquals(2, table.uniqueComponents().size());
assertEquals(1, table.component(comp1).size());
assertEquals(104, table.instance("container_1_bolt-1_2").sum(), 0.01);
assertEquals(3, table.component(comp2).size());
assertEquals(1, table.uniqueTypes().size());
assertEquals(3, table.type(metric).instance("container_1_bolt-2_1").size());
assertEquals(17, table.instance("container_1_bolt-2_1").sum(), 0.01);
}
use of com.microsoft.dhalion.core.Measurement in project heron by twitter.
the class TrackerMetricsProviderTest method parsesBackPressureMetric.
@Test
public void parsesBackPressureMetric() {
TrackerMetricsProvider spyMetricsProvider = createMetricsProviderSpy();
String metric = "__time_spent_back_pressure_by_compid/container_1_split_1";
String comp = "__stmgr__";
String response = "{\"status\": \"success\", " + "\"executiontime\": 0.30, \"message\": \"\", \"version\": \"v\", " + "\"result\": " + "{\"metrics\": {\"__time_spent_back_pressure_by_compid/container_1_split_1\": " + "{\"stmgr-1\": {\"00\" : \"601\"}}}, " + "\"interval\": 60, \"component\": \"__stmgr__\"}}";
doReturn(response).when(spyMetricsProvider).getMetricsFromTracker(metric, comp, Instant.ofEpochSecond(10), Duration.ofSeconds(60));
Collection<Measurement> metrics = spyMetricsProvider.getMeasurements(Instant.ofEpochSecond(10), Duration.ofSeconds(60), metric, comp);
assertEquals(1, metrics.size());
MeasurementsTable table = MeasurementsTable.of(metrics);
assertEquals(1, table.component(comp).size());
assertEquals(601, table.instance("stmgr-1").type(metric).sum(), 0.01);
}
use of com.microsoft.dhalion.core.Measurement in project heron by twitter.
the class TrackerMetricsProvider method parse.
@SuppressWarnings("unchecked")
private Collection<Measurement> parse(String response, String component, String metric) {
Collection<Measurement> metricsData = new ArrayList();
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);
for (String timeStamp : tmpValues.keySet()) {
Measurement measurement = new Measurement(component, instanceName, metric, Instant.ofEpochSecond(Long.parseLong(timeStamp)), Double.parseDouble(tmpValues.get(timeStamp)));
metricsData.add(measurement);
}
}
return metricsData;
}
use of com.microsoft.dhalion.core.Measurement in project heron by twitter.
the class WaitQueueSkewDetectorTest method testConfigAndFilter.
@Test
public void testConfigAndFilter() {
HealthPolicyConfig config = mock(HealthPolicyConfig.class);
when(config.getConfig(CONF_SKEW_RATIO, 20.0)).thenReturn(15.0);
Measurement measurement1 = new Measurement("bolt", "i1", METRIC_WAIT_Q_SIZE.text(), Instant.ofEpochSecond(1497892222), 1501);
Measurement measurement2 = new Measurement("bolt", "i2", METRIC_WAIT_Q_SIZE.text(), Instant.ofEpochSecond(1497892222), 100.0);
Collection<Measurement> metrics = new ArrayList<>();
metrics.add(measurement1);
metrics.add(measurement2);
WaitQueueSkewDetector detector = new WaitQueueSkewDetector(config);
PoliciesExecutor.ExecutionContext context = mock(PoliciesExecutor.ExecutionContext.class);
when(context.checkpoint()).thenReturn(Instant.now());
detector.initialize(context);
Collection<Symptom> symptoms = detector.detect(metrics);
assertEquals(3, symptoms.size());
SymptomsTable symptomsTable = SymptomsTable.of(symptoms);
assertEquals(1, symptomsTable.type("POSITIVE " + BaseDetector.SymptomType.SYMPTOM_WAIT_Q_SIZE_SKEW).size());
assertEquals(1, symptomsTable.type("NEGATIVE " + BaseDetector.SymptomType.SYMPTOM_WAIT_Q_SIZE_SKEW).size());
assertEquals(1, symptomsTable.type("POSITIVE " + BaseDetector.SymptomType.SYMPTOM_WAIT_Q_SIZE_SKEW).assignment("i1").size());
assertEquals(1, symptomsTable.type("NEGATIVE " + BaseDetector.SymptomType.SYMPTOM_WAIT_Q_SIZE_SKEW).assignment("i2").size());
measurement1 = new Measurement("bolt", "i1", METRIC_WAIT_Q_SIZE.text(), Instant.ofEpochSecond(1497892222), 1500);
measurement2 = new Measurement("bolt", "i2", METRIC_WAIT_Q_SIZE.text(), Instant.ofEpochSecond(1497892222), 110.0);
metrics = new ArrayList<>();
metrics.add(measurement1);
metrics.add(measurement2);
detector = new WaitQueueSkewDetector(config);
detector.initialize(context);
symptoms = detector.detect(metrics);
assertEquals(0, symptoms.size());
}
Aggregations