use of com.twitter.heron.proto.tmaster.TopologyMaster.MetricResponse.TaskMetric in project incubator-heron by apache.
the class MetricsCacheMetricsProvider method parse.
@VisibleForTesting
@SuppressWarnings("unchecked")
Map<String, InstanceMetrics> parse(TopologyMaster.MetricResponse response, String component, String metric, Instant startTime) {
Map<String, InstanceMetrics> metricsData = new HashMap<>();
if (response == null || !response.getStatus().getStatus().equals(StatusCode.OK)) {
LOG.info(String.format("Query failure from MetricsCache for %s:%s ", component, metric));
return metricsData;
}
if (response.getMetricCount() == 0) {
LOG.info(String.format("Did not get any metrics from MetricsCache for %s:%s ", component, metric));
return metricsData;
}
// convert heron.protobuf.taskMetrics to dhalion.InstanceMetrics
for (TaskMetric tm : response.getMetricList()) {
String instanceId = tm.getInstanceId();
InstanceMetrics instanceMetrics = new InstanceMetrics(instanceId);
for (IndividualMetric im : tm.getMetricList()) {
String metricName = im.getName();
Map<Instant, Double> values = new HashMap<>();
// case 1
for (IntervalValue iv : im.getIntervalValuesList()) {
MetricInterval mi = iv.getInterval();
String value = iv.getValue();
values.put(Instant.ofEpochSecond(mi.getStart()), Double.parseDouble(value));
}
// case 2
if (im.hasValue()) {
values.put(startTime, Double.parseDouble(im.getValue()));
}
if (!values.isEmpty()) {
instanceMetrics.addMetric(metricName, values);
}
}
metricsData.put(instanceId, instanceMetrics);
}
return metricsData;
}
Aggregations