use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.
the class TestWindowedFunctions method testIntegralFunction.
@Test
public void testIntegralFunction() throws Exception {
double[] values = { 1.1, 2.2, 3.3, 4.4 };
List<DataPoint> dps = new ArrayList<>();
long ts = 1486617103629L;
for (int i = 0; i < values.length; i++) {
double d = values[i];
ts = ts + (30_000);
dps.add(MiscUtils.buildDataPoint(ts, d));
}
ReducingWindowedAggregator rwa = new IntegralFunction();
rwa.init(new Object[] { 70, "smean" });
Series series = new Series();
series.setDataPoints(dps);
series.setFp(true);
List<DataPoint> result = rwa.apply(series).getDataPoints();
assertEquals(2, result.size());
assertEquals(1.1, result.get(0).getValue(), 0);
assertEquals(9.9, result.get(1).getValue(), 0);
}
use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.
the class TestGRPWriterServiceImpl method testPointWritesRejects.
@Test
public void testPointWritesRejects() throws Exception {
WriterServiceBlockingStub client = WriterServiceGrpc.newBlockingStub(channel);
long sts = 1497720452566L;
String dbName = "test3";
String measurementName = "cpu4";
List<Point> points = Arrays.asList(Point.newBuilder().setDbName(dbName).setFp(false).setMeasurementName(measurementName).addTags("host=1").setTimestamp(sts).setValue(1L).setValueFieldName("usage").build(), Point.newBuilder().setDbName(dbName).setFp(true).setMeasurementName(measurementName).addTags("host=1").setTimestamp(sts + 1).setValue(2L).setValueFieldName("usage").build());
try {
Ack response = client.writeBatchDataPoint(BatchData.newBuilder().setMessageId(sts).addAllPoints(points).build());
if (response.getResponseCode() == 200) {
fail("Exception must be thrown");
}
} catch (Exception e) {
}
// second data point should have been rejected
assertTrue(engine.checkIfExists(dbName));
assertTrue(engine.checkIfExists(dbName, measurementName));
assertEquals("host", engine.getTagKeysForMeasurement(dbName, measurementName).iterator().next());
List<Series> result = engine.queryDataPoints(dbName, measurementName, "usage", sts, sts + 1, null);
assertEquals(1, result.size());
assertEquals(1, result.iterator().next().getDataPoints().size());
assertEquals(1L, result.iterator().next().getDataPoints().iterator().next().getLongValue());
}
use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.
the class TestGRPWriterServiceImpl method testMultiDataPointWrites.
// @Test
public void testMultiDataPointWrites() throws Exception {
WriterServiceBlockingStub client = WriterServiceGrpc.newBlockingStub(channel);
long sts = 1497720452566L;
String dbName = "test2";
String measurementName = "cpu";
List<Point> points = Arrays.asList(Point.newBuilder().setDbName(dbName).setFp(false).setMeasurementName(measurementName).addTags("host=1").setTimestamp(sts).setValue(1L).setValueFieldName("usage").build(), Point.newBuilder().setDbName(dbName).setFp(false).setMeasurementName(measurementName).addTags("host=1").setTimestamp(sts + 1).setValue(2L).setValueFieldName("usage").build());
client.writeBatchDataPoint(BatchData.newBuilder().setMessageId(sts).addAllPoints(points).build());
assertTrue(engine.checkIfExists(dbName));
assertTrue(engine.checkIfExists(dbName, measurementName));
assertEquals("host=1", engine.getTagKeysForMeasurement(dbName, measurementName).iterator().next());
List<Series> result = engine.queryDataPoints(dbName, measurementName, "usage", sts, sts + 1, null);
assertEquals(1, result.size());
assertEquals(2, result.iterator().next().getDataPoints().size());
assertEquals(1L, result.iterator().next().getDataPoints().iterator().next().getLongValue());
}
use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.
the class GrafanaUtils method queryAndGetData.
public static void queryAndGetData(StorageEngine engine, String dbName, long startTs, long endTs, List<Target> output, TargetSeries targetSeriesEntry) throws IOException {
List<Series> 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 (Series entry : points) {
Target tar = new Target(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() });
}
}
}
output.add(tar);
tar.sort();
}
}
}
use of com.srotya.sidewinder.core.storage.Series in project sidewinder by srotya.
the class MultiSeriesFunction method apply.
@Override
public List<Series> apply(List<Series> t) {
List<Series> output = new ArrayList<>();
boolean fp = t.get(0).isFp();
List<List<DataPoint>> intermediate = new ArrayList<>();
int size = t.get(0).getDataPoints().size();
for (int i = 0; i < t.size(); i++) {
Series ts = t.get(i);
if (size != ts.getDataPoints().size()) {
throw new IllegalArgumentException("Non-uniform series length");
}
intermediate.add(ts.getDataPoints());
}
List<DataPoint> compute = compute(intermediate, fp);
Series series = new Series(compute);
series.setFp(fp);
series.setMeasurementName(t.get(0).getMeasurementName());
series.setValueFieldName(name());
series.setTags(Arrays.asList(new Tag("multiseries", "true")));
output.add(series);
return output;
}
Aggregations