use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class TestTransformFunctions method testSquare.
@Test
public void testSquare() {
Function f = new SquareFunction();
List<SeriesOutput> series = new ArrayList<>();
SeriesOutput s = new SeriesOutput(Arrays.asList(new DataPoint(1L, 3), new DataPoint(1L, 4)));
series.add(s);
List<SeriesOutput> apply = f.apply(series);
assertEquals(2, apply.get(0).getDataPoints().size());
assertEquals(9, apply.get(0).getDataPoints().get(0).getLongValue());
assertEquals(16, apply.get(0).getDataPoints().get(1).getLongValue());
}
use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class GrafanaUtils method queryAndGetData.
public static void queryAndGetData(StorageEngine engine, String dbName, long startTs, long endTs, List<GrafanaOutput> output, TargetSeries targetSeriesEntry) throws IOException {
List<SeriesOutput> points;
try {
points = engine.queryDataPoints(dbName, targetSeriesEntry.getMeasurementName(), targetSeriesEntry.getFieldName(), startTs, endTs, targetSeriesEntry.getTagFilter(), null, targetSeriesEntry.getAggregationFunction());
} catch (ItemNotFoundException e) {
throw new NotFoundException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new BadRequestException(e.getMessage());
}
if (points != null) {
for (SeriesOutput entry : points) {
GrafanaOutput tar = new GrafanaOutput(entry.toString());
List<DataPoint> dps = entry.getDataPoints();
if (dps != null) {
for (DataPoint point : dps) {
if (!entry.isFp()) {
tar.getDatapoints().add(new Number[] { point.getLongValue(), point.getTimestamp() });
} else {
tar.getDatapoints().add(new Number[] { point.getValue(), point.getTimestamp() });
}
}
}
tar.sort();
output.add(tar);
}
}
}
use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class MultiSeriesFunction method apply.
@Override
public List<SeriesOutput> apply(List<SeriesOutput> t) {
List<SeriesOutput> output = new ArrayList<>();
if (t.size() == 0) {
return output;
}
SortedMap<Long, List<DataPoint>> bucketMap = new TreeMap<>();
boolean fp = t.get(0).isFp();
for (int i = 0; i < t.size(); i++) {
SeriesOutput ts = t.get(i);
for (DataPoint dataPoint : ts.getDataPoints()) {
long key = (dataPoint.getTimestamp() * timeBucketSeconds / 1000) / timeBucketSeconds;
List<DataPoint> list = bucketMap.get(key);
if (list == null) {
list = new ArrayList<>();
bucketMap.put(key, list);
}
list.add(dataPoint);
}
}
List<DataPoint> compute = compute(bucketMap, fp);
SeriesOutput series = new SeriesOutput(compute);
series.setFp(fp);
series.setMeasurementName(t.get(0).getMeasurementName());
series.setValueFieldName(t.get(0).getValueFieldName() + "-" + aggregator.getClass().getSimpleName());
series.setTags(Arrays.asList(Tag.newBuilder().setTagKey("multiseries").setTagValue("true").build()));
output.add(series);
return output;
}
use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class WindowedFunction method apply.
@Override
public SeriesOutput apply(SeriesOutput t) {
SeriesOutput output = new SeriesOutput(t.getMeasurementName(), t.getValueFieldName(), t.getTags());
output.setFp(t.isFp());
SortedMap<Long, List<DataPoint>> map = new TreeMap<>();
for (DataPoint dataPoint : t.getDataPoints()) {
try {
long bucket = (dataPoint.getTimestamp() / getTimeWindow()) * getTimeWindow();
List<DataPoint> list = map.get(bucket);
if (list == null) {
list = new ArrayList<>();
map.put(bucket, list);
}
list.add(dataPoint);
} catch (Exception e) {
System.err.println("Exception :" + getTimeWindow());
}
}
output.setDataPoints(apply(map, t.isFp()));
return output;
}
use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class QADataIntegrity method testCompactions.
@Test
public void testCompactions() throws Exception {
conf.put("compaction.delay", "1");
conf.put("compaction.frequency", "2");
conf.put("compaction.codec", "gorilla");
engine.configure(conf, bgTasks);
long ts = System.currentTimeMillis();
String measurementName = "cpu";
String dbName = "db1";
for (int i = 0; i < 100000; i++) {
for (int l = 0; l < 10; l++) {
Point dp = Point.newBuilder().setDbName(dbName).setMeasurementName(measurementName).addTags(Tag.newBuilder().setTagKey("host").setTagValue(String.valueOf(l)).build()).addFp(false).addValueFieldName("user").addValue(Double.doubleToLongBits(21.2 * i)).setTimestamp(ts + i * 1000).build();
engine.writeDataPointWithLock(dp, false);
}
}
Thread.sleep(4000);
// check fields
Set<String> fields = engine.getFieldsForMeasurement(dbName, measurementName);
assertEquals(2, fields.size());
assertTrue(fields.contains("user"));
// check tag keys
Set<String> tagKeys = engine.getTagKeysForMeasurement(dbName, measurementName);
assertEquals(1, tagKeys.size());
assertEquals("host", tagKeys.iterator().next());
// check tag filters
TagFilter filter = MiscUtils.buildSimpleFilter("host~.*");
Set<String> rowKeys = engine.getTagFilteredRowKeys(dbName, measurementName, filter);
assertEquals(10, rowKeys.size());
// check dataset
List<SeriesOutput> all = engine.queryDataPoints(dbName, measurementName, "user", ts - 1000 * 10, ts + 1000 * 100, filter);
assertEquals(10, all.size());
// Measurement m = engine.getMeasurementMap().get(dbName).get(measurementName);
}
Aggregations