Search in sources :

Example 16 with Tag

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

the class TestGraphiteDecoder method testHandler.

@Test
public void testHandler() throws IOException {
    EmbeddedChannel ch = new EmbeddedChannel(new StringDecoder(), new GraphiteDecoder("test", engine, null));
    ch.writeInbound(Unpooled.copiedBuffer("app=1.server=1.s=jvm.heap.max 233123 1497720452", Charset.defaultCharset()));
    ch.readInbound();
    List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("app").setTagValue("1").build(), Tag.newBuilder().setTagKey("server").setTagValue("1").build(), Tag.newBuilder().setTagKey("s").setTagValue("jvm").build());
    verify(engine, times(1)).writeDataPointWithLock(MiscUtils.buildDataPoint("test", "heap", "max", tags, ((long) 1497720452) * 1000, 233123), false);
    ch.close();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) StringDecoder(io.netty.handler.codec.string.StringDecoder) Tag(com.srotya.sidewinder.core.rpc.Tag) Test(org.junit.Test)

Example 17 with Tag

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

the class TestMeasurement method testMeasurementRecovery.

@Test
public void testMeasurementRecovery() throws IOException {
    List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("1").build(), Tag.newBuilder().setTagKey("t").setTagValue("2").build());
    measurement.configure(conf, engine, 4096, DBNAME, "m1", indexDir, dataDir, metadata, bgTaskPool);
    long t = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
        measurement.addPointWithLocking(build("vf1", tags, t + i * 1000, i), false);
    }
    Series s = measurement.getOrCreateSeries(tags, false);
    List<DataPoint> dps = s.queryDataPoints(measurement, Arrays.asList("vf1"), t, t + 1000 * 100, null).get("vf1");
    assertEquals(100, dps.size());
    for (int i = 0; i < 100; i++) {
        DataPoint dp = dps.get(i);
        assertEquals(t + i * 1000, dp.getTimestamp());
        assertEquals(i, dp.getLongValue());
    }
    List<SeriesOutput> resultMap = new ArrayList<>();
    measurement.queryDataPoints("vf1", t, t + 1000 * 100, null, null, resultMap, null);
    assertEquals(1, resultMap.size());
    SeriesOutput next = resultMap.iterator().next();
    for (int i = 0; i < next.getDataPoints().size(); i++) {
        DataPoint dp = next.getDataPoints().get(i);
        assertEquals(t + i * 1000, dp.getTimestamp());
        assertEquals(i, dp.getLongValue());
    }
    ConcurrentMap<ByteString, FieldReaderIterator[]> readers = new ConcurrentHashMap<>();
    measurement.queryReaders(Arrays.asList("vf1"), null, false, t, t + 1000 * 100, null, readers);
    assertEquals(1, readers.size());
    for (Entry<ByteString, FieldReaderIterator[]> entry : readers.entrySet()) {
        assertEquals(100, entry.getValue()[0].getReaders().get(0).getCount());
        assertEquals(100, entry.getValue()[1].getReaders().get(0).getCount());
    }
    measurement.close();
}
Also used : ArrayList(java.util.ArrayList) Point(com.srotya.sidewinder.core.rpc.Point) Tag(com.srotya.sidewinder.core.rpc.Tag) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 18 with Tag

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

the class TestMeasurement method testDataPointsQuery.

