private long getTimelineMetricInterval(TreeMap<Long, Double> values, long startTime, long endTime) {

    Precision precision = Precision.getPrecision(startTime, endTime);
    long interval;

    if (precision.equals(Precision.DAYS)) {
      interval = TimeUnit.DAYS.toMillis(1);
    } else if (precision.equals(Precision.HOURS)) {
      interval = TimeUnit.HOURS.toMillis(1);
    } else if (precision.equals(Precision.MINUTES)) {
      interval = TimeUnit.MINUTES.toMillis(1);
    } else {
      //Precision = SECONDS.
      //More than 1 point.
      if (values != null && values.size() > 1) {
        Iterator<Long> tsValuesIterator = values.descendingKeySet().iterator();
        long lastValue = tsValuesIterator.next();
        long secondToLastValue = tsValuesIterator.next();
        interval =  Math.abs(lastValue - secondToLastValue);
      } else {
        // Only 1 point
        interval = -1;
      }
    }
    return interval;
  }
Adds zero/null values towards the end of metrics sequence as well as the
beginning to support backward compatibility with Ganglia.
We use step if only a single datapoint is found.
It is assumed that @TimelineMetric.metricsValues are sorted in ascending
order and thee is no padding between the interval.

@param metric AMS @TimelineMetric
@param temporalInfo @TemporalInfo Requested interval
ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java