Search in sources :

Example 21 with RollupInterval

use of net.opentsdb.rollup.RollupInterval in project opentsdb by OpenTSDB.

the class TestTSDBAddAggregatePoint method addAggregatePointLongs.

@Test
public void addAggregatePointLongs() throws Exception {
    final RollupInterval interval = rollup_config.getRollupInterval("10m");
    // 1 byte
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, 0, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(0, storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 0, 0, interval))[0]);
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, 42, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(42, storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 0, 0, interval))[0]);
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, -42, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(-42, storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 0, 0, interval))[0]);
    // 2 bytes
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, 257, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(257, Bytes.getShort(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 1, 0, interval))));
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, -257, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(-257, Bytes.getShort(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 1, 0, interval))));
    // 4 bytes
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, 65537, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(65537, Bytes.getInt(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 3, 0, interval))));
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, -65537, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(-65537, Bytes.getInt(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 3, 0, interval))));
    // 8 bytes
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, 4294967296L, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(4294967296L, Bytes.getLong(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 7, 0, interval))));
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, -4294967296L, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(-4294967296L, Bytes.getLong(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 7, 0, interval))));
}
Also used : RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test)

Example 22 with RollupInterval

use of net.opentsdb.rollup.RollupInterval in project opentsdb by OpenTSDB.

the class TestTSDBAddAggregatePoint method addAggregatePointFloats.

@Test
public void addAggregatePointFloats() throws Exception {
    final RollupInterval interval = rollup_config.getRollupInterval("10m");
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, 0.0F, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(0.0, Float.intBitsToFloat(Bytes.getInt(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 11, 0, interval)))), 0.0001);
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, 42.5F, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(42.5, Float.intBitsToFloat(Bytes.getInt(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 11, 0, interval)))), 0.0001);
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, -42.5F, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(-42.5, Float.intBitsToFloat(Bytes.getInt(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 11, 0, interval)))), 0.0001);
    tsdb.addAggregatePoint(METRIC_STRING, 1356998400, 42.5123459999F, tags, false, "10m", "sum", null).joinUninterruptibly();
    assertEquals(42.5123459999F, Float.intBitsToFloat(Bytes.getInt(storage.getColumn(interval.getTemporalTable(), row, FAMILY, RollupUtils.buildRollupQualifier(1356998400, (short) 11, 0, interval)))), 0.0000001);
}
Also used : RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test)

Example 23 with RollupInterval

use of net.opentsdb.rollup.RollupInterval in project opentsdb by OpenTSDB.

the class TestFillingDownsampler method testDownsampler_rollupCountMissing.

@Test
public void testDownsampler_rollupCountMissing() {
    final RollupInterval interval = RollupInterval.builder().setTable("tsdb-rollup-1h").setPreAggregationTable("tsdb-agg-rollup-1h").setInterval("1h").setRowSpan("1d").build();
    final RollupQuery rollup_query = new RollupQuery(interval, Aggregators.SUM, 3600000, Aggregators.SUM);
    final long baseTime = 500L;
    final SeekableView source = SeekableViewsForTest.fromArray(new DataPoint[] { MutableDataPoint.ofDoubleValue(baseTime + 25L * 4L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 5L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 7L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 12L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 15L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 24L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 25L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 26L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 27L, 1.) });
    specification = new DownsamplingSpecification("100ms-count-nan");
    final Downsampler downsampler = new FillingDownsampler(source, baseTime, baseTime + 36 * 25L, specification, 0, 0, rollup_query);
    long timestamp = baseTime;
    step(downsampler, timestamp, Double.NaN);
    step(downsampler, timestamp += 100, 3.);
    step(downsampler, timestamp += 100, Double.NaN);
    step(downsampler, timestamp += 100, 2.);
    step(downsampler, timestamp += 100, Double.NaN);
    step(downsampler, timestamp += 100, Double.NaN);
    step(downsampler, timestamp += 100, 4.);
    step(downsampler, timestamp += 100, Double.NaN);
    step(downsampler, timestamp += 100, Double.NaN);
    assertFalse(downsampler.hasNext());
}
Also used : MockSeekableView(net.opentsdb.core.SeekableViewsForTest.MockSeekableView) RollupQuery(net.opentsdb.rollup.RollupQuery) RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test)

Example 24 with RollupInterval

use of net.opentsdb.rollup.RollupInterval in project opentsdb by OpenTSDB.

the class TestFillingDownsampler method testDownsampler_rollupCount.

@Test
public void testDownsampler_rollupCount() {
    final RollupInterval interval = RollupInterval.builder().setTable("tsdb-rollup-1h").setPreAggregationTable("tsdb-agg-rollup-1h").setInterval("1h").setRowSpan("1d").build();
    // This query, in combination with the configuration/interval above, is asking for rolled up COUNTs (i.e. already
    // downsampled).  These COUNTs should then be SUMmed over some interval we'll define later in a DownsamplingSpecification
    final RollupQuery rollup_query = new RollupQuery(interval, Aggregators.COUNT, 3600000, Aggregators.SUM);
    final long baseTime = 1000L;
    // These points represent rolled up COUNTs that would be stored in the rollup table (e.g. tsdb-rollup-1h) and as
    // such we don't expect these to be COUNTed again on retrieval.  These points are at 25ms intervals
    final SeekableView source = SeekableViewsForTest.fromArray(new DataPoint[] { MutableDataPoint.ofDoubleValue(baseTime + 25L * 0L, 12.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 1L, 11.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 2L, 10.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 3L, 9.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 4L, 8.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 5L, 7.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 6L, 6.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 7L, 5.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 8L, 4.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 9L, 3.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 10L, 2.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 11L, 1.) });
    // The rolled up points above are at 25ms intervals but we want to downsample these further so that we only get
    // points at 100ms intervals
    specification = new DownsamplingSpecification("100ms-count-nan");
    final Downsampler downsampler = new FillingDownsampler(source, baseTime, baseTime + 12L * 25L, specification, 0, 0, rollup_query);
    long timestamp = baseTime;
    // Expect the SUM of points 1 to 4
    step(downsampler, timestamp, 42);
    // Expect the SUM of points 5 to 8
    step(downsampler, timestamp += 100, 26);
    // Expect the SUM of points 9 to 12
    step(downsampler, timestamp += 100, 10);
    assertFalse(downsampler.hasNext());
}
Also used : MockSeekableView(net.opentsdb.core.SeekableViewsForTest.MockSeekableView) RollupQuery(net.opentsdb.rollup.RollupQuery) RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test)

Example 25 with RollupInterval

use of net.opentsdb.rollup.RollupInterval in project opentsdb by OpenTSDB.

the class TestFillingDownsampler method testDownsampler_rollupAvgMissing.

@Test
public void testDownsampler_rollupAvgMissing() {
    final RollupInterval interval = RollupInterval.builder().setTable("tsdb-rollup-1h").setPreAggregationTable("tsdb-agg-rollup-1h").setInterval("1h").setRowSpan("1d").build();
    final RollupQuery rollup_query = new RollupQuery(interval, Aggregators.SUM, 3600000, Aggregators.SUM);
    final long baseTime = 500L;
    final SeekableView source = SeekableViewsForTest.fromArray(new DataPoint[] { MutableDataPoint.ofDoubleValue(baseTime + 25L * 4L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 5L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 7L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 12L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 15L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 24L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 25L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 26L, 1.), MutableDataPoint.ofDoubleValue(baseTime + 25L * 27L, 1.) });
    specification = new DownsamplingSpecification("100ms-avg-nan");
    final Downsampler downsampler = new FillingDownsampler(source, baseTime, baseTime + 36 * 25L, specification, 0, 0, rollup_query);
    long timestamp = baseTime;
    step(downsampler, timestamp, Double.NaN);
    step(downsampler, timestamp += 100, 1.);
    step(downsampler, timestamp += 100, Double.NaN);
    step(downsampler, timestamp += 100, 1);
    step(downsampler, timestamp += 100, Double.NaN);
    step(downsampler, timestamp += 100, Double.NaN);
    step(downsampler, timestamp += 100, 1.);
    step(downsampler, timestamp += 100, Double.NaN);
    step(downsampler, timestamp += 100, Double.NaN);
    assertFalse(downsampler.hasNext());
}
Also used : MockSeekableView(net.opentsdb.core.SeekableViewsForTest.MockSeekableView) RollupQuery(net.opentsdb.rollup.RollupQuery) RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test)

Aggregations

RollupInterval (net.opentsdb.rollup.RollupInterval)45 Test (org.junit.Test)42 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)26 RollupQuery (net.opentsdb.rollup.RollupQuery)14 MockSeekableView (net.opentsdb.core.SeekableViewsForTest.MockSeekableView)7 ArrayList (java.util.ArrayList)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Callback (com.stumbleupon.async.Callback)1 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NoSuchElementException (java.util.NoSuchElementException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 TagVLiteralOrFilter (net.opentsdb.query.filter.TagVLiteralOrFilter)1 RollupConfig (net.opentsdb.rollup.RollupConfig)1 HBaseException (org.hbase.async.HBaseException)1 PutRequest (org.hbase.async.PutRequest)1 TableNotFoundException (org.hbase.async.TableNotFoundException)1