Search in sources :

Example 31 with Tag

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

the class TestStorageEngine method testConcurrentOperations.

@Test
public void testConcurrentOperations() throws Exception {
    engine.configure(conf, bgTasks);
    final long ts = System.currentTimeMillis();
    ExecutorService es = Executors.newFixedThreadPool(2, new BackgrounThreadFactory("wr1"));
    String measurementName = "mmm2";
    String valueFieldName = "v1";
    String dbName = "db9";
    List<Tag> tagd = Arrays.asList(Tag.newBuilder().setTagKey("h").setTagValue("1").build());
    for (int k = 0; k < 2; k++) {
        final int p = k;
        es.submit(() -> {
            long t = ts + p;
            for (int i = 0; i < 100; i++) {
                Point dp = MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tagd, t + i * 1000, i);
                try {
                    engine.writeDataPointWithLock(dp, false);
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            }
            System.err.println("Completed writes:" + 100 + " data points");
        });
    }
    es.shutdown();
    es.awaitTermination(100, TimeUnit.SECONDS);
    assertEquals(1, engine.getAllMeasurementsForDb(dbName).size());
    assertEquals(1, engine.getMeasurementMap().size());
    try {
        Series timeSeries = engine.getTimeSeries(dbName, measurementName, valueFieldName, tagd);
        assertNotNull(timeSeries);
    } catch (ItemNotFoundException e) {
        fail("Time series must exist");
    }
    List<SeriesOutput> queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, ts, ts + 220 * 1000, null);
    assertEquals(1, queryDataPoints.size());
    SeriesOutput next = queryDataPoints.iterator().next();
    assertEquals(200, next.getDataPoints().size());
}
Also used : BackgrounThreadFactory(com.srotya.sidewinder.core.utils.BackgrounThreadFactory) Point(com.srotya.sidewinder.core.rpc.Point) Point(com.srotya.sidewinder.core.rpc.Point) InvalidFilterException(com.srotya.sidewinder.core.utils.InvalidFilterException) IOException(java.io.IOException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Tag(com.srotya.sidewinder.core.rpc.Tag) Test(org.junit.Test)

Example 32 with Tag

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

the class TestDiskStorageEngine method testMultipleDrives2.

@Test
public void testMultipleDrives2() throws ItemNotFoundException, IOException {
    StorageEngine engine = new DiskStorageEngine();
    HashMap<String, String> map = new HashMap<>();
    MiscUtils.delete(new File("targer/db10221/"));
    map.put("index.dir", "target/db10221/index");
    map.put("data.dir", "target/db10221/data1,target/db10221/data2");
    List<Tag> tagd = Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("e").build());
    try {
        engine.configure(map, bgTasks);
    } catch (IOException e) {
        e.printStackTrace();
        fail("No IOException should be thrown");
    }
    long ts = System.currentTimeMillis();
    try {
        for (int i = 0; i < 10; i++) {
            engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test" + i, "ss", "value", tagd, ts, 2.2), false);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
    }
    assertEquals(5, new File("target/db10221/data1").listFiles().length);
    assertEquals(5, new File("target/db10221/data2").listFiles().length);
    engine.shutdown();
}
Also used : HashMap(java.util.HashMap) Tag(com.srotya.sidewinder.core.rpc.Tag) IOException(java.io.IOException) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) File(java.io.File) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 33 with Tag

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

the class TestDiskStorageEngine method testQueryDataPointsRecovery.

