Search in sources :

Example 21 with SeriesOutput

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

Example 22 with SeriesOutput

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

Example 23 with SeriesOutput

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

Example 24 with SeriesOutput

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

Example 25 with SeriesOutput

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);
}
Also used : TagFilter(com.srotya.sidewinder.core.filters.TagFilter) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) Test(org.junit.Test)

Aggregations

SeriesOutput (com.srotya.sidewinder.core.storage.SeriesOutput)40 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)35 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)31 WindowedAggregator (com.srotya.sidewinder.core.functions.list.WindowedAggregator)10 Function (com.srotya.sidewinder.core.functions.list.Function)7 IOException (java.io.IOException)6 TagFilter (com.srotya.sidewinder.core.filters.TagFilter)4 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)4 Tag (com.srotya.sidewinder.core.rpc.Tag)3 WriterServiceBlockingStub (com.srotya.sidewinder.core.rpc.WriterServiceGrpc.WriterServiceBlockingStub)3 BadRequestException (javax.ws.rs.BadRequestException)3 NotFoundException (javax.ws.rs.NotFoundException)3 WindowedMean (com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean)2 ChainFunction (com.srotya.sidewinder.core.functions.list.ChainFunction)2 ReduceFunction (com.srotya.sidewinder.core.functions.list.ReduceFunction)2 Point (com.srotya.sidewinder.core.rpc.Point)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 List (java.util.List)2