Search in sources :

Example 36 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method appendsDuplicateCompacted.

@Test
public void appendsDuplicateCompacted() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(1);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    final byte[] qual = { 0x00, 0x07 };
    final byte[] val = Bytes.fromLong(42L);
    final byte[] qual2 = { 0x00, 0x17 };
    final byte[] val2 = Bytes.fromLong(5L);
    kvs.add(makekv(AppendDataPoints.APPEND_COLUMN_QUALIFIER, MockBase.concatByteArrays(qual, val, qual2, val2)));
    kvs.add(makekv(MockBase.concatByteArrays(qual, qual2), MockBase.concatByteArrays(val, val2, ZERO)));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual, qual2), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val, val2, ZERO), kv.value());
    // We had nothing to do so...
    // ... verify there were no put.
    verify(tsdb, never()).put(anyBytes(), anyBytes(), anyBytes());
    // ... verify there were no delete.
    verify(tsdb, never()).delete(anyBytes(), any(byte[][].class));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method emptyRow.

@Test
public void emptyRow() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(0);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertNull(kv);
    // We had nothing to do so...
    // ... verify there were no put.
    verify(tsdb, never()).put(anyBytes(), anyBytes(), anyBytes());
    // ... verify there were no delete.
    verify(tsdb, never()).delete(anyBytes(), any(byte[][].class));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method oneCellAppendWAnnotiation.

@Test
public void oneCellAppendWAnnotiation() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(1);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(1);
    kvs.add(makekv(note_qual, note));
    final byte[] qual = { 0x00, 0x07 };
    final byte[] val = Bytes.fromLong(42L);
    kvs.add(makekv(AppendDataPoints.APPEND_COLUMN_QUALIFIER, MockBase.concatByteArrays(qual, val)));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(qual, kv.qualifier());
    assertArrayEquals(val, kv.value());
    assertEquals(1, annotations.size());
    // We had nothing to do so...
    // ... verify there were no put.
    verify(tsdb, never()).put(anyBytes(), anyBytes(), anyBytes());
    // ... verify there were no delete.
    verify(tsdb, never()).delete(anyBytes(), any(byte[][].class));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method oneCellAppend.

@Test
public void oneCellAppend() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(1);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    final byte[] qual = { 0x00, 0x07 };
    final byte[] val = Bytes.fromLong(42L);
    kvs.add(makekv(AppendDataPoints.APPEND_COLUMN_QUALIFIER, MockBase.concatByteArrays(qual, val)));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(qual, kv.qualifier());
    assertArrayEquals(val, kv.value());
    // We had nothing to do so...
    // ... verify there were no put.
    verify(tsdb, never()).put(anyBytes(), anyBytes(), anyBytes());
    // ... verify there were no delete.
    verify(tsdb, never()).delete(anyBytes(), any(byte[][].class));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 40 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class Plot method writeGnuplotScript.

/**
   * Generates the Gnuplot script.
   * @param basepath The base path to use.
   * @param datafiles The names of the data files that need to be plotted,
   * in the order in which they ought to be plotted.  It is assumed that
   * the ith file will correspond to the ith entry in {@code datapoints}.
   * Can be {@code null} if there's no data to plot.
   */
