public void applyPaddingStrategy(TimelineMetric metric, TemporalInfo temporalInfo) {
    if (strategy.equals(PADDING_STRATEGY.NONE) || temporalInfo == null) {
      return;
    }

    TreeMap<Long, Double> values = metric.getMetricValues();

    if (values==null || values.isEmpty()) {
      return;
    }

    long intervalStartTime = longToMillis(temporalInfo.getStartTime());
    long intervalEndTime = longToMillis(temporalInfo.getEndTime());
    long dataStartTime = longToMillis(values.firstKey());
    long dataEndTime = longToMillis(values.lastKey());

    long dataInterval = getTimelineMetricInterval(values, intervalStartTime, intervalEndTime);

    if (dataInterval == -1 || dataInterval < MINIMUM_STEP_INTERVAL) {
      dataInterval = temporalInfo.getStep() != null ? temporalInfo.getStep() : -1;
    }
    // Unable to determine what interval to use for padding
    if (dataInterval == -1) {
      return;
    }

    Double paddingValue = 0.0d;

    if (strategy.equals(PADDING_STRATEGY.NULLS)) {
      paddingValue = null;
    }
    // Pad before data interval
    for (long counter = intervalStartTime; counter < dataStartTime; counter += dataInterval) {
      // Until counter approaches or goes past dataStartTime : pad
      values.put(counter, paddingValue);
    }
    // Pad after data interval
    for (long counter = dataEndTime + dataInterval; counter <= intervalEndTime; counter += dataInterval) {
      values.put(counter, paddingValue);
    }
    // Put back new + old values
    metric.setMetricValues(values);
  }
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