@Test public void testDiffCalculation() throws Exception { Map<Long, Double> metricValues = new TreeMap<>(); metricValues.put(1454016368371L, 1011.25); metricValues.put(1454016428371L, 1010.25); metricValues.put(1454016488371L, 1012.25); metricValues.put(1454016548371L, 1015.25); metricValues.put(1454016608371L, 1020.25); Map<Long, Double> rates = HBaseTimelineMetricsService.updateValuesAsRate(new TreeMap<>(metricValues), true); Assert.assertTrue(rates.size() == 3); Assert.assertTrue(rates.containsValue(2.0)); Assert.assertTrue(rates.containsValue(3.0)); Assert.assertTrue(rates.containsValue(5.0)); }
static Map<Long, Double> updateValuesAsRate(Map<Long, Double> metricValues, boolean isDiff) { Long prevTime = null; Double prevVal = null; long step; Double diff; for (Iterator<Map.Entry<Long, Double>> it = metricValues.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Long, Double> timeValueEntry = it.next(); Long currTime = timeValueEntry.getKey(); Double currVal = timeValueEntry.getValue(); if (prevTime != null) { step = currTime - prevTime; diff = currVal - prevVal; if (diff < 0) { it.remove(); } else { Double rate = isDiff ? diff : (diff / TimeUnit.MILLISECONDS.toSeconds(step)); timeValueEntry.setValue(rate); } } else { it.remove(); } prevTime = currTime; prevVal = currVal; } return metricValues; }
HBaseTimelineMetricsService extends AbstractService implements TimelineMetricStore { static Map<Long, Double> updateValuesAsRate(Map<Long, Double> metricValues, boolean isDiff) { Long prevTime = null; Double prevVal = null; long step; Double diff; for (Iterator<Map.Entry<Long, Double>> it = metricValues.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Long, Double> timeValueEntry = it.next(); Long currTime = timeValueEntry.getKey(); Double currVal = timeValueEntry.getValue(); if (prevTime != null) { step = currTime - prevTime; diff = currVal - prevVal; if (diff < 0) { it.remove(); } else { Double rate = isDiff ? diff : (diff / TimeUnit.MILLISECONDS.toSeconds(step)); timeValueEntry.setValue(rate); } } else { it.remove(); } prevTime = currTime; prevVal = currVal; } return metricValues; } }
HBaseTimelineMetricsService extends AbstractService implements TimelineMetricStore { static Map<Long, Double> updateValuesAsRate(Map<Long, Double> metricValues, boolean isDiff) { Long prevTime = null; Double prevVal = null; long step; Double diff; for (Iterator<Map.Entry<Long, Double>> it = metricValues.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Long, Double> timeValueEntry = it.next(); Long currTime = timeValueEntry.getKey(); Double currVal = timeValueEntry.getValue(); if (prevTime != null) { step = currTime - prevTime; diff = currVal - prevVal; if (diff < 0) { it.remove(); } else { Double rate = isDiff ? diff : (diff / TimeUnit.MILLISECONDS.toSeconds(step)); timeValueEntry.setValue(rate); } } else { it.remove(); } prevTime = currTime; prevVal = currVal; } return metricValues; } HBaseTimelineMetricsService(TimelineMetricConfiguration configuration); }
HBaseTimelineMetricsService extends AbstractService implements TimelineMetricStore { static Map<Long, Double> updateValuesAsRate(Map<Long, Double> metricValues, boolean isDiff) { Long prevTime = null; Double prevVal = null; long step; Double diff; for (Iterator<Map.Entry<Long, Double>> it = metricValues.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Long, Double> timeValueEntry = it.next(); Long currTime = timeValueEntry.getKey(); Double currVal = timeValueEntry.getValue(); if (prevTime != null) { step = currTime - prevTime; diff = currVal - prevVal; if (diff < 0) { it.remove(); } else { Double rate = isDiff ? diff : (diff / TimeUnit.MILLISECONDS.toSeconds(step)); timeValueEntry.setValue(rate); } } else { it.remove(); } prevTime = currTime; prevVal = currVal; } return metricValues; } HBaseTimelineMetricsService(TimelineMetricConfiguration configuration); @Override TimelineMetrics getTimelineMetrics(List<String> metricNames,
                                            List<String> hostnames, String applicationId, String instanceId,
                                            Long startTime, Long endTime, Precision precision, Integer limit,
                                            boolean groupedByHosts, TopNConfig topNConfig, String seriesAggregateFunction); TimelinePutResponse putMetricsSkipCache(TimelineMetrics metrics); @Override TimelinePutResponse putMetrics(TimelineMetrics metrics); @Override TimelinePutResponse putContainerMetrics(List<ContainerMetric> metrics); @Override Map<String, List<TimelineMetricMetadata>> getTimelineMetricMetadata(String appId, String metricPattern,
                                                                             boolean includeBlacklistedMetrics); @Override byte[] getUuid(String metricName, String appId, String instanceId, String hostname); @Override Map<String, Set<String>> getHostAppsMetadata(); @Override TimelinePutResponse putHostAggregatedMetrics(AggregationResult aggregationResult); @Override Map<String, Map<String, Set<String>>> getInstanceHostsMetadata(String instanceId, String appId); @Override List<String> getLiveInstances(); @Override TimelineMetricServiceSummary getTimelineMetricServiceSummary(); }
HBaseTimelineMetricsService extends AbstractService implements TimelineMetricStore { static Map<Long, Double> updateValuesAsRate(Map<Long, Double> metricValues, boolean isDiff) { Long prevTime = null; Double prevVal = null; long step; Double diff; for (Iterator<Map.Entry<Long, Double>> it = metricValues.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Long, Double> timeValueEntry = it.next(); Long currTime = timeValueEntry.getKey(); Double currVal = timeValueEntry.getValue(); if (prevTime != null) { step = currTime - prevTime; diff = currVal - prevVal; if (diff < 0) { it.remove(); } else { Double rate = isDiff ? diff : (diff / TimeUnit.MILLISECONDS.toSeconds(step)); timeValueEntry.setValue(rate); } } else { it.remove(); } prevTime = currTime; prevVal = currVal; } return metricValues; } HBaseTimelineMetricsService(TimelineMetricConfiguration configuration); @Override TimelineMetrics getTimelineMetrics(List<String> metricNames,
                                            List<String> hostnames, String applicationId, String instanceId,
                                            Long startTime, Long endTime, Precision precision, Integer limit,
                                            boolean groupedByHosts, TopNConfig topNConfig, String seriesAggregateFunction); TimelinePutResponse putMetricsSkipCache(TimelineMetrics metrics); @Override TimelinePutResponse putMetrics(TimelineMetrics metrics); @Override TimelinePutResponse putContainerMetrics(List<ContainerMetric> metrics); @Override Map<String, List<TimelineMetricMetadata>> getTimelineMetricMetadata(String appId, String metricPattern,
                                                                             boolean includeBlacklistedMetrics); @Override byte[] getUuid(String metricName, String appId, String instanceId, String hostname); @Override Map<String, Set<String>> getHostAppsMetadata(); @Override TimelinePutResponse putHostAggregatedMetrics(AggregationResult aggregationResult); @Override Map<String, Map<String, Set<String>>> getInstanceHostsMetadata(String instanceId, String appId); @Override List<String> getLiveInstances(); @Override TimelineMetricServiceSummary getTimelineMetricServiceSummary();  }