if (point.getData() instanceof BluefloodGaugeRollup) { BluefloodGaugeRollup rollup = (BluefloodGaugeRollup)point.getData(); numPoints += rollup.getCount(); filterStatsObject = getFilteredStatsForRollup(rollup, filterStats); } else if (point.getData() instanceof BasicRollup) { numPoints = ((BasicRollup) point.getData()).getCount(); filterStatsObject = getFilteredStatsForRollup((BasicRollup) point.getData(), filterStats); } else if (point.getData() instanceof SimpleNumber) { numPoints = 1; filterStatsObject = getFilteredStatsForFullRes(point.getData(), filterStats); } else if (point.getData() instanceof String) { numPoints = 1; filterStatsObject = getFilteredStatsForString((String) point.getData()); } else if (point.getData() instanceof Boolean) { numPoints = 1; filterStatsObject = getFilteredStatsForBoolean((Boolean) point.getData()); } else if (point.getData() instanceof BluefloodSetRollup) { BluefloodSetRollup rollup = (BluefloodSetRollup)point.getData(); numPoints += rollup.getCount(); filterStatsObject = getFilteredStatsForRollup(rollup, filterStats); } else if (point.getData() instanceof BluefloodTimerRollup) { BluefloodTimerRollup rollup = (BluefloodTimerRollup)point.getData(); numPoints += rollup.getCount(); filterStatsObject = getFilteredStatsForRollup(rollup, filterStats); } else if (point.getData() instanceof BluefloodCounterRollup) { BluefloodCounterRollup rollup = (BluefloodCounterRollup)point.getData(); numPoints += rollup.getCount().longValue(); filterStatsObject = getFilteredStatsForRollup(rollup, filterStats);
final Points.Point point = (Points.Point) metricData.getData().getPoints().get(dataJSON.get("timestamp")); long numPoints = ((BasicRollup) point.getData()).getCount(); Assert.assertEquals(numPoints, dataJSON.get("numPoints")); Assert.assertNull(dataJSON.get("sum")); } else { Assert.assertEquals(((BasicRollup) point.getData()).getAverage(), dataJSON.get("average")); Assert.assertEquals(((BasicRollup) point.getData()).getMaxValue(), dataJSON.get("max")); Assert.assertEquals(((BasicRollup) point.getData()).getMinValue(), dataJSON.get("min")); Assert.assertEquals(((BasicRollup) point.getData()).getSum(), dataJSON.get("sum"));
@Test public void testTransformRollupDataAtFullRes() throws Exception { final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer(); final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeFullResPoints(), "unknown"); JSONObject metricDataJSON = serializer.transformRollupData(metricData, filterStats); final JSONArray data = (JSONArray) metricDataJSON.get("values"); // Assert that we have some data to test Assert.assertTrue(data.size() > 0); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject) data.get(i); final Points.Point<SimpleNumber> point = (Points.Point<SimpleNumber>) metricData.getData().getPoints().get(dataJSON.get("timestamp")); Assert.assertEquals(point.getData().getValue(), dataJSON.get("average")); Assert.assertEquals(point.getData().getValue(), dataJSON.get("min")); Assert.assertEquals(point.getData().getValue(), dataJSON.get("max")); // Assert that variance isn't present Assert.assertNull(dataJSON.get("variance")); // Assert numPoints isn't present Assert.assertNull(dataJSON.get("numPoints")); // Assert sum isn't present Assert.assertNull(dataJSON.get("sum")); } }
boolean hasAllZeroData(MetricData dataPoints) { boolean allZeroFlag = true; // Points should be of type BasicRollup. Will throw an exception if they are not. Map<Long, Points.Point<BasicRollup>> points = dataPoints.getData().getPoints(); for (Map.Entry<Long, Points.Point<BasicRollup>> entry : points.entrySet()) { BasicRollup basicRollup = entry.getValue().getData(); if((basicRollup.getMaxValue().isFloatingPoint() ? basicRollup.getMaxValue().toDouble() != 0.0 : basicRollup.getMaxValue().toLong() != 0) && (basicRollup.getMinValue().isFloatingPoint() ? basicRollup.getMinValue().toDouble() != 0.0 : basicRollup.getMinValue().toLong() != 0) && (basicRollup.getAverage().isFloatingPoint() ? basicRollup.getAverage().toDouble() != 0.0 : basicRollup.getAverage().toLong() != 0)) { allZeroFlag = false; break; } } return allZeroFlag; }