Search in sources :

Example 1 with MetricInterval

use of com.twitter.heron.proto.tmaster.TopologyMaster.MetricInterval 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;
}
Also used : InstanceMetrics(com.microsoft.dhalion.metrics.InstanceMetrics) HashMap(java.util.HashMap) TaskMetric(com.twitter.heron.proto.tmaster.TopologyMaster.MetricResponse.TaskMetric) Instant(java.time.Instant) MetricInterval(com.twitter.heron.proto.tmaster.TopologyMaster.MetricInterval) IndividualMetric(com.twitter.heron.proto.tmaster.TopologyMaster.MetricResponse.IndividualMetric) IntervalValue(com.twitter.heron.proto.tmaster.TopologyMaster.MetricResponse.IndividualMetric.IntervalValue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 InstanceMetrics (com.microsoft.dhalion.metrics.InstanceMetrics)1 MetricInterval (com.twitter.heron.proto.tmaster.TopologyMaster.MetricInterval)1 IndividualMetric (com.twitter.heron.proto.tmaster.TopologyMaster.MetricResponse.IndividualMetric)1 IntervalValue (com.twitter.heron.proto.tmaster.TopologyMaster.MetricResponse.IndividualMetric.IntervalValue)1 TaskMetric (com.twitter.heron.proto.tmaster.TopologyMaster.MetricResponse.TaskMetric)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1