@Test
public void testDataPointsQuery() throws Exception {
    final long ts = 1546334202515L;
    List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("test").setTagValue("1").build(), Tag.newBuilder().setTagKey("test").setTagValue("2").build());
    conf.put(DiskMalloc.CONF_MEASUREMENT_FILE_MAX, String.valueOf(2 * 1024 * 1024));
    measurement.configure(conf, null, 4096, DBNAME, "m1", indexDir, dataDir, metadata, bgTaskPool);
    int LIMIT = 1000;
    for (int i = 0; i < LIMIT; i++) {
        measurement.addPointWithLocking(Point.newBuilder().setDbName(DBNAME).setMeasurementName("m1").addAllTags(tags).setTimestamp(ts + i * 1000).addFp(false).addValue(1L).addValueFieldName("value1").addFp(false).addValue(1L).addValueFieldName("value2").build(), true);
    }
    List<SeriesOutput> resultMap = new ArrayList<>();
    measurement.queryDataPoints("value.*$", ts, ts + 1000 * LIMIT, null, null, resultMap, null);
    assertEquals(2, resultMap.size());
    for (SeriesOutput s : resultMap) {
        for (int i = 0; i < s.getDataPoints().size(); i++) {
            DataPoint dataPoint = s.getDataPoints().get(i);
            assertEquals("Bad timestamp:" + ts + " + " + i * 1000 + " iteration:" + i, ts + i * 1000, dataPoint.getTimestamp());
            assertEquals(1L, dataPoint.getLongValue());
        }
    }
    List<List<Tag>> tagsResult = measurement.getTagsForMeasurement();
    Collections.sort(tags, Measurement.TAG_COMPARATOR);
    for (List<Tag> list : tagsResult) {
        Set<Tag> hashSet = new HashSet<>(list);
        for (int i = 0; i < tags.size(); i++) {
            Tag tag = tags.get(i);
            assertTrue(hashSet.contains(tag));
        }
    }
    try {
        tagsResult = measurement.getTagsForMeasurement();
    } catch (IOException e) {
    }
    measurement.close();
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Point(com.srotya.sidewinder.core.rpc.Point) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.srotya.sidewinder.core.rpc.Tag) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with Tag

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

the class TestMeasurement method testTagEncodingPerformance.

@Test
public void testTagEncodingPerformance() throws IOException {
    measurement.configure(conf, engine, 4096, DBNAME, "m1", indexDir, dataDir, metadata, bgTaskPool);
    assertTrue(measurement.getTagIndex() != null);
    for (int i = 0; i < 1_000_000; i++) {
        List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("test").setTagValue(String.valueOf("asdasd" + i)).build(), Tag.newBuilder().setTagKey("test").setTagValue("2").build());
        measurement.encodeTagsToString(tags);
    }
}
Also used : Tag(com.srotya.sidewinder.core.rpc.Tag) Point(com.srotya.sidewinder.core.rpc.Point) Test(org.junit.Test)

Example 20 with Tag

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

the class TestMeasurement method testLinearizability.

@Test
public void testLinearizability() throws IOException, InterruptedException {
    String valueFieldName = "vf2";
    for (int p = 0; p < 100; p++) {
        MiscUtils.delete(new File("target/measurement-common"));
        final long t1 = 1497720452566L;
        measurement.configure(conf, engine, 4096, DBNAME, "m2", indexDir, dataDir, metadata, bgTaskPool);
        ExecutorService es = Executors.newFixedThreadPool(2, new BackgrounThreadFactory("tlinear"));
        final List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("1").build(), Tag.newBuilder().setTagKey("t").setTagValue("2").build());
        AtomicBoolean wait = new AtomicBoolean(false);
        for (int i = 0; i < 2; i++) {
            final int th = i;
            es.submit(() -> {
                while (!wait.get()) {
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                    }
                }
                long t = t1 + th * 3;
                for (int j = 0; j < 100; j++) {
                    try {
                        long timestamp = t + j * 1000;
                        measurement.addPointWithLocking(build(valueFieldName, tags, timestamp, j), false);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        es.shutdown();
        wait.set(true);
        es.awaitTermination(100, TimeUnit.SECONDS);
        Series s = measurement.getOrCreateSeries(tags, false);
        List<DataPoint> dps = s.queryDataPoints(measurement, Arrays.asList(valueFieldName), t1 - 120, t1 + 1000_000, null).get(valueFieldName);
        assertEquals(200, dps.size());
        measurement.close();
    }
}
Also used : BackgrounThreadFactory(com.srotya.sidewinder.core.utils.BackgrounThreadFactory) Point(com.srotya.sidewinder.core.rpc.Point) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Tag(com.srotya.sidewinder.core.rpc.Tag) File(java.io.File) 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