use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class DatabaseOpsApi method querySeries.
@Path("/{" + DB_NAME + "}/query")
@POST
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.TEXT_PLAIN })
public String querySeries(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, String query) {
try {
String[] queryParts = query.split("<=?");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
long endTs = System.currentTimeMillis();
long startTs = endTs;
String startTime = queryParts[0];
String endTime = queryParts[2];
if (startTime.contains("now")) {
String[] split = startTime.split("-");
int offset = Integer.parseInt(split[1].charAt(0) + "");
startTs = startTs - (offset * 3600 * 1000);
} else if (startTime.matches("\\d+")) {
startTs = Long.parseLong(startTime);
endTs = Long.parseLong(endTime);
} else {
startTs = sdf.parse(startTime).getTime();
endTs = sdf.parse(endTime).getTime();
}
// cpu.load.host=v1.domain=test\.com=>derivative,10,mean
TargetSeries tagSeries = MiscUtils.extractTargetFromQuery(query);
List<SeriesOutput> points = storageEngine.queryDataPoints(dbName, tagSeries.getMeasurementName(), tagSeries.getFieldName(), startTs, endTs, tagSeries.getTagFilter(), null, tagSeries.getAggregationFunction());
return new Gson().toJson(points);
} catch (ItemNotFoundException e) {
throw new NotFoundException(e);
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
e.printStackTrace();
throw new InternalServerErrorException(e);
}
}
use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class MeasurementOpsApi method getSeries.
public List<Number[]> getSeries(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, @PathParam(MEASUREMENT) String measurementName, @QueryParam("field") String valueFieldName, @DefaultValue("now-1h") @QueryParam(START_TIME) String startTime, @QueryParam(END_TIME) String endTime) {
if (valueFieldName == null) {
throw new BadRequestException("Must specify a value field");
}
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long endTs = System.currentTimeMillis();
long startTs = endTs;
if (startTime.contains("now")) {
String[] split = startTime.split("-");
int offset = Integer.parseInt(split[1].charAt(0) + "");
startTs = startTs - (offset * 3600 * 1000);
} else {
startTs = sdf.parse(startTime).getTime();
endTs = sdf.parse(endTime).getTime();
}
List<SeriesOutput> points = engine.queryDataPoints(dbName, measurementName, valueFieldName, startTs, endTs, null);
List<Number[]> response = new ArrayList<>();
for (SeriesOutput entry : points) {
for (DataPoint dataPoint : entry.getDataPoints()) {
if (entry.isFp()) {
response.add(new Number[] { dataPoint.getLongValue(), dataPoint.getTimestamp() });
} else {
response.add(new Number[] { dataPoint.getValue(), dataPoint.getTimestamp() });
}
}
}
return response;
} catch (ItemNotFoundException e) {
throw new NotFoundException(e);
} catch (Exception e) {
throw new InternalServerErrorException(e);
}
}
use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class ReduceFunction method apply.
@Override
public SeriesOutput apply(SeriesOutput dataPoints) {
SeriesOutput output = new SeriesOutput(dataPoints.getMeasurementName(), dataPoints.getValueFieldName(), dataPoints.getTags());
output.setFp(dataPoints.isFp());
DataPoint single = new DataPoint();
single.setTimestamp(dataPoints.getDataPoints().get(0).getTimestamp());
aggregateToSingle(dataPoints.getDataPoints(), single, dataPoints.isFp());
output.setDataPoints(Arrays.asList(single));
return output;
}
use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class TestGRPWriterServiceImpl method testPointWritesRejects.
@Test
public void testPointWritesRejects() throws Exception {
WriterServiceBlockingStub client = WriterServiceGrpc.newBlockingStub(channel);
long sts = 1497720452566L;
String dbName = "test3";
String measurementName = "cpu4";
List<Point> points = Arrays.asList(Point.newBuilder().setDbName(dbName).addFp(false).setMeasurementName(measurementName).addTags(Tag.newBuilder().setTagKey("host").setTagValue("1").build()).setTimestamp(sts).addValue(1L).addValueFieldName("usage").build(), Point.newBuilder().setDbName(dbName).addFp(false).setMeasurementName(measurementName).addTags(Tag.newBuilder().setTagKey("host").setTagValue("1").build()).setTimestamp(sts + 1).addValue(2L).addValueFieldName("usage").build());
try {
Ack response = client.writeBatchDataPoint(BatchData.newBuilder().setMessageId(sts).addAllPoints(points).build());
if (response.getResponseCode() != 200) {
fail("Must return 200");
}
} catch (Exception e) {
}
assertTrue(engine.checkIfExists(dbName));
assertTrue(engine.checkIfExists(dbName, measurementName));
assertEquals("host", engine.getTagKeysForMeasurement(dbName, measurementName).iterator().next());
List<SeriesOutput> result = engine.queryDataPoints(dbName, measurementName, "usage", sts, sts + 1, null);
assertEquals(1, result.size());
assertEquals(2, result.iterator().next().getDataPoints().size());
assertEquals(1L, result.iterator().next().getDataPoints().iterator().next().getLongValue());
}
use of com.srotya.sidewinder.core.storage.SeriesOutput in project sidewinder by srotya.
the class TestGRPWriterServiceImpl method testMultiDataPointWrites.
// @Test
public void testMultiDataPointWrites() throws Exception {
WriterServiceBlockingStub client = WriterServiceGrpc.newBlockingStub(channel);
long sts = 1497720452566L;
String dbName = "test2";
String measurementName = "cpu";
List<Point> points = Arrays.asList(Point.newBuilder().setDbName(dbName).addFp(false).setMeasurementName(measurementName).addTags(Tag.newBuilder().setTagKey("host").setTagValue("1").build()).setTimestamp(sts).addValue(1L).addValueFieldName("usage").build(), Point.newBuilder().setDbName(dbName).addFp(false).setMeasurementName(measurementName).addTags(Tag.newBuilder().setTagKey("host").setTagValue("1").build()).setTimestamp(sts + 1).addValue(2L).addValueFieldName("usage").build());
client.writeBatchDataPoint(BatchData.newBuilder().setMessageId(sts).addAllPoints(points).build());
assertTrue(engine.checkIfExists(dbName));
assertTrue(engine.checkIfExists(dbName, measurementName));
assertEquals("host=1", engine.getTagKeysForMeasurement(dbName, measurementName).iterator().next());
List<SeriesOutput> result = engine.queryDataPoints(dbName, measurementName, "usage", sts, sts + 1, null);
assertEquals(1, result.size());
assertEquals(2, result.iterator().next().getDataPoints().size());
assertEquals(1L, result.iterator().next().getDataPoints().iterator().next().getLongValue());
}
Aggregations