use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.
the class TestHttpJsonSerializer method formatQueryAsyncV1wQuery.
@Test
public void formatQueryAsyncV1wQuery() throws Exception {
setupFormatQuery();
HttpQuery query = NettyMocks.getQuery(tsdb, "");
HttpJsonSerializer serdes = new HttpJsonSerializer(query);
final TSQuery data_query = getTestQuery(false);
data_query.setShowQuery(true);
validateTestQuery(data_query);
final List<DataPoints[]> results = new ArrayList<DataPoints[]>(1);
results.add(new DataPoints[] { new MockDataPoints().getMock() });
ChannelBuffer cb = serdes.formatQueryAsyncV1(data_query, results, Collections.<Annotation>emptyList()).joinUninterruptibly();
assertNotNull(cb);
final String json = cb.toString(Charset.forName("UTF-8"));
assertTrue(json.contains("\"metric\":\"system.cpu.user\","));
assertTrue(json.contains("\"1356998700\":1,"));
assertTrue(json.contains("\"1357058700\":201"));
assertFalse(json.contains("\"timeTotal\""));
assertTrue(json.contains("\"tsuid\":\"000001000001000001\""));
assertTrue(json.contains("\"query\":"));
}
use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.
the class TestHttpJsonSerializer method formatQueryAsyncV1NoSuchMetricId.
@Test(expected = DeferredGroupException.class)
public void formatQueryAsyncV1NoSuchMetricId() throws Exception {
setupFormatQuery();
HttpQuery query = NettyMocks.getQuery(tsdb, "");
HttpJsonSerializer serdes = new HttpJsonSerializer(query);
final TSQuery data_query = getTestQuery(false);
validateTestQuery(data_query);
final DataPoints dps = new MockDataPoints().getMock();
final List<DataPoints[]> results = new ArrayList<DataPoints[]>(1);
results.add(new DataPoints[] { dps });
when(dps.metricNameAsync()).thenReturn(Deferred.<String>fromError(new NoSuchUniqueId("No such metric", new byte[] { 0, 0, 1 })));
serdes.formatQueryAsyncV1(data_query, results, Collections.<Annotation>emptyList()).joinUninterruptibly();
}
use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.
the class MultiGetQuery method mergeDataPoints.
private void mergeDataPoints() {
for (List<KeyValue> kvs : kvsmap.values()) {
if (kvs == null || kvs.isEmpty()) {
LOG.error("Found a key value list that was null or empty");
continue;
}
for (final KeyValue kv : kvs) {
if (kv == null) {
LOG.error("Found a key value item that was null");
continue;
}
if (kv.key() == null) {
LOG.error("A key for a kv was null");
continue;
}
Span datapoints = null;
try {
datapoints = spans.get(kv.key());
} catch (RuntimeException e) {
LOG.error("Failed to fetch the span", e);
}
// non-compcated or out of order rows here
if (datapoints == null) {
datapoints = RollupQuery.isValidQuery(rollup_query) ? new RollupSpan(tsdb, rollup_query) : new Span(tsdb);
spans.put(kv.key(), datapoints);
}
if (annotMap.containsKey(kv.key())) {
for (Annotation note : annotMap.get(kv.key())) {
datapoints.getAnnotations().add(note);
}
annotMap.remove(kv.key());
}
try {
datapoints.addRow(kv);
} catch (RuntimeException e) {
LOG.error("Exception adding row to span", e);
}
}
}
kvsmap.clear();
for (byte[] key : annotMap.keySet()) {
Span datapoints = (Span) spans.get(key);
if (datapoints == null) {
datapoints = new Span(tsdb);
spans.put(key, datapoints);
}
for (Annotation note : annotMap.get(key)) {
datapoints.getAnnotations().add(note);
}
}
annotMap.clear();
}
use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.
the class TestTsdbQueryHistogramQueries method runWithAnnotation.
// end runSingleTsMsTwoAggSum()
@Test
public void runWithAnnotation() throws Exception {
this.storeTestHistogramTimeSeriesSeconds(false);
final Annotation note = new Annotation();
note.setTSUID(getTSUIDString(HISTOGRAM_METRIC_STRING, TAGK_STRING, TAGV_STRING));
note.setStartTime(1356998490);
note.setDescription("Hello World!");
note.syncToStorage(tsdb, false).joinUninterruptibly();
HashMap<String, String> tags = new HashMap<String, String>(1);
tags.put("host", "web01");
query.setStartTime(1356998400);
query.setEndTime(1357041600);
query.setTimeSeries("msg.end2end.latency", tags, Aggregators.SUM, false);
List<Float> percentiles = new ArrayList<Float>();
float per_98 = 0.98F;
percentiles.add(per_98);
query.setPercentiles(percentiles);
final DataPoints[] dps = query.runHistogram();
assertNotNull(dps);
assertEquals(1, dps[0].getAnnotations().size());
assertEquals("Hello World!", dps[0].getAnnotations().get(0).getDescription());
int value = 1;
for (DataPoint dp : dps[0]) {
assertEquals(value * 0.98, dp.doubleValue(), 0.0001);
value++;
}
assertEquals(300, dps[0].size());
}
use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.
the class SaltScanner method mergeDataPoints.
/**
* Called once all of the scanners have reported back in to record our
* latency and merge the results into the spans map. If there was an exception
* stored then we'll return that instead.
*/
private void mergeDataPoints() {
// Merge sorted spans together
final long merge_start = DateTime.nanoTime();
for (final List<KeyValue> kvs : kv_map.values()) {
if (kvs == null || kvs.isEmpty()) {
LOG.warn("Found a key value list that was null or empty");
continue;
}
for (final KeyValue kv : kvs) {
if (kv == null) {
LOG.warn("Found a key value item that was null");
continue;
}
if (kv.key() == null) {
LOG.warn("A key for a kv was null");
continue;
}
Span datapoints = spans.get(kv.key());
if (datapoints == null) {
datapoints = RollupQuery.isValidQuery(rollup_query) ? new RollupSpan(tsdb, this.rollup_query) : new Span(tsdb);
spans.put(kv.key(), datapoints);
}
if (annotation_map.containsKey(kv.key())) {
for (final Annotation note : annotation_map.get(kv.key())) {
datapoints.getAnnotations().add(note);
}
annotation_map.remove(kv.key());
}
try {
datapoints.addRow(kv);
} catch (RuntimeException e) {
LOG.error("Exception adding row to span", e);
throw e;
}
}
}
kv_map.clear();
for (final byte[] key : annotation_map.keySet()) {
Span datapoints = spans.get(key);
if (datapoints == null) {
datapoints = new Span(tsdb);
spans.put(key, datapoints);
}
for (final Annotation note : annotation_map.get(key)) {
datapoints.getAnnotations().add(note);
}
}
annotation_map.clear();
}
Aggregations