private void updateExistingMetricValues(TimelineMetrics existingMetrics,
      Long requestedStartTime, Long requestedEndTime, boolean removeAll) {
    for (TimelineMetric existingMetric : existingMetrics.getMetrics()) {
      if (removeAll) {
        existingMetric.setMetricValues(new TreeMap<>());
      } else {
        TreeMap<Long, Double> existingMetricValues = existingMetric.getMetricValues();
        LOG.trace("Existing metric: {} # {}", existingMetric.getMetricName(), existingMetricValues.size());

        // Retain only the values that are within the [requestStartTime, requestedEndTime] window
        existingMetricValues.headMap(requestedStartTime,false).clear();
        existingMetricValues.tailMap(requestedEndTime, false).clear();
      }
    }
  }
Update cache with new timeseries data
ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/cache/TimelineMetricCacheEntryFactory.java