Search in sources :

Example 26 with Series

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);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ReducingWindowedAggregator(com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 27 with Series

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());
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) WriterServiceBlockingStub(com.srotya.sidewinder.core.rpc.WriterServiceGrpc.WriterServiceBlockingStub) Test(org.junit.Test)

Example 28 with Series

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());
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) WriterServiceBlockingStub(com.srotya.sidewinder.core.rpc.WriterServiceGrpc.WriterServiceBlockingStub)

Example 29 with Series

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();
        }
    }
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) IOException(java.io.IOException) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException)

Example 30 with Series

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;
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Tag(com.srotya.sidewinder.core.filters.Tag) DataPoint(com.srotya.sidewinder.core.storage.DataPoint)

Aggregations

Series (com.srotya.sidewinder.core.storage.Series)56 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)49 Test (org.junit.Test)47 ArrayList (java.util.ArrayList)37 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)21 IOException (java.io.IOException)18 LinkedHashMap (java.util.LinkedHashMap)16 HashMap (java.util.HashMap)15 Point (com.srotya.sidewinder.core.rpc.Point)13 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)13 File (java.io.File)13 ReducingWindowedAggregator (com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator)10 RejectException (com.srotya.sidewinder.core.storage.RejectException)10 StorageEngine (com.srotya.sidewinder.core.storage.StorageEngine)7 List (java.util.List)7 ByzantineWriter (com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter)6 Tag (com.srotya.sidewinder.core.filters.Tag)5 SimpleTagFilter (com.srotya.sidewinder.core.filters.SimpleTagFilter)4 Measurement (com.srotya.sidewinder.core.storage.Measurement)4 WriterServiceBlockingStub (com.srotya.sidewinder.core.rpc.WriterServiceGrpc.WriterServiceBlockingStub)3