Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ static Map<Long, Double> updateValuesAsRate(Map<Long, Double> metricValues, bool
if (diff < 0) {
it.remove(); //Discard calculating rate when the metric counter has been reset.
} else {
Double rate = isDiff ? diff : (diff / TimeUnit.MILLISECONDS.toSeconds(step));
double seconds = step / 1000.0;
Double rate = isDiff ? diff : (diff / seconds);
timeValueEntry.setValue(rate);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,19 @@ public void testDiffCalculation() throws Exception {
Assert.assertTrue(rates.containsValue(3.0));
Assert.assertTrue(rates.containsValue(5.0));
}

@Test
public void testRateCalculationShouldNotReturnInfinite() {
Map<Long, Double> metricValues = new TreeMap<>();
metricValues.put(1686721209272L, 5538.0);
metricValues.put(1686721219241L, 1750.0);
metricValues.put(1686721219272L, 5538.0);

// Calculate rate
Map<Long, Double> rates = HBaseTimelineMetricsService.updateValuesAsRate(new TreeMap<>(metricValues), false);
for (Map.Entry<Long, Double> entry :
rates.entrySet()) {
Assert.assertNotSame("rate transformation should not return Infinity", "Infinity", Double.toString(entry.getValue()));
}
}
}