use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.
the class Measurement method encodeTagsToString.
public default ByteString encodeTagsToString(List<Tag> tags) throws IOException {
StringBuilder builder = new StringBuilder(tags.size() * 5);
serializeTagForKey(builder, tags.get(0));
for (int i = 1; i < tags.size(); i++) {
Tag tag = tags.get(i);
builder.append(TAG_SEPARATOR);
serializeTagForKey(builder, tag);
}
String rowKey = builder.toString();
return new ByteString(rowKey);
}
use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.
the class MeasurementOpsApi method createSeries.
@Path("/series")
@PUT
@Consumes({ MediaType.APPLICATION_JSON })
public void createSeries(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, @PathParam(MEASUREMENT) String measurementName, String seriesConfig) {
Gson gson = new Gson();
JsonObject series = gson.fromJson(seriesConfig, JsonObject.class);
List<Tag> tags = new ArrayList<>();
for (JsonElement jsonElement : series.get("tags").getAsJsonArray()) {
String tagStr = jsonElement.getAsString();
String[] splits = tagStr.split(Measurement.TAG_KV_SEPARATOR);
tags.add(Tag.newBuilder().setTagKey(splits[0]).setTagValue(splits[1]).build());
}
try {
Measurement m = engine.getOrCreateMeasurement(dbName, measurementName);
m.getOrCreateSeries(tags, false);
} catch (IOException e) {
throw new InternalServerErrorException(e);
}
}
use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.
the class TestStorageEngine method testCompaction.
@Test
public void testCompaction() throws IOException, InterruptedException {
conf.put("default.bucket.size", "409600");
conf.put("use.query.pool", "false");
conf.put("compaction.delay", "1");
conf.put("compaction.frequency", "1");
engine.configure(conf, bgTasks);
final long curr = 1497720652566L;
String dbName = "test";
String measurementName = "cpu";
String valueFieldName = "value";
List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("host").setTagValue("123123").build());
for (int i = 1; i <= 10000; i++) {
engine.writeDataPointWithLock(MiscUtils.buildDataPoint(dbName, measurementName, Arrays.asList(valueFieldName), tags, curr + i * 1000, Arrays.asList(Double.doubleToLongBits(i * 1.1)), Arrays.asList(true)), false);
}
long ts = System.nanoTime();
List<SeriesOutput> queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr - 1000, curr + 10000 * 1000 + 1, null, null);
ts = System.nanoTime() - ts;
System.out.println("Before compaction:" + ts / 1000 + "us");
assertEquals(1, queryDataPoints.size());
assertEquals(10000, queryDataPoints.iterator().next().getDataPoints().size());
List<DataPoint> dataPoints = queryDataPoints.iterator().next().getDataPoints();
for (int i = 1; i <= 10000; i++) {
DataPoint dp = dataPoints.get(i - 1);
assertEquals("Bad ts:" + i, curr + i * 1000, dp.getTimestamp());
assertEquals(dp.getValue(), i * 1.1, 0.001);
}
Measurement m = engine.getOrCreateMeasurement(dbName, measurementName);
Series series = m.getOrCreateSeries(tags, false);
SortedMap<Integer, Map<String, Field>> bucketRawMap = series.getBucketMap();
assertEquals(1, bucketRawMap.size());
int size = (int) MiscUtils.bucketCounter(series);
assertTrue(size > 2);
Thread.sleep(4000);
ts = System.nanoTime();
queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr - 1, curr + 20000 * 1000 + 1, null, null);
ts = System.nanoTime() - ts;
System.out.println("After compaction:" + ts / 1000 + "us");
bucketRawMap = series.getBucketMap();
assertEquals(2, bucketRawMap.values().iterator().next().size());
assertEquals(10000, queryDataPoints.iterator().next().getDataPoints().size());
dataPoints = queryDataPoints.iterator().next().getDataPoints();
for (int i = 1; i <= 10000; i++) {
DataPoint dp = dataPoints.get(i - 1);
assertEquals("Bad ts:" + i, curr + i * 1000, dp.getTimestamp());
assertEquals(dp.getValue(), i * 1.1, 0.001);
}
}
use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.
the class TestStorageEngine method testConfigureTimeBuckets.
@Test
public void testConfigureTimeBuckets() throws ItemNotFoundException, IOException {
long ts = System.currentTimeMillis();
conf.put(StorageEngine.DEFAULT_BUCKET_SIZE, String.valueOf(4096 * 10));
List<Tag> tagd = Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("e").build());
try {
engine.configure(conf, bgTasks);
} catch (IOException e) {
fail("No IOException should be thrown");
}
try {
for (int i = 0; i < 10; i++) {
engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test", "ss", "value", tagd, ts + (i * 4096 * 1000), 2.2), false);
}
} catch (Exception e) {
e.printStackTrace();
fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
}
List<SeriesOutput> queryDataPoints = engine.queryDataPoints("test", "ss", "value", ts, ts + (4096 * 100 * 1000) + 1, new SimpleTagFilter(FilterType.EQUALS, "t", "e"));
assertTrue(queryDataPoints.size() >= 1);
}
use of com.srotya.sidewinder.core.rpc.Tag in project sidewinder by srotya.
the class TestStorageEngine method testConfigure.
@Test
public void testConfigure() throws IOException {
List<Tag> tagd = Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("e").build());
try {
engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test", "ss", "value", tagd, System.currentTimeMillis(), 2.2), false);
fail("Engine not initialized, shouldn't be able to write a datapoint");
} catch (Exception e) {
}
try {
// FileUtils.forceDelete(new File("target/db2/"));
MiscUtils.delete(new File("targer/db2/"));
HashMap<String, String> map = new HashMap<>();
map.put("index.dir", "target/db2/index");
map.put("data.dir", "target/db2/data");
map.put("default.series.retention.hours", "32");
engine.configure(map, bgTasks);
} catch (IOException e) {
fail("No IOException should be thrown");
}
try {
engine.writeDataPointWithLock(MiscUtils.buildDataPoint("test", "ss", "value", tagd, System.currentTimeMillis(), 2.2), false);
String md = new String(Files.readAllBytes(new File("target/db2/data/test/.md").toPath()), Charset.forName("utf8"));
DBMetadata metadata = new Gson().fromJson(md, DBMetadata.class);
assertEquals(32, metadata.getRetentionHours());
} catch (Exception e) {
e.printStackTrace();
fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
}
engine.shutdown();
}
Aggregations