Search in sources :

Example 1 with Annotation

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\":"));
}
Also used : TSQuery(net.opentsdb.core.TSQuery) MockDataPoints(net.opentsdb.storage.MockDataPoints) ArrayList(java.util.ArrayList) DataPoints(net.opentsdb.core.DataPoints) MockDataPoints(net.opentsdb.storage.MockDataPoints) Matchers.anyString(org.mockito.Matchers.anyString) Annotation(net.opentsdb.meta.Annotation) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with Annotation

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();
}
Also used : TSQuery(net.opentsdb.core.TSQuery) MockDataPoints(net.opentsdb.storage.MockDataPoints) NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) ArrayList(java.util.ArrayList) DataPoints(net.opentsdb.core.DataPoints) MockDataPoints(net.opentsdb.storage.MockDataPoints) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with Annotation

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();
}
Also used : KeyValue(org.hbase.async.KeyValue) RollupSpan(net.opentsdb.rollup.RollupSpan) RollupSpan(net.opentsdb.rollup.RollupSpan) Annotation(net.opentsdb.meta.Annotation)

Example 4 with Annotation

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Annotation(net.opentsdb.meta.Annotation) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with Annotation

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();
}
Also used : KeyValue(org.hbase.async.KeyValue) RollupSpan(net.opentsdb.rollup.RollupSpan) RollupSpan(net.opentsdb.rollup.RollupSpan) Annotation(net.opentsdb.meta.Annotation)

Aggregations

Annotation (net.opentsdb.meta.Annotation)83 ArrayList (java.util.ArrayList)71 Test (org.junit.Test)66 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)66 KeyValue (org.hbase.async.KeyValue)53 DataPoints (net.opentsdb.core.DataPoints)18 TSQuery (net.opentsdb.core.TSQuery)15 MockDataPoints (net.opentsdb.storage.MockDataPoints)13 Matchers.anyString (org.mockito.Matchers.anyString)12 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)10 HashMap (java.util.HashMap)6 Deferred (com.stumbleupon.async.Deferred)5 IOException (java.io.IOException)5 Callback (com.stumbleupon.async.Callback)4 List (java.util.List)4 DataPoint (net.opentsdb.core.DataPoint)4 NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)3 Map (java.util.Map)2 IncomingDataPoint (net.opentsdb.core.IncomingDataPoint)2 Query (net.opentsdb.core.Query)2