Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

George/fix mplot queries #577

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void run() {

if (executionContext.wasSuccessful()) {
this.scheduleCtx.clearFromRunning(parentSlotKey);
log.info("Successful completion of rollups for (gran,slot,shard) {} in {}", new Object[] {parentSlotKey, System.currentTimeMillis() - waitStart});
} else {
log.error("Performing BasicRollups for {} failed", parentSlotKey);
this.scheduleCtx.pushBackToScheduled(parentSlotKey, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testMultiplotQuery() throws Exception {
" {\n" +
" \"numPoints\": 1,\n" +
" \"timestamp\": 1382400000,\n" +
" \"average\": 397\n" +
" \"latest\": 397\n" +
" }\n" +
" ],\n" +
" \"type\": \"number\"\n" +
Expand All @@ -63,7 +63,7 @@ public void testMultiplotQuery() throws Exception {
" {\n" +
" \"numPoints\": 1,\n" +
" \"timestamp\": 1382400000,\n" +
" \"average\": 56\n" +
" \"latest\": 56\n" +
" }\n" +
" ],\n" +
" \"type\": \"number\"\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public JSONObject transformRollupData(Map<Locator, MetricData> metricData, Set<M
final JSONObject globalJSON = new JSONObject();
final JSONArray metricsArray = new JSONArray();


for (Map.Entry<Locator, MetricData> one : metricData.entrySet()) {
final JSONObject singleMetricJSON = new JSONObject();
singleMetricJSON.put("metric", one.getKey().getMetricName());
singleMetricJSON.put("unit", one.getValue().getUnit() == null ? Util.UNKNOWN : one.getValue().getUnit());
singleMetricJSON.put("type", one.getValue().getType());
JSONArray values = transformDataToJSONArray(one.getValue(), filterStats);
Set<MetricStat> oneFilterStats = fixFilterStats(one.getValue(), filterStats);
JSONArray values = transformDataToJSONArray(one.getValue(), oneFilterStats);
singleMetricJSON.put("data", values);
metricsArray.add(singleMetricJSON);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ public static Points<BluefloodCounterRollup> generateFakeCounterRollupPoints() {
return points;
}

public static Points<BluefloodEnumRollup> generateFakeEnumRollupPoints() {
Points<BluefloodEnumRollup> points = new Points<BluefloodEnumRollup>();
long startTime = 1234567L;
for (int i = 0; i < 5; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused why we are generating fake enum rollup points. Is this method only being called in Test classes? If so, should we move it to some class in src/test/java ?

long timeNow = startTime + i*1000;
Points.Point<BluefloodEnumRollup> point = new Points.Point<BluefloodEnumRollup>(timeNow, new BluefloodEnumRollup().withEnumValue("enum_value_" + i));
points.add(point);
}
return points;
}

public static Points<BluefloodSetRollup> generateFakeSetRollupPoints() {
Points<BluefloodSetRollup> points = new Points<BluefloodSetRollup>();
long startTime = 1234567L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@

public class JSONBasicRollupsOutputSerializer implements BasicRollupsOutputSerializer<JSONObject> {
private static final Logger log = LoggerFactory.getLogger(JSONBasicRollupsOutputSerializer.class);

@Override
public JSONObject transformRollupData(MetricData metricData, Set<MetricStat> filterStats)
throws SerializationException {
final JSONObject globalJSON = new JSONObject();
final JSONObject metaObject = new JSONObject();


protected Set<MetricStat> fixFilterStats(MetricData metricData, Set<MetricStat> filterStats) {
// if no stats were entered, figure out what type we are dealing with and select out default stats.
if (metricData.getData().getPoints().size() > 0 && filterStats == PlotRequestParser.DEFAULT_STATS) {
Class dataClass = metricData.getData().getDataClass();
Expand All @@ -56,6 +51,16 @@ else if (dataClass.equals(BluefloodEnumRollup.class))
// else, I got nothing.
}

return filterStats;
}

@Override
public JSONObject transformRollupData(MetricData metricData, Set<MetricStat> filterStats)
throws SerializationException {
final JSONObject globalJSON = new JSONObject();
final JSONObject metaObject = new JSONObject();
filterStats = fixFilterStats(metricData, filterStats);

final JSONArray valuesArray = transformDataToJSONArray(metricData, filterStats);

metaObject.put("count", valuesArray.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.rackspacecloud.blueflood.outputs.serializers;

import com.rackspacecloud.blueflood.outputs.formats.MetricData;
import com.rackspacecloud.blueflood.outputs.utils.PlotRequestParser;
import com.rackspacecloud.blueflood.types.Locator;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
Expand Down Expand Up @@ -65,4 +66,32 @@ public void testBatchedMetricsSerialization() throws Exception {
Assert.assertTrue(data != null);
}
}

@Test
public void testBatchedEnumMetricsSerialization() throws Exception {
final BatchedMetricsJSONOutputSerializer serializer = new BatchedMetricsJSONOutputSerializer();

final Map<Locator, MetricData> metrics = new HashMap<Locator, MetricData>();
for (int i = 0; i < 2; i++) {
final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeEnumRollupPoints(), "unknown",
MetricData.Type.ENUM);

metrics.put(Locator.createLocatorFromPathComponents(tenantId, String.valueOf(i)), metricData);
}

JSONObject jsonMetrics = serializer.transformRollupData(metrics, PlotRequestParser.DEFAULT_STATS);
Assert.assertTrue(jsonMetrics.get("metrics") != null);
JSONArray jsonMetricsArray = (JSONArray) jsonMetrics.get("metrics");

Iterator<JSONObject> metricsObjects = jsonMetricsArray.iterator();
Assert.assertTrue(metricsObjects.hasNext());

while (metricsObjects.hasNext()) {
JSONObject singleMetricObject = metricsObjects.next();
Assert.assertTrue(singleMetricObject.get("unit").equals("unknown"));
Assert.assertTrue(singleMetricObject.get("type").equals("enum"));
JSONArray data = (JSONArray) singleMetricObject.get("data");
Assert.assertTrue(data != null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.util.HashSet;
import java.util.Set;
import java.util.Map;

public class JSONBasicRollupOutputSerializerTest {
private final Set<MetricStat> filterStats;
Expand Down Expand Up @@ -161,6 +162,33 @@ public void testCounters() throws Exception {
}
}

@Test
public void testEnums() throws Exception {
final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer();
final MetricData metricData = new MetricData(
FakeMetricDataGenerator.generateFakeEnumRollupPoints(),
"unknown",
MetricData.Type.ENUM);
JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_STATS);
final JSONArray data = (JSONArray)metricDataJSON.get("values");

Assert.assertEquals(5, data.size());
for (int i = 0; i < data.size(); i++) {
final JSONObject dataJSON = (JSONObject)data.get(i);
final Map<String,Long> evJSON = (Map<String, Long>)dataJSON.get("enum_values");
Set<String> keys = evJSON.keySet();

Assert.assertEquals(1, keys.size());
for (String key : keys) {
Assert.assertEquals(key, "enum_value_" + i);
Assert.assertEquals((long)evJSON.get(key), 1);
}
Assert.assertNotNull(dataJSON.get("numPoints"));
Assert.assertEquals(1, dataJSON.get("numPoints"));
Assert.assertEquals(MetricData.Type.ENUM, dataJSON.get("type"));
}
}

@Test
public void testGauges() throws Exception {
final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer();
Expand Down