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());
}
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;
}
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();
}
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));
}
}
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;
}
Aggregations