Search in sources :

Example 1 with Tag

use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.

the class Measurement method encodeTagsToString.

public default ByteString encodeTagsToString(List<Tag> tags) throws IOException {
    StringBuilder builder = new StringBuilder(tags.size() * 5);
    serializeTagForKey(builder, tags.get(0));
    for (int i = 1; i < tags.size(); i++) {
        Tag tag = tags.get(i);
        builder.append(TAG_SEPARATOR);
        serializeTagForKey(builder, tag);
    }
    String rowKey = builder.toString();
    return new ByteString(rowKey);
}
Also used : Tag(com.srotya.sidewinder.core.rpc.Tag) Point(com.srotya.sidewinder.core.rpc.Point)

Example 2 with Tag

use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.

the class MeasurementOpsApi method createSeries.

@Path("/series")
@PUT
@Consumes({ MediaType.APPLICATION_JSON })
public void createSeries(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, @PathParam(MEASUREMENT) String measurementName, String seriesConfig) {
    Gson gson = new Gson();
    JsonObject series = gson.fromJson(seriesConfig, JsonObject.class);
    List<Tag> tags = new ArrayList<>();
    for (JsonElement jsonElement : series.get("tags").getAsJsonArray()) {
        String tagStr = jsonElement.getAsString();
        String[] splits = tagStr.split(Measurement.TAG_KV_SEPARATOR);
        tags.add(Tag.newBuilder().setTagKey(splits[0]).setTagValue(splits[1]).build());
    }
    try {
        Measurement m = engine.getOrCreateMeasurement(dbName, measurementName);
        m.getOrCreateSeries(tags, false);
    } catch (IOException e) {
        throw new InternalServerErrorException(e);
    }
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Tag(com.srotya.sidewinder.core.rpc.Tag) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 3 with Tag

use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.

the class TestStorageEngine method testCompaction.

@Test
public void testCompaction() throws IOException, InterruptedException {
    conf.put("default.bucket.size", "409600");
    conf.put("use.query.pool", "false");
    conf.put("compaction.delay", "1");
    conf.put("compaction.frequency", "1");
    engine.configure(conf, bgTasks);
    final long curr = 1497720652566L;
    String dbName = "test";
    String measurementName = "cpu";
    String valueFieldName = "value";
    List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("host").setTagValue("123123").build());
    for (int i = 1; i <= 10000; i++) {
        engine.writeDataPointWithLock(MiscUtils.buildDataPoint(dbName, measurementName, Arrays.asList(valueFieldName), tags, curr + i * 1000, Arrays.asList(Double.doubleToLongBits(i * 1.1)), Arrays.asList(true)), false);
    }
    long ts = System.nanoTime();
    List<SeriesOutput> queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr - 1000, curr + 10000 * 1000 + 1, null, null);
    ts = System.nanoTime() - ts;
    System.out.println("Before compaction:" + ts / 1000 + "us");
    assertEquals(1, queryDataPoints.size());
    assertEquals(10000, queryDataPoints.iterator().next().getDataPoints().size());
    List<DataPoint> dataPoints = queryDataPoints.iterator().next().getDataPoints();
    for (int i = 1; i <= 10000; i++) {
        DataPoint dp = dataPoints.get(i - 1);
        assertEquals("Bad ts:" + i, curr + i * 1000, dp.getTimestamp());
        assertEquals(dp.getValue(), i * 1.1, 0.001);
    }
    Measurement m = engine.getOrCreateMeasurement(dbName, measurementName);
    Series series = m.getOrCreateSeries(tags, false);
    SortedMap<Integer, Map<String, Field>> bucketRawMap = series.getBucketMap();
    assertEquals(1, bucketRawMap.size());
    int size = (int) MiscUtils.bucketCounter(series);
    assertTrue(size > 2);
    Thread.sleep(4000);
    ts = System.nanoTime();
    queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr - 1, curr + 20000 * 1000 + 1, null, null);
    ts = System.nanoTime() - ts;
    System.out.println("After compaction:" + ts / 1000 + "us");
    bucketRawMap = series.getBucketMap();
    assertEquals(2, bucketRawMap.values().iterator().next().size());
    assertEquals(10000, queryDataPoints.iterator().next().getDataPoints().size());
    dataPoints = queryDataPoints.iterator().next().getDataPoints();
    for (int i = 1; i <= 10000; i++) {
        DataPoint dp = dataPoints.get(i - 1);
        assertEquals("Bad ts:" + i, curr + i * 1000, dp.getTimestamp());
        assertEquals(dp.getValue(), i * 1.1, 0.001);
    }
}
Also used : Point(com.srotya.sidewinder.core.rpc.Point) Tag(com.srotya.sidewinder.core.rpc.Tag) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with Tag

