@Test public void testRateCalculationOnMetricsWithEqualValues() throws Exception { Map<Long, Double> metricValues = new TreeMap<>(); metricValues.put(1454000000000L, 1.0); metricValues.put(1454000001000L, 6.0); metricValues.put(1454000002000L, 0.0); metricValues.put(1454000003000L, 3.0); metricValues.put(1454000004000L, 4.0); metricValues.put(1454000005000L, 7.0); Map<Long, Double> rates = HBaseTimelineMetricsService.updateValuesAsRate(new TreeMap<>(metricValues), false); Assert.assertTrue(rates.size() == 4); Assert.assertFalse(rates.containsKey(1454000000000L)); Assert.assertFalse(rates.containsKey(1454000002000L)); Assert.assertEquals(rates.get(1454000001000L), 5.0); Assert.assertEquals(rates.get(1454000003000L), 3.0); Assert.assertEquals(rates.get(1454000004000L), 1.0); Assert.assertEquals(rates.get(1454000005000L), 3.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();  }