Search in sources :

Example 1 with Tag

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

the class TestChainFunction method testTwoFunctions.

@Test
public void testTwoFunctions() throws Exception {
    Series series = new Series("cpu", "test", Arrays.asList(new Tag("t", "1"), new Tag("t", "2")));
    List<DataPoint> dps = new ArrayList<>();
    long baseTs = 1486617103629L;
    for (int i = 0; i < 4; i++) {
        dps.add(new DataPoint(baseTs + 30_000 * i, 1));
    }
    series.setDataPoints(dps);
    series.setFp(false);
    List<Series> seriesList = Arrays.asList(series);
    ChainFunction cf = new ChainFunction();
    ReducingWindowedAggregator rwa = new WindowedMean();
    rwa.init(new Object[] { 70, "smean" });
    ReducingWindowedAggregator rwa2 = new WindowedMean();
    rwa2.init(new Object[] { 200, "smean" });
    cf.init(new Function[] { rwa, rwa2 });
    List<Series> apply = cf.apply(seriesList);
    List<DataPoint> result = apply.get(0).getDataPoints();
    assertEquals(1, result.size());
    assertEquals(1, result.get(0).getLongValue());
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ReducingWindowedAggregator(com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ChainFunction(com.srotya.sidewinder.core.functions.multiseries.ChainFunction) ArrayList(java.util.ArrayList) Tag(com.srotya.sidewinder.core.filters.Tag) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 2 with Tag

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

the class Measurement method decodeStringToTags.

public static List<Tag> decodeStringToTags(TagIndex tagIndex, String tagString) throws IOException {
    List<Tag> tagList = new ArrayList<>();
    if (tagString == null || tagString.isEmpty()) {
        return tagList;
    }
    for (String tag : tagString.split("\\" + TAG_SEPARATOR)) {
        String[] split = tag.split(TAG_KV_SEPARATOR);
        if (split.length != 2) {
            throw SEARCH_REJECT;
        }
        tagList.add(new Tag(split[0], split[1]));
    }
    return tagList;
}
Also used : ArrayList(java.util.ArrayList) Tag(com.srotya.sidewinder.core.filters.Tag)

Example 3 with Tag

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

the class TestPersistentMeasurement method testDataPointsQuery.

@Test
public void testDataPointsQuery() throws Exception {
    long ts = System.currentTimeMillis();
    MiscUtils.delete(new File("target/db41/"));
    List<String> tags = Arrays.asList("test=1", "test=2");
    PersistentMeasurement m = new PersistentMeasurement();
    Map<String, String> map = new HashMap<>();
    map.put("disk.compression.class", ByzantineWriter.class.getName());
    map.put("malloc.file.max", String.valueOf(2 * 1024 * 1024));
    m.configure(map, null, DBNAME, "m1", "target/db41/index", "target/db41/data", metadata, bgTaskPool);
    int LIMIT = 1000;
    for (int i = 0; i < LIMIT; i++) {
        TimeSeries t = m.getOrCreateTimeSeries("value1", tags, 4096, false, map);
        t.addDataPoint(TimeUnit.MILLISECONDS, ts + i * 1000, 1L);
    }
    for (int i = 0; i < LIMIT; i++) {
        TimeSeries t = m.getOrCreateTimeSeries("value2", tags, 4096, false, map);
        t.addDataPoint(TimeUnit.MILLISECONDS, ts + i * 1000, 1L);
    }
    List<Series> resultMap = new ArrayList<>();
    m.queryDataPoints("value.*$", ts, ts + 1000 * LIMIT, null, null, resultMap);
    assertEquals(2, resultMap.size());
    for (Series s : resultMap) {
        for (int i = 0; i < s.getDataPoints().size(); i++) {
            DataPoint dataPoint = s.getDataPoints().get(i);
            assertEquals(ts + i * 1000, dataPoint.getTimestamp());
            assertEquals(1L, dataPoint.getLongValue());
        }
    }
    List<List<Tag>> tagsResult = m.getTagsForMeasurement();
    Collections.sort(tags);
    for (List<Tag> list : tagsResult) {
        Set<Tag> hashSet = new HashSet<>(list);
        for (int i = 0; i < tags.size(); i++) {
            String tag = tags.get(i);
            String[] split = tag.split("=");
            assertTrue(hashSet.contains(new Tag(split[0], split[1])));
        }
    }
    try {
        tagsResult = m.getTagsForMeasurement();
    } catch (IOException e) {
    }
    m.close();
}
Also used : TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ByzantineWriter(com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.srotya.sidewinder.core.filters.Tag) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Tag

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

the class TestPersistentMeasurement method testTagEncodeDecode.

@Test
public void testTagEncodeDecode() throws IOException {
    String indexDir = "target/test";
    MetricsRegistryService.getInstance(engine, bgTaskPool).getInstance("requests");
    MiscUtils.delete(new File(indexDir));
    new File(indexDir).mkdirs();
    SetIndex table = new SetIndex(indexDir, "test2");
    Measurement measurement = new PersistentMeasurement();
    String encodedStr = measurement.encodeTagsToString(table, Arrays.asList("host=2", "value=1", "test=1"));
    List<Tag> decodedStr = Measurement.decodeStringToTags(table, encodedStr);
    List<Tag> list = Arrays.asList(new Tag("host", "2"), new Tag("value", "1"), new Tag("test", "1"));
    for (int i = 0; i < list.size(); i++) {
        assertEquals(list.get(i) + "", list.get(i), decodedStr.get(i));
    }
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) SetIndex(com.srotya.sidewinder.core.storage.mem.SetIndex) Tag(com.srotya.sidewinder.core.filters.Tag) File(java.io.File) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 5 with Tag

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

the class MultiSeriesFunction method apply.

@Override
public List<Series> apply(List<Series> t) {
    List<Series> output = new ArrayList<>();
    boolean fp = t.get(0).isFp();
    List<List<DataPoint>> intermediate = new ArrayList<>();
    int size = t.get(0).getDataPoints().size();
    for (int i = 0; i < t.size(); i++) {
        Series ts = t.get(i);
        if (size != ts.getDataPoints().size()) {
            throw new IllegalArgumentException("Non-uniform series length");
        }
        intermediate.add(ts.getDataPoints());
    }
    List<DataPoint> compute = compute(intermediate, fp);
    Series series = new Series(compute);
    series.setFp(fp);
    series.setMeasurementName(t.get(0).getMeasurementName());
    series.setValueFieldName(name());
    series.setTags(Arrays.asList(new Tag("multiseries", "true")));
    output.add(series);
    return output;
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Tag(com.srotya.sidewinder.core.filters.Tag) DataPoint(com.srotya.sidewinder.core.storage.DataPoint)

Aggregations

Tag (com.srotya.sidewinder.core.filters.Tag)11 Test (org.junit.Test)6 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)5 ArrayList (java.util.ArrayList)5 Series (com.srotya.sidewinder.core.storage.Series)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Gson (com.google.gson.Gson)2 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 ChainFunction (com.srotya.sidewinder.core.functions.multiseries.ChainFunction)2 ReducingWindowedAggregator (com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator)2 Reader (com.srotya.sidewinder.core.storage.compression.Reader)2 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPost (org.apache.http.client.methods.HttpPost)2