Search in sources :

Example 1 with MetricInterval

use of org.apache.heron.proto.tmanager.TopologyManager.MetricInterval in project heron by twitter.

the class MetricsCacheMetricsProvider method parse.

@VisibleForTesting
@SuppressWarnings("unchecked")
Collection<Measurement> parse(TopologyManager.MetricResponse response, String component, String metric, Instant startTime) {
    Collection<Measurement> metricsData = new ArrayList();
    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();
        for (IndividualMetric im : tm.getMetricList()) {
            String metricName = im.getName();
            // case 1
            for (IntervalValue iv : im.getIntervalValuesList()) {
                MetricInterval mi = iv.getInterval();
                String value = iv.getValue();
                Measurement measurement = new Measurement(component, instanceId, metricName, Instant.ofEpochSecond(mi.getStart()), Double.parseDouble(value));
                metricsData.add(measurement);
            }
            // case 2
            if (im.hasValue()) {
                Measurement measurement = new Measurement(component, instanceId, metricName, startTime, Double.parseDouble(im.getValue()));
                metricsData.add(measurement);
            }
        }
    }
    return metricsData;
}
Also used : Measurement(com.microsoft.dhalion.core.Measurement) TaskMetric(org.apache.heron.proto.tmanager.TopologyManager.MetricResponse.TaskMetric) ArrayList(java.util.ArrayList) MetricInterval(org.apache.heron.proto.tmanager.TopologyManager.MetricInterval) IndividualMetric(org.apache.heron.proto.tmanager.TopologyManager.MetricResponse.IndividualMetric) IntervalValue(org.apache.heron.proto.tmanager.TopologyManager.MetricResponse.IndividualMetric.IntervalValue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Measurement (com.microsoft.dhalion.core.Measurement)1 ArrayList (java.util.ArrayList)1 MetricInterval (org.apache.heron.proto.tmanager.TopologyManager.MetricInterval)1 IndividualMetric (org.apache.heron.proto.tmanager.TopologyManager.MetricResponse.IndividualMetric)1 IntervalValue (org.apache.heron.proto.tmanager.TopologyManager.MetricResponse.IndividualMetric.IntervalValue)1 TaskMetric (org.apache.heron.proto.tmanager.TopologyManager.MetricResponse.TaskMetric)1