private void writeGnuplotScript(final String basepath, final String[] datafiles) throws IOException {
    final String script_path = basepath + ".gnuplot";
    final PrintWriter gp = new PrintWriter(script_path);
    try {
        // XXX don't hardcode all those settings.  At least not like that.
        gp.append("set term png small size ").append(Short.toString(width)).append(",").append(Short.toString(height));
        final String smooth = params.remove("smooth");
        final String fgcolor = params.remove("fgcolor");
        final String style = params.remove("style");
        String bgcolor = params.remove("bgcolor");
        if (fgcolor != null && bgcolor == null) {
            // We can't specify a fgcolor without specifying a bgcolor.
            // So use a default.
            bgcolor = "xFFFFFF";
        }
        if (bgcolor != null) {
            if (fgcolor != null && "transparent".equals(bgcolor)) {
                // In case we need to specify a fgcolor but we wanted a transparent
                // background, we also need to pass a bgcolor otherwise the first
                // hex color will be mistakenly taken as a bgcolor by Gnuplot.
                bgcolor = "transparent xFFFFFF";
            }
            gp.append(' ').append(bgcolor);
        }
        if (fgcolor != null) {
            gp.append(' ').append(fgcolor);
        }
        gp.append("\n" + "set xdata time\n" + "set timefmt \"%s\"\n" + "if (GPVAL_VERSION < 4.6) set xtics rotate; else set xtics rotate right\n" + "set output \"").append(basepath + ".png").append("\"\n" + "set xrange [\"").append(String.valueOf((start_time & UNSIGNED) + utc_offset)).append("\":\"").append(String.valueOf((end_time & UNSIGNED) + utc_offset)).append("\"]\n");
        if (!params.containsKey("format x")) {
            gp.append("set format x \"").append(xFormat()).append("\"\n");
        }
        final int nseries = datapoints.size();
        if (nseries > 0) {
            gp.write("set grid\n" + "set style data ");
            gp.append(style != null ? style : "linespoint").append("\n");
            if (!params.containsKey("key")) {
                gp.write("set key right box\n");
            }
        } else {
            gp.write("unset key\n");
            if (params == null || !params.containsKey("label")) {
                gp.write("set label \"No data\" at graph 0.5,0.9 center\n");
            }
        }
        if (params != null) {
            for (final Map.Entry<String, String> entry : params.entrySet()) {
                final String key = entry.getKey();
                final String value = entry.getValue();
                if (value != null) {
                    gp.append("set ").append(key).append(' ').append(value).write('\n');
                } else {
                    gp.append("unset ").append(key).write('\n');
                }
            }
        }
        for (final String opts : options) {
            if (opts.contains("x1y2")) {
                // Create a second scale for the y-axis on the right-hand side.
                gp.write("set y2tics border\n");
                break;
            }
        }
        // compile annotations to determine if we have any to graph
        final List<Annotation> notes = new ArrayList<Annotation>();
        for (int i = 0; i < nseries; i++) {
            final DataPoints dp = datapoints.get(i);
            final List<Annotation> series_notes = dp.getAnnotations();
            if (series_notes != null && !series_notes.isEmpty()) {
                notes.addAll(series_notes);
            }
        }
        if (globals != null) {
            notes.addAll(globals);
        }
        if (notes.size() > 0) {
            Collections.sort(notes);
            for (Annotation note : notes) {
                String ts = Long.toString(note.getStartTime());
                String value = new String(note.getDescription());
                gp.append("set arrow from \"").append(ts).append("\", graph 0 to \"");
                gp.append(ts).append("\", graph 1 nohead ls 3\n");
                gp.append("set object rectangle at \"").append(ts);
                gp.append("\", graph 0 size char (strlen(\"").append(value);
                gp.append("\")), char 1 front fc rgbcolor \"white\"\n");
                gp.append("set label \"").append(value).append("\" at \"");
                gp.append(ts).append("\", graph 0 front center\n");
            }
        }
        gp.write("plot ");
        for (int i = 0; i < nseries; i++) {
            final DataPoints dp = datapoints.get(i);
            final String title = dp.metricName() + dp.getTags();
            gp.append(" \"").append(datafiles[i]).append("\" using 1:2");
            if (smooth != null) {
                gp.append(" smooth ").append(smooth);
            }
            // TODO(tsuna): Escape double quotes in title.
            gp.append(" title \"").append(title).write('"');
            final String opts = options.get(i);
            if (!opts.isEmpty()) {
                gp.append(' ').write(opts);
            }
            if (i != nseries - 1) {
                gp.print(", \\");
            }
            gp.write('\n');
        }
        if (nseries == 0) {
            gp.write('0');
        }
    } finally {
        gp.close();
        LOG.info("Wrote Gnuplot script to " + script_path);
    }
}
Also used : ArrayList(java.util.ArrayList) DataPoints(net.opentsdb.core.DataPoints) Map(java.util.Map) DataPoint(net.opentsdb.core.DataPoint) Annotation(net.opentsdb.meta.Annotation) PrintWriter(java.io.PrintWriter)

Aggregations

Annotation (net.opentsdb.meta.Annotation)77 ArrayList (java.util.ArrayList)68 Test (org.junit.Test)63 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)63 KeyValue (org.hbase.async.KeyValue)50 DataPoints (net.opentsdb.core.DataPoints)18 TSQuery (net.opentsdb.core.TSQuery)15 MockDataPoints (net.opentsdb.storage.MockDataPoints)13 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)10 Matchers.anyString (org.mockito.Matchers.anyString)10 Deferred (com.stumbleupon.async.Deferred)5 IOException (java.io.IOException)5 Callback (com.stumbleupon.async.Callback)4 HashMap (java.util.HashMap)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