use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.

the class TestStorageEngine method testConfigureTimeBuckets.

@Test
public void testConfigureTimeBuckets() throws ItemNotFoundException, IOException {
    long ts = System.currentTimeMillis();
    conf.put(StorageEngine.DEFAULT_BUCKET_SIZE, String.valueOf(4096 * 10));
    List<Tag> tagd = Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("e").build());
    try {
        engine.configure(conf, bgTasks);
    } catch (IOException e) {
        fail("No IOException should be thrown");
    }
    try {
        for (int i = 0; i < 10; i++) {
            engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test", "ss", "value", tagd, ts + (i * 4096 * 1000), 2.2), false);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
    }
    List<SeriesOutput> queryDataPoints = engine.queryDataPoints("test", "ss", "value", ts, ts + (4096 * 100 * 1000) + 1, new SimpleTagFilter(FilterType.EQUALS, "t", "e"));
    assertTrue(queryDataPoints.size() >= 1);
}
Also used : SimpleTagFilter(com.srotya.sidewinder.core.filters.SimpleTagFilter) Tag(com.srotya.sidewinder.core.rpc.Tag) IOException(java.io.IOException) Point(com.srotya.sidewinder.core.rpc.Point) InvalidFilterException(com.srotya.sidewinder.core.utils.InvalidFilterException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with Tag

use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.

the class TestStorageEngine method testConfigure.

@Test
public void testConfigure() throws IOException {
    List<Tag> tagd = Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("e").build());
    try {
        engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test", "ss", "value", tagd, System.currentTimeMillis(), 2.2), false);
        fail("Engine not initialized, shouldn't be able to write a datapoint");
    } catch (Exception e) {
    }
    try {
        // FileUtils.forceDelete(new File("target/db2/"));
        MiscUtils.delete(new File("targer/db2/"));
        HashMap<String, String> map = new HashMap<>();
        map.put("index.dir", "target/db2/index");
        map.put("data.dir", "target/db2/data");
        map.put("default.series.retention.hours", "32");
        engine.configure(map, bgTasks);
    } catch (IOException e) {
        fail("No IOException should be thrown");
    }
    try {
        engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test", "ss", "value", tagd, System.currentTimeMillis(), 2.2), false);
        String md = new String(Files.readAllBytes(new File("target/db2/data/test/.md").toPath()), Charset.forName("utf8"));
        DBMetadata metadata = new Gson().fromJson(md, DBMetadata.class);
        assertEquals(32, metadata.getRetentionHours());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
    }
    engine.shutdown();
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson) Tag(com.srotya.sidewinder.core.rpc.Tag) IOException(java.io.IOException) File(java.io.File) InvalidFilterException(com.srotya.sidewinder.core.utils.InvalidFilterException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Tag (com.srotya.sidewinder.core.rpc.Tag)36 Test (org.junit.Test)32 Point (com.srotya.sidewinder.core.rpc.Point)22 IOException (java.io.IOException)19 HashMap (java.util.HashMap)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 InvalidFilterException (com.srotya.sidewinder.core.utils.InvalidFilterException)7 ExecutorService (java.util.concurrent.ExecutorService)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)6 BackgrounThreadFactory (com.srotya.sidewinder.core.utils.BackgrounThreadFactory)5 Gson (com.google.gson.Gson)4 SimpleTagFilter (com.srotya.sidewinder.core.filters.SimpleTagFilter)4 TagFilter (com.srotya.sidewinder.core.filters.TagFilter)4 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)4 SeriesOutput (com.srotya.sidewinder.core.storage.SeriesOutput)4 HashSet (java.util.HashSet)4 List (java.util.List)4 JsonElement (com.google.gson.JsonElement)3 JsonObject (com.google.gson.JsonObject)3