@Test
public void testQueryDataPointsRecovery() throws Exception {
    try {
        List<Tag> tagd = Arrays.asList(Tag.newBuilder().setTagKey("test").setTagValue("e").build());
        DiskStorageEngine engine = new DiskStorageEngine();
        File file = new File("target/db201/");
        MiscUtils.delete(file);
        MiscUtils.ls(file);
        Map<String, String> map = new HashMap<>();
        map.put("index.dir", "target/db201/index");
        map.put("data.dir", "target/db201/data");
        engine.configure(map, bgTasks);
        long ts = System.currentTimeMillis();
        Map<String, Measurement> db = engine.getOrCreateDatabase("test3");
        assertEquals(0, db.size());
        engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test3", "cpu", "value", tagd, ts, 1), false);
        engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test3", "cpu", "value", tagd, ts + (400 * 60000), 4), false);
        Measurement measurement = engine.getOrCreateMeasurement("test3", "cpu");
        assertEquals(1, measurement.getSeriesKeys().size());
        MiscUtils.ls(file);
        engine = new DiskStorageEngine();
        engine.configure(map, bgTasks);
        assertTrue(!engine.isMeasurementFieldFP("test3", "cpu", "value"));
        List<SeriesOutput> queryDataPoints = engine.queryDataPoints("test3", "cpu", "value", ts, ts + (400 * 60000), null, null);
        try {
            engine.isMeasurementFieldFP("test3", "test", "test");
            fail("Measurement should not exist");
        } catch (Exception e) {
        }
        assertEquals(1, queryDataPoints.size());
        assertEquals(2, queryDataPoints.iterator().next().getDataPoints().size());
        assertEquals(ts, queryDataPoints.iterator().next().getDataPoints().get(0).getTimestamp());
        assertEquals(ts + (400 * 60000), queryDataPoints.iterator().next().getDataPoints().get(1).getTimestamp());
        TagFilter filter = MiscUtils.buildTagFilter("test=e");
        queryDataPoints = engine.queryDataPoints("test3", "cpu", "value", ts, ts + (400 * 60000), filter, null);
        assertEquals(1, queryDataPoints.size());
        assertEquals(2, queryDataPoints.iterator().next().getDataPoints().size());
        assertEquals(ts, queryDataPoints.iterator().next().getDataPoints().get(0).getTimestamp());
        assertEquals(ts + (400 * 60000), queryDataPoints.iterator().next().getDataPoints().get(1).getTimestamp());
        filter = MiscUtils.buildTagFilter("test=2");
        queryDataPoints = engine.queryDataPoints("test3", "cpu", "value", ts, ts + (400 * 60000), filter, null);
        assertEquals(0, queryDataPoints.size());
        try {
            engine.dropDatabase("test3");
        } catch (Exception e) {
            e.printStackTrace();
            fail("Database delete must succeed");
        }
        assertTrue(!new File("target/db201/data/test3").exists());
        assertEquals(0, engine.getOrCreateMeasurement("test3", "cpu").getSeriesKeys().size());
        engine.shutdown();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) HashMap(java.util.HashMap) TagFilter(com.srotya.sidewinder.core.filters.TagFilter) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) IOException(java.io.IOException) Tag(com.srotya.sidewinder.core.rpc.Tag) File(java.io.File) Test(org.junit.Test)

Example 34 with Tag

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

the class TestDiskStorageEngine method testMultipleDrives.

@Test
public void testMultipleDrives() throws ItemNotFoundException, IOException {
    StorageEngine engine = new DiskStorageEngine();
    HashMap<String, String> map = new HashMap<>();
    MiscUtils.delete(new File("targer/db10221/"));
    map.put("index.dir", "target/db10221/index");
    map.put("data.dir", "target/db10221/data1, target/db10221/data2");
    List<Tag> tagd = Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("e").build());
    try {
        engine.configure(map, bgTasks);
    } catch (IOException e) {
        e.printStackTrace();
        fail("No IOException should be thrown");
    }
    long ts = System.currentTimeMillis();
    try {
        for (int i = 0; i < 10; i++) {
            engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test" + i, "ss", "value", tagd, ts, 2.2), false);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
    }
    assertEquals(5, new File("target/db10221/data1").listFiles().length);
    assertEquals(5, new File("target/db10221/data2").listFiles().length);
    engine.shutdown();
}
Also used : HashMap(java.util.HashMap) Tag(com.srotya.sidewinder.core.rpc.Tag) IOException(java.io.IOException) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) File(java.io.File) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 35 with Tag

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

the class QAInMemoryByzantineDefaultsAuthenticated method testSingleSeriesWrites.

