Search in sources :

Example 1 with Point

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

the class InfluxDecoder method pointsFromString.

public static List<Point> pointsFromString(String dbName, String payload) {
    List<Point> dps = new ArrayList<>();
    String[] splits = payload.split("[\\r\\n]+");
    for (String split : splits) {
        try {
            String[] parts = split.split("\\s+");
            if (parts.length < 2 || parts.length > 3) {
                // invalid datapoint => drop
                continue;
            }
            long timestamp = System.currentTimeMillis();
            if (parts.length == 3) {
                timestamp = Long.parseLong(parts[2]);
                if (parts[2].length() > LENGTH_OF_MILLISECOND_TS) {
                    timestamp = timestamp / (1000 * 1000);
                }
            } else {
                logger.finest("Bad datapoint parts:" + parts.length);
            }
            String[] key = parts[0].split(",");
            String measurementName = key[0];
            Set<String> tTags = new HashSet<>();
            for (int i = 1; i < key.length; i++) {
                tTags.add(key[i]);
            }
            List<String> tags = new ArrayList<>(tTags);
            String[] fields = parts[1].split(",");
            for (String field : fields) {
                String[] fv = field.split("=");
                String valueFieldName = fv[0];
                if (!fv[1].endsWith("i")) {
                    Builder builder = Point.newBuilder();
                    double value = Double.parseDouble(fv[1]);
                    builder.setDbName(dbName);
                    builder.setMeasurementName(measurementName);
                    builder.setValueFieldName(valueFieldName);
                    builder.setValue(Double.doubleToLongBits(value));
                    builder.addAllTags(tags);
                    builder.setTimestamp(timestamp);
                    builder.setFp(true);
                    dps.add(builder.build());
                } else {
                    Builder builder = Point.newBuilder();
                    fv[1] = fv[1].substring(0, fv[1].length() - 1);
                    long value = Long.parseLong(fv[1]);
                    builder.setDbName(dbName);
                    builder.setMeasurementName(measurementName);
                    builder.setValueFieldName(valueFieldName);
                    builder.setValue(value);
                    builder.addAllTags(tags);
                    builder.setTimestamp(timestamp);
                    builder.setFp(false);
                    dps.add(builder.build());
                }
            }
        } catch (Exception e) {
            logger.fine("Rejected:" + split);
        }
    }
    return dps;
}
Also used : Builder(com.srotya.sidewinder.core.rpc.Point.Builder) ArrayList(java.util.ArrayList) Point(com.srotya.sidewinder.core.rpc.Point) Point(com.srotya.sidewinder.core.rpc.Point) HashSet(java.util.HashSet)

Example 2 with Point

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

the class TestInfluxDecoder method testIdenticalWriteMultipoints.

@Test
public void testIdenticalWriteMultipoints() {
    String testPoints = "cpu,host=server01,region=uswest value=1i 1434055562000000000\ncpu,host=server01,region=uswest value=1i 1434055562000000000\ncpu,host=server01,region=uswest value=1i 1434055562000000000";
    List<Point> dps = InfluxDecoder.pointsFromString("test", testPoints);
    for (Point dp : dps) {
        assertEquals("cpu", dp.getMeasurementName());
        assertTrue(dp.getTagsList().contains("host=server01"));
        assertTrue(dp.getTagsList().contains("region=uswest"));
        assertEquals(1, dp.getValue());
        assertEquals(1434055562000000000L / (1000 * 1000), dp.getTimestamp());
    }
}
Also used : Point(com.srotya.sidewinder.core.rpc.Point) Test(org.junit.Test)

Example 3 with Point

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

the class TestInfluxDecoder method testSinglePointMeasurementValueWithoutTimestamp.

@Test
public void testSinglePointMeasurementValueWithoutTimestamp() {
    String testPoints = "cpu value=1i";
    List<Point> dps = InfluxDecoder.pointsFromString("test", testPoints);
    assertEquals(1, dps.size());
    Point dp = dps.get(0);
    assertEquals("cpu", dp.getMeasurementName());
    assertEquals(0, dp.getTagsList().size());
    assertEquals(1, dp.getValue());
    long ts = System.currentTimeMillis();
    assertTrue(dp.getTimestamp() > 0);
    assertEquals(1, (dp.getTimestamp() / ts), 1);
}
Also used : Point(com.srotya.sidewinder.core.rpc.Point) Test(org.junit.Test)

Example 4 with Point

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

the class TestInfluxDecoder method testIdenticalWriteSinglePoint.

@Test
public void testIdenticalWriteSinglePoint() {
    String testPoints = "cpu,host=server01,region=uswest value=1i 1434055562000000000";
    List<Point> dps = InfluxDecoder.pointsFromString("test", testPoints);
    Point dp = dps.get(0);
    assertEquals("cpu", dp.getMeasurementName());
    assertTrue(dp.getTagsList().contains("host=server01"));
    assertTrue(dp.getTagsList().contains("region=uswest"));
    assertEquals(1, dp.getValue());
    assertEquals(1434055562000000000L / (1000 * 1000), dp.getTimestamp());
}
Also used : Point(com.srotya.sidewinder.core.rpc.Point) Test(org.junit.Test)

Example 5 with Point

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

the class TestInfluxDecoder method testSinglePointMeasurementValue.

@Test
public void testSinglePointMeasurementValue() {
    String testPoints = "cpu value=1i 1434055562000000000";
    List<Point> dps = InfluxDecoder.pointsFromString("test", testPoints);
    assertEquals(1, dps.size());
    Point dp = dps.get(0);
    assertEquals("cpu", dp.getMeasurementName());
    assertEquals(0, dp.getTagsList().size());
    assertEquals(1, dp.getValue());
    assertEquals(1434055562000000000L / (1000 * 1000), dp.getTimestamp());
}
Also used : Point(com.srotya.sidewinder.core.rpc.Point) Test(org.junit.Test)

Aggregations

Point (com.srotya.sidewinder.core.rpc.Point)12 Test (org.junit.Test)8 IOException (java.io.IOException)4 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)2 Series (com.srotya.sidewinder.core.storage.Series)2 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)2 ExecutorService (java.util.concurrent.ExecutorService)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Builder (com.srotya.sidewinder.core.rpc.Point.Builder)1 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)1 RejectException (com.srotya.sidewinder.core.storage.RejectException)1 StorageEngine (com.srotya.sidewinder.core.storage.StorageEngine)1 BackgrounThreadFactory (com.srotya.sidewinder.core.utils.BackgrounThreadFactory)1 ByteBuf (io.netty.buffer.ByteBuf)1 HttpContent (io.netty.handler.codec.http.HttpContent)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)1