Search in sources :

Example 1 with RollupInterval

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

the class TestTsdbQueryQueries method runRollupFiltering.

@Test
public void runRollupFiltering() throws Exception {
    storeLongTimeSeriesSeconds(false, false);
    final List<byte[]> families = new ArrayList<byte[]>();
    families.add("t".getBytes(MockBase.ASCII()));
    storage.addTable("tsdb-agg".getBytes(), families);
    setupGroupByTagValues();
    long start_timestamp = 1559347200L;
    RollupInterval defaultInterval = RollupInterval.builder().setTable("tsdb").setPreAggregationTable("tsdb-agg").setInterval("1m").setRowSpan("1h").build();
    RollupInterval rollupInterval = RollupInterval.builder().setTable("tsdb-agg").setPreAggregationTable("tsdb-agg").setInterval("1h").setRowSpan("1d").build();
    Whitebox.setInternalState(tsdb, "default_interval", defaultInterval);
    RollupConfig rollupConfig = RollupConfig.builder().setAggregationIds(new HashMap<String, Integer>() {

        {
            put("sum", 0);
            put("count", 1);
            put("min", 2);
            put("max", 3);
            put("avg", 4);
        }
    }).setIntervals(Arrays.asList(defaultInterval, rollupInterval)).build();
    Whitebox.setInternalState(tsdb, "default_interval", defaultInterval);
    Whitebox.setInternalState(tsdb, "rollup_config", rollupConfig);
    this.tsdb.addAggregatePoint(METRIC_STRING, start_timestamp, 42L, new HashMap<String, String>() {

        {
            put("host", "web01");
        }
    }, false, "1h", "sum", null);
    this.tsdb.addAggregatePoint(METRIC_STRING, start_timestamp, 42L, new HashMap<String, String>() {

        {
            put("host", "web02");
        }
    }, false, "1h", "sum", null);
    this.tsdb.addAggregatePoint(METRIC_STRING, start_timestamp, 42L, new HashMap<String, String>() {

        {
            put("host", "web01");
        }
    }, false, "1h", "count", null);
    this.tsdb.addAggregatePoint(METRIC_STRING, start_timestamp, 42L, new HashMap<String, String>() {

        {
            put("host", "web02");
        }
    }, false, "1h", "count", null);
    TSQuery ts_query = new TSQuery();
    ts_query.setStart("1559343600");
    ts_query.setEnd("1559350800");
    final TSSubQuery sub = new TSSubQuery();
    sub.setMetric(METRIC_STRING);
    sub.setAggregator("sum");
    sub.setDownsample("1h-sum");
    sub.setFilters(Lists.<TagVFilter>newArrayList(new TagVLiteralOrFilter("host", TAGV_STRING)));
    ts_query.setQueries(Arrays.asList(sub));
    ts_query.validateAndSetQuery();
    query.configureFromQuery(ts_query, 0);
    final DataPoints[] dps = query.run();
    assertEquals(1, dps.length);
    assertEquals(1, dps[0].aggregatedSize());
    assertEquals(METRIC_STRING, dps[0].metricName());
    assertTrue(dps[0].getAggregatedTags().isEmpty());
    assertNull(dps[0].getAnnotations());
    assertEquals(TAGV_STRING, dps[0].getTags().get(TAGK_STRING));
    long ts = start_timestamp * 1000;
    final DataPoint dp = dps[0].iterator().next();
    assertEquals(42, dp.doubleValue(), 0);
    assertEquals(ts, dp.timestamp());
    assertEquals(1, dps[0].size());
}
Also used : ArrayList(java.util.ArrayList) RollupConfig(net.opentsdb.rollup.RollupConfig) TagVLiteralOrFilter(net.opentsdb.query.filter.TagVLiteralOrFilter) RollupInterval(net.opentsdb.rollup.RollupInterval) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with RollupInterval

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

the class TestTsdbQueryRollup method run10mAvgLongSingleTSMissingSum.

@Test
public void run10mAvgLongSingleTSMissingSum() throws Exception {
    final RollupInterval interval = rollup_config.getRollupInterval("10m");
    final Aggregator aggr = Aggregators.AVG;
    long start_timestamp = 1356998400L;
    long end_timestamp = 1357041600L;
    storeCount(start_timestamp, end_timestamp, false, false, interval, 1);
    setQuery(interval.getInterval(), aggr, tags, aggr);
    query.configureFromQuery(ts_query, 0);
    final DataPoints[] dps = query.run();
    assertEquals(1, dps.length);
    assertEquals("", dps[0].metricName());
    assertTrue(dps[0].getAggregatedTags().isEmpty());
    assertNull(dps[0].getAnnotations());
    assertNull(dps[0].getTags().get(TAGK_STRING));
    assertFalse(dps[0].iterator().hasNext());
    assertEquals(0, dps[0].size());
}
Also used : RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with RollupInterval

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

the class TestTsdbQueryRollup method run10mMaxLongSingleTSNotFound.