@Test
public void testSingleSeriesWrites() throws KeyManagementException, ClientProtocolException, NoSuchAlgorithmException, KeyStoreException, MalformedURLException, IOException, ParseException, InterruptedException {
    long sts = 1497720452566L;
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    format.setTimeZone(TimeZone.getTimeZone("utc"));
    String payload = "{\"panelId\":2,\"range\":{\"from\":\"%s\",\"to\":\"%s\",\"raw\":{\"from\":\"now-5m\",\"to\":\"now\"}},\"rangeRaw\":{\"from\":\"now-5m\",\"to\":\"now\"},\"interval\":\"200ms\",\"intervalMs\":200,\"targets\":[{\"target\":\"cpu\",\"filters\":[],\"aggregator\":{\"args\":[{\"index\":0,\"type\":\"int\",\"value\":\"20\"}],\"name\":\"none\",\"unit\":\"secs\"},\"field\":\"value\",\"refId\":\"A\",\"type\":\"timeserie\"}],\"format\":\"json\",\"maxDataPoints\":1280}";
    HttpPost post = new HttpPost("http://localhost:" + PORT + "/influx?db=qaSingleSeries");
    CloseableHttpResponse response = TestUtils.makeRequestAuthenticated(post, provider);
    assertEquals(400, response.getStatusLine().getStatusCode());
    post = new HttpPost("http://localhost:" + PORT + "/influx?db=qaSingleSeries");
    post.setEntity(new StringEntity("cpu,host=server01,region=uswest value=1i 1497720452566000000\n" + "cpu,host=server02,region=uswest value=1i 1497720452566000000\n" + "cpu,host=server03,region=uswest value=1i 1497720452566000000\n" + "cpu,host=server01,region=uswest value=1i 1497720453566000000\n" + "cpu,host=server02,region=uswest value=1i 1497720453566000000\n" + "cpu,host=server03,region=uswest value=1i 1497720453566000000"));
    response = TestUtils.makeRequestAuthenticated(post, provider);
    assertEquals(204, response.getStatusLine().getStatusCode());
    post = new HttpPost("http://localhost:" + PORT + "/qaSingleSeries/query/measurements");
    post.setHeader("Content-Type", "application/json");
    response = TestUtils.makeRequestAuthenticated(post, provider);
    Gson gson = new Gson();
    JsonArray ary = gson.fromJson(EntityUtils.toString(response.getEntity()), JsonArray.class);
    assertEquals("cpu", ary.get(0).getAsString());
    post = new HttpPost("http://localhost:" + PORT + "/qaSingleSeries/query/tags");
    post.setHeader("Content-Type", "application/json");
    post.setEntity(new StringEntity("{ \"target\":\"cpu\" }"));
    response = TestUtils.makeRequestAuthenticated(post, provider);
    ary = gson.fromJson(EntityUtils.toString(response.getEntity()), JsonArray.class);
    assertEquals(2, ary.size());
    post = new HttpPost("http://localhost:" + PORT + "/qaSingleSeries/query");
    post.setHeader("Content-Type", "application/json");
    post.setEntity(new StringEntity(String.format(payload, format.format(new Date(sts - 60_000)), format.format(new Date(sts + 60_000)))));
    response = TestUtils.makeRequestAuthenticated(post, provider);
    ary = gson.fromJson(EntityUtils.toString(response.getEntity()), JsonArray.class);
    assertEquals(3, ary.size());
    int i = 0;
    for (JsonElement ele : ary) {
        i += ele.getAsJsonObject().get("datapoints").getAsJsonArray().size();
    }
    assertEquals(6, i);
    response = TestUtils.makeRequestAuthenticated(new HttpGet("http://localhost:" + PORT + "/databases/qaSingleSeries/measurements/cpu/fields/value?startTime=" + (sts - 2000) + "&endTime=" + (sts + 2000)), provider);
    ary = gson.fromJson(EntityUtils.toString(response.getEntity()), JsonArray.class);
    Set<Tag> tag = new HashSet<>(Arrays.asList(Tag.newBuilder().setTagKey("host").setTagValue("server02").build(), Tag.newBuilder().setTagKey("host").setTagValue("server01").build(), Tag.newBuilder().setTagKey("host").setTagValue("server03").build(), Tag.newBuilder().setTagKey("region").setTagValue("uswest").build()));
    Iterator<JsonElement> itr = ary.iterator();
    i = 0;
    while (itr.hasNext()) {
        JsonObject obj = itr.next().getAsJsonObject();
        assertEquals("cpu", obj.get("measurementName").getAsString());
        assertEquals("value", obj.get("valueFieldName").getAsString());
        ary = obj.get("tags").getAsJsonArray();
        for (JsonElement ele : ary) {
            Tag tagObj = gson.fromJson(ele, Tag.class);
            assertTrue(ele + " ", tag.contains(tagObj));
        }
        i += obj.get("dataPoints").getAsJsonArray().size();
        JsonArray ary2 = obj.get("dataPoints").getAsJsonArray();
        for (int j = 0; j < ary2.size(); j++) {
            JsonElement ele = ary2.get(j);
            assertEquals(1, ele.getAsJsonObject().get("value").getAsInt());
            long ts = 1497720452566L + j * 1000;
            assertEquals(ts, ele.getAsJsonObject().get("timestamp").getAsLong());
        }
    }
    assertEquals(6, i);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpGet(org.apache.http.client.methods.HttpGet) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) Date(java.util.Date) JsonArray(com.google.gson.JsonArray) StringEntity(org.apache.http.entity.StringEntity) JsonElement(com.google.gson.JsonElement) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Tag(com.srotya.sidewinder.core.rpc.Tag) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet) 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