Skip to content

Commit

Permalink
Merge 056c704 into 7937a0b
Browse files Browse the repository at this point in the history
  • Loading branch information
tilogaat committed Feb 19, 2015
2 parents 7937a0b + 056c704 commit 467a6fc
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class PreaggregatedMetricsIntegrationTest extends IntegrationTestBase {
public void createFixtures() throws Exception {
simple = new TimerRollup()
.withSampleCount(1)
.withSum(100L)
.withSum(100d)
.withCountPS(101d)
.withAverage(102L)
.withVariance(103d)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void setUp() throws Exception {
.withMaxValue(100 - i)
.withMinValue(100 - i - i)
.withAverage(i / 2)
.withCountPS((double)i).withSum(2 * i)
.withCountPS((double)i).withSum(Double.valueOf(2 * i))
.withVariance((double) i / 2d);
metric = new PreaggregatedMetric(time, timerLocator, ttl, timer);
preaggregatedMetrics.add(metric);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private static int sizeOf(Object o, byte type) throws IOException {
case Type.B_TIMER:
sz += 1; // version
TimerRollup rollup = (TimerRollup)o;
sz += CodedOutputStream.computeRawVarint64Size(rollup.getSum());
sz += CodedOutputStream.computeDoubleSizeNoTag(rollup.getSum());
sz += CodedOutputStream.computeRawVarint64Size(rollup.getCount());
sz += CodedOutputStream.computeDoubleSizeNoTag(rollup.getRate());
sz += CodedOutputStream.computeRawVarint32Size(rollup.getSampleCount());
Expand Down Expand Up @@ -339,7 +339,7 @@ private static void serializeTimer(TimerRollup rollup, byte[] buf) throws IOExce
out.writeRawByte(Constants.VERSION_1_TIMER);

// sum, count, countps, avg, max, min, var
out.writeRawVarint64(rollup.getSum());
out.writeDoubleNoTag(rollup.getSum());
out.writeRawVarint64(rollup.getCount());
out.writeDoubleNoTag(rollup.getRate());
out.writeRawVarint32(rollup.getSampleCount());
Expand All @@ -359,7 +359,7 @@ private static void serializeTimer(TimerRollup rollup, byte[] buf) throws IOExce

private static TimerRollup deserializeV1Timer(CodedInputStream in) throws IOException {
// note: type and version have already been read.
final long sum = in.readRawVarint64();
final double sum = in.readDouble();
final long count = in.readRawVarint64();
final double countPs = in.readDouble();
final int sampleCount = in.readRawVarint32();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


public class TimerRollup implements Rollup, IBasicRollup {
private long sum = 0;
private double sum = 0;
private long count = 0;
private double rate = 0;

Expand All @@ -34,7 +34,7 @@ public TimerRollup() {
super();
}

public TimerRollup withSum(long sum) {
public TimerRollup withSum(double sum) {
this.sum = sum;
return this;
}
Expand Down Expand Up @@ -153,7 +153,7 @@ else if (number instanceof Integer)

// per second rate.
public double getRate() { return rate; }
public long getSum() { return sum; }
public double getSum() { return sum; }
public long getCount() { return count; };
public int getSampleCount() { return sampleCount; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testSetSerialization() throws IOException {

@Test
public void testTimerSerialization() throws IOException {
String timerValue = "{\"type\":\"timer\",\"average\":214,\"count\":1,\"max\":214,\"min\":214,\"percentiles\":{\"98\":214,\"99\":214,\"75\":214,\"999\":214,\"50\":214},\"rate\":0.06666666666666667,\"sampleCount\":1,\"sum\":214,\"variance\":0.0}";
String timerValue = "{\"type\":\"timer\",\"average\":214,\"count\":1,\"max\":214,\"min\":214,\"percentiles\":{\"98\":214,\"99\":214,\"75\":214,\"999\":214,\"50\":214},\"rate\":0.06666666666666667,\"sampleCount\":1,\"sum\":214.0,\"variance\":0.0}";

TimerRollup timerDeserialized = mapper.readValue(timerValue, TimerRollup.class);
String timerSerialized = mapper.writeValueAsString(timerDeserialized);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class TimerSerializationTest {
public void testV1RoundTrip() throws IOException {
// build up a Timer
TimerRollup r0 = new TimerRollup()
.withSum(42)
.withSum(Double.valueOf(42))
.withCountPS(23.32d)
.withAverage(56)
.withVariance(853.3245d)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testTimerRollupSerialization() {
rollup.withMaxValue(20);
rollup.withMinValue(5);
rollup.withVariance(12);
rollup.withSum(10);
rollup.withSum(Double.valueOf(10));
rollup.withCountPS(30);
//Get the JSON object node from Rollup
ObjectNode resultNode = RollupSerializationHelper.rollupToJson(rollup);
Expand All @@ -61,7 +61,7 @@ public void testTimerRollupSerialization() {
Assert.assertEquals(resultNode.get("mean").asLong(), rollup.getAverage().toLong());
Assert.assertEquals(resultNode.get("var").asDouble(), rollup.getVariance().toDouble());
Assert.assertEquals(resultNode.get("count").asLong(), rollup.getCount());
Assert.assertEquals(resultNode.get("sum").asLong(), rollup.getSum());
Assert.assertEquals(resultNode.get("sum").asDouble(), rollup.getSum());
Assert.assertEquals(resultNode.get("rate").asDouble(), rollup.getRate());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ private static void assertRollupsAreClose(IBasicRollup expected, IBasicRollup ac
@Test
public void testConstantTimerRollup() throws IOException {
// 40 samples, one per milli, each sample increments by one. Now divide those into four parts.
TimerRollup tr0 = new TimerRollup().withSum(45).withCountPS(4.5d).withAverage(4).withVariance(8.25d).withMinValue(0).withMaxValue(9).withCount(10);
TimerRollup tr1 = new TimerRollup().withSum(145).withCountPS(4.5d).withAverage(14).withVariance(8.25d).withMinValue(10).withMaxValue(19).withCount(10);
TimerRollup tr2 = new TimerRollup().withSum(245).withCountPS(4.5d).withAverage(24).withVariance(8.25d).withMinValue(20).withMaxValue(29).withCount(10);
TimerRollup tr3 = new TimerRollup().withSum(345).withCountPS(4.5d).withAverage(34).withVariance(8.25d).withMinValue(30).withMaxValue(39).withCount(10);
TimerRollup tr0 = new TimerRollup().withSum(45d).withCountPS(4.5d).withAverage(4).withVariance(8.25d).withMinValue(0).withMaxValue(9).withCount(10);
TimerRollup tr1 = new TimerRollup().withSum(145d).withCountPS(4.5d).withAverage(14).withVariance(8.25d).withMinValue(10).withMaxValue(19).withCount(10);
TimerRollup tr2 = new TimerRollup().withSum(245d).withCountPS(4.5d).withAverage(24).withVariance(8.25d).withMinValue(20).withMaxValue(29).withCount(10);
TimerRollup tr3 = new TimerRollup().withSum(345d).withCountPS(4.5d).withAverage(34).withVariance(8.25d).withMinValue(30).withMaxValue(39).withCount(10);
BasicRollup br0 = BasicRollup.buildRollupFromRawSamples(TimerRollupTest.createPoints(0, 0, 10, 1, 1));
BasicRollup br1 = BasicRollup.buildRollupFromRawSamples(TimerRollupTest.createPoints(10, 10, 10, 1, 1));
BasicRollup br2 = BasicRollup.buildRollupFromRawSamples(TimerRollupTest.createPoints(20, 20, 10, 1, 1));
Expand Down Expand Up @@ -100,7 +100,7 @@ public void testVariableRateTimerRollup() throws IOException {
// count_ps for this will be 200 time units / 100 samples = 2.0
BasicRollup br0 = BasicRollup.buildRollupFromRawSamples(p0);
final TimerRollup tr0 = new TimerRollup()
.withSum(9900)
.withSum(9900.0d)
.withCountPS(2.0)
.withAverage(99)
.withVariance(3333.0d)
Expand All @@ -113,7 +113,7 @@ public void testVariableRateTimerRollup() throws IOException {
// count_ps for this will be 200 time units / 200 samples = 1.0
BasicRollup br1 = BasicRollup.buildRollupFromRawSamples(p1);
final TimerRollup tr1 = new TimerRollup()
.withSum(39900)
.withSum(39900.0d)
.withCountPS(1.0)
.withAverage(399)
.withVariance(13333.0d)
Expand Down Expand Up @@ -169,8 +169,8 @@ public void testMax() {

@Test
public void testPercentiles() throws IOException {
final TimerRollup tr0 = new TimerRollup().withSum(0).withCountPS(0).withAverage(0).withVariance(0).withMinValue(0).withMaxValue(0).withCount(0);
final TimerRollup tr1 = new TimerRollup().withSum(0).withCountPS(0).withAverage(0).withVariance(0).withMinValue(0).withMaxValue(0).withCount(0);
final TimerRollup tr0 = new TimerRollup().withSum(0d).withCountPS(0).withAverage(0).withVariance(0).withMinValue(0).withMaxValue(0).withCount(0);
final TimerRollup tr1 = new TimerRollup().withSum(0d).withCountPS(0).withAverage(0).withVariance(0).withMinValue(0).withMaxValue(0).withCount(0);

// populate percentiles (these are nonsensical)
tr0.setPercentile("75", 0.1d);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ACrZAlK4HoXrUTdAAABsOANs2wcCbAIBbmq8dJOYqopAAgNmb29uw/UoXI8qh0ADYmFybmFUUiegiaA/
AAAAAAAAAEVA2QJSuB6F61E3QAAAbDgDbNsHAmwCAW5qvHSTmKqKQAIDZm9vbsP1KFyPKodAA2Jhcm5hVFInoImgPw==
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static Collection<PreaggregatedMetric> remarshalTimers(Bundle bundle, St
.withMaxValue(t.getMax())
.withMinValue(t.getMin())
.withCountPS(t.getRate().doubleValue())
.withSum(t.getSum().longValue())
.withSum(t.getSum().doubleValue())
.withVariance(Math.pow(t.getStd().doubleValue(), 2d));

// percentiles.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static Collection<PreaggregatedMetric> convertTimers(String tenant, long
.withMaxValue(resolveNumber(timer.getMax() == null ? 0.0d : timer.getMax()))
.withMinValue(resolveNumber(timer.getMin() == null ? 0.0d : timer.getMin()))
.withCountPS(timer.getRate() == null ? 0.0d : timer.getRate().doubleValue())
.withSum(timer.getSum() == null ? 0L : timer.getSum().longValue()) // I wonder now if assuming sum instanceof Long is wrong.
.withSum(timer.getSum() == null ? 0L : timer.getSum().doubleValue())
.withVariance(Math.pow(timer.getStd() == null ? 0.0d : timer.getStd().doubleValue(), 2d));
for (Map.Entry<String, Bundle.Percentile> entry : timer.getPercentiles().entrySet()) {
// throw away max and sum.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static Points<TimerRollup> generateFakeTimerRollups() {
.withCountPS(i*0.1d)
.withMaxValue(i)
.withMinValue(i)
.withSum(i+i)
.withSum(Double.valueOf(i+i))
.withVariance(i);
rollup.setPercentile("50", i);
rollup.setPercentile("99", i * 2 + 1);
Expand Down
2 changes: 1 addition & 1 deletion blueflood-http/src/test/resources/sample_bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"rate":4.933333333333334,
"min":1,
"max":491,
"sum":18082,
"sum":18082.35135135135135,
"avg":244.35135135135135,
"median":244,
"std":142.11647606257384,
Expand Down

0 comments on commit 467a6fc

Please sign in to comment.