@Test
public void run10mMaxLongSingleTSNotFound() throws Exception {
    final RollupInterval interval = rollup_config.getRollupInterval("10m");
    Aggregator aggr = Aggregators.SUM;
    long start_timestamp = 1356998400L;
    long end_timestamp = 1357041599L;
    storeLongRollup(start_timestamp, end_timestamp, false, false, interval, aggr);
    aggr = Aggregators.MAX;
    setQuery(interval.getInterval(), aggr, tags, aggr);
    query.configureFromQuery(ts_query, 0);
    final DataPoints[] dps = query.run();
    assertEquals(0, dps.length);
}
Also used : RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with RollupInterval

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

the class TestTsdbQueryRollup method run10mAvgLongSingleTSMissingToZeroOneSpan.

@Test
public void run10mAvgLongSingleTSMissingToZeroOneSpan() throws Exception {
    final RollupInterval interval = rollup_config.getRollupInterval("10m");
    // For this test, a span in the middle was zero'd out
    storePoint(1356998400, 20, Aggregators.SUM, interval);
    storePoint(1356998400, 2, Aggregators.COUNT, interval);
    storePoint(1356999000, 40, Aggregators.SUM, interval);
    storePoint(1356999000, 5, Aggregators.COUNT, interval);
    storePoint(1357084800, 60, Aggregators.SUM, interval);
    // storePoint(1357084800, 3, Aggregators.COUNT, interval);
    // storePoint(1357085400, 80, Aggregators.SUM, interval);
    storePoint(1357085400, 4, Aggregators.COUNT, interval);
    storePoint(1357171200, 90, Aggregators.SUM, interval);
    storePoint(1357171200, 3, Aggregators.COUNT, interval);
    storePoint(1357171800, 100, Aggregators.SUM, interval);
    storePoint(1357171800, 5, Aggregators.COUNT, interval);
    Aggregator aggr = Aggregators.AVG;
    setQuery(interval.getInterval(), aggr, tags, aggr);
    ts_query.setEnd("1359590400");
    ts_query.validateAndSetQuery();
    query.configureFromQuery(ts_query, 0);
    final DataPoints[] dps = query.run();
    assertEquals(1, dps.length);
    assertEquals(METRIC_STRING, dps[0].metricName());
    assertTrue(dps[0].getAggregatedTags().isEmpty());
    assertNull(dps[0].getAnnotations());
    assertEquals(TAGV_STRING, dps[0].getTags().get(TAGK_STRING));
    final SeekableView it = dps[0].iterator();
    DataPoint dp = it.next();
    assertEquals(1356998400000L, dp.timestamp());
    assertEquals(10, dp.doubleValue(), 0.0001);
    dp = it.next();
    assertEquals(1356999000000L, dp.timestamp());
    assertEquals(8, dp.doubleValue(), 0.0001);
    dp = it.next();
    assertEquals(1357171200000L, dp.timestamp());
    assertEquals(30, dp.doubleValue(), 0.0001);
    dp = it.next();
    assertEquals(1357171800000L, dp.timestamp());
    assertEquals(20, dp.doubleValue(), 0.0001);
    assertFalse(it.hasNext());
    assertEquals(4, dps[0].size());
}
Also used : RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with RollupInterval

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

the class TestTsdbQueryRollup method run10mSumLongDoubleTSFilterOtherAggs.

// Make sure other aggregates don't polute our results
@Test
public void run10mSumLongDoubleTSFilterOtherAggs() throws Exception {
    final RollupInterval interval = rollup_config.getRollupInterval("10m");
    final Aggregator aggr = Aggregators.SUM;
    long start_timestamp = 1356998400L;
    long end_timestamp = 1357041600L;
    storeLongRollup(1356998400L, end_timestamp, true, false, interval, aggr);
    storeLongRollup(1356998400L, end_timestamp, true, false, interval, Aggregators.MAX);
    storeLongRollup(1356998400L, end_timestamp, true, false, interval, Aggregators.MIN);
    final int time_interval = interval.getIntervalSeconds();
    setQuery(interval.getInterval(), aggr, tags, aggr);
    query.configureFromQuery(ts_query, 0);
    final DataPoints[] dps = query.run();
    assertEquals(1, dps.length);
    assertEquals(METRIC_STRING, dps[0].metricName());
    assertTrue(dps[0].getAggregatedTags().isEmpty());
    assertNull(dps[0].getAnnotations());
    assertEquals(TAGV_STRING, dps[0].getTags().get(TAGK_STRING));
    int i = 600;
    long ts = start_timestamp * 1000;
    for (final DataPoint dp : dps[0]) {
        assertFalse(dp.isInteger());
        assertEquals(i, dp.doubleValue(), 0.0001);
        assertEquals(ts, dp.timestamp());
        ts += time_interval * 1000;
        i += time_interval;
    }
    assertEquals(73, dps[0].size());
}
Also used : RollupInterval(net.opentsdb.rollup.RollupInterval) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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