Search in sources :

Example 16 with RollupInterval

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

the class TestDownsampler method testDownsampler_rollupSum.

@Test
public void testDownsampler_rollupSum() {
    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);
    source = spy(SeekableViewsForTest.fromArray(new DataPoint[] { MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 0, 1), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 1, 2), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 2, 4), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 3, 8), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 4, 16), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 5, 32), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 6, 64), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 7, 128), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 8, 256), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 9, 512), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 10, 1024) }));
    specification = new DownsamplingSpecification("10s-sum");
    downsampler = new Downsampler(source, specification, 0, 0, rollup_query);
    verify(source, never()).next();
    List<Double> values = Lists.newArrayList();
    List<Long> timestamps_in_millis = Lists.newArrayList();
    while (downsampler.hasNext()) {
        DataPoint dp = downsampler.next();
        assertFalse(dp.isInteger());
        values.add(dp.doubleValue());
        timestamps_in_millis.add(dp.timestamp());
    }
    assertEquals(6, values.size());
    assertEquals(3, values.get(0), 0.0000001);
    assertEquals(BASE_TIME + 00000L, timestamps_in_millis.get(0).longValue());
    assertEquals(12, values.get(1), 0.0000001);
    assertEquals(BASE_TIME + 10000L, timestamps_in_millis.get(1).longValue());
    assertEquals(48, values.get(2), 0.0000001);
    assertEquals(BASE_TIME + 20000L, timestamps_in_millis.get(2).longValue());
    assertEquals(192, values.get(3), 0.0000001);
    assertEquals(BASE_TIME + 30000L, timestamps_in_millis.get(3).longValue());
    assertEquals(768, values.get(4), 0.0000001);
    assertEquals(BASE_TIME + 40000L, timestamps_in_millis.get(4).longValue());
    assertEquals(1024, values.get(5), 0.0000001);
    assertEquals(BASE_TIME + 50000L, timestamps_in_millis.get(5).longValue());
}
Also used : RollupQuery(net.opentsdb.rollup.RollupQuery) RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test)

Example 17 with RollupInterval

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

the class TestDownsampler 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);
    // 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 5s intervals
    source = spy(SeekableViewsForTest.fromArray(new DataPoint[] { MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 0, 1), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 1, 2), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 2, 4), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 3, 8) }));
    // The rolled up points above are at 5s intervals but we want to downsample these further so that we only get
    // points at 10s intervals
    specification = new DownsamplingSpecification("10s-count");
    downsampler = new Downsampler(source, specification, 0, 0, rollup_query);
    verify(source, never()).next();
    List<Double> values = Lists.newArrayList();
    List<Long> timestamps_in_millis = Lists.newArrayList();
    while (downsampler.hasNext()) {
        DataPoint dp = downsampler.next();
        assertFalse(dp.isInteger());
        values.add(dp.doubleValue());
        timestamps_in_millis.add(dp.timestamp());
    }
    // Asserts here different to upstream as there is a bug upstream and the original test was written to pass with the bug.
    // 2 points are expected because the 4 points at 5s intervals will be downsampled to 2 points at 10s intervals
    assertEquals(2, values.size());
    // Expect the SUM of points 1 and 2
    assertEquals(3, values.get(0), 0.0000001);
    assertEquals(BASE_TIME + 00000L, timestamps_in_millis.get(0).longValue());
    // Expect the SUM of points 3 and 4
    assertEquals(12, values.get(1), 0.0000001);
    assertEquals(BASE_TIME + 10000L, timestamps_in_millis.get(1).longValue());
}
Also used : RollupQuery(net.opentsdb.rollup.RollupQuery) RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test)

Example 18 with RollupInterval

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

the class TestDownsampler method testDownsampler_rollupAvg.

@Test
public void testDownsampler_rollupAvg() {
    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.AVG, 3600000, Aggregators.SUM);
    source = spy(SeekableViewsForTest.fromArray(new DataPoint[] { MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 0, 1), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 1, 2), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 2, 4), MutableDataPoint.ofDoubleValue(BASE_TIME + 5000L * 3, 8) }));
    specification = new DownsamplingSpecification("10s-avg");
    downsampler = new Downsampler(source, specification, 0, 0, rollup_query);
    verify(source, never()).next();
    List<Double> values = Lists.newArrayList();
    List<Long> timestamps_in_millis = Lists.newArrayList();
    while (downsampler.hasNext()) {
        DataPoint dp = downsampler.next();
        assertFalse(dp.isInteger());
        values.add(dp.doubleValue());
        timestamps_in_millis.add(dp.timestamp());
    }
    assertEquals(2, values.size());
    assertEquals(1.5, values.get(0), 0.0000001);
    assertEquals(BASE_TIME + 00000L, timestamps_in_millis.get(0).longValue());
    assertEquals(6, values.get(1), 0.0000001);
    assertEquals(BASE_TIME + 10000L, timestamps_in_millis.get(1).longValue());
}
Also used : RollupQuery(net.opentsdb.rollup.RollupQuery) RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test)

Example 19 with RollupInterval

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

the class TestDownsampler method testDownsampler_rollupDev.

@Test(expected = UnsupportedOperationException.class)
public void testDownsampler_rollupDev() {
    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.DEV, 3600000, Aggregators.SUM);
    specification = new DownsamplingSpecification("10s-dev");
    downsampler = new Downsampler(source, specification, 0, 0, rollup_query);
    while (downsampler.hasNext()) {
        // <-- throws here
        downsampler.next();
    }
}
Also used : RollupQuery(net.opentsdb.rollup.RollupQuery) RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test)

Example 20 with RollupInterval

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

the class TestFillingDownsampler method testDownsampler_rollupDev.

@Test(expected = UnsupportedOperationException.class)
public void testDownsampler_rollupDev() {
    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.DEV, 3600000, Aggregators.SUM);
    final long baseTime = 1000L;
    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.) });
    specification = new DownsamplingSpecification("100ms-dev-nan");
    final Downsampler downsampler = new FillingDownsampler(source, baseTime, baseTime + 12L * 25L, specification, 0, 0, rollup_query);
    while (downsampler.hasNext()) {
        // <-- throws here
        downsampler.next();
    }
}
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