use of net.opentsdb.rollup.RollupQuery in project opentsdb by OpenTSDB.
the class TestFillingDownsampler 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);
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-avg-nan");
final Downsampler downsampler = new FillingDownsampler(source, baseTime, baseTime + 12L * 25L, specification, 0, 0, rollup_query);
long timestamp = baseTime;
step(downsampler, timestamp, 10.5);
step(downsampler, timestamp += 100, 6.5);
step(downsampler, timestamp += 100, 2.5);
assertFalse(downsampler.hasNext());
}
use of net.opentsdb.rollup.RollupQuery in project opentsdb by OpenTSDB.
the class TestMultiGetQuery method prepareRowBaseTimesRollup.
@Test
public void prepareRowBaseTimesRollup() throws Exception {
RollupInterval interval = RollupInterval.builder().setTable("tsdb").setPreAggregationTable("tsdb_agg").setInterval("1m").setRowSpan("1h").build();
RollupQuery rq = new RollupQuery(interval, aggregator, 0, aggregator);
MultiGetQuery mgq = new MultiGetQuery(tsdb, query, METRIC_BYTES, q_tags, start_ts, end_ts, tsdb.dataTable(), spans, null, 0, rq, query_stats, 0, max_bytes, false, multiget_no_meta);
List<Long> timestamps = mgq.prepareRowBaseTimesRollup();
assertEquals(17, timestamps.size());
long expected = 1481227200;
for (final long ts : timestamps) {
assertEquals(expected, ts);
expected += 3600;
}
interval = RollupInterval.builder().setTable("tsdb").setPreAggregationTable("tsdb_agg").setInterval("1m").setRowSpan("1d").build();
rq = new RollupQuery(interval, aggregator, 0, aggregator);
mgq = new MultiGetQuery(tsdb, query, METRIC_BYTES, q_tags, start_ts, end_ts, tsdb.dataTable(), spans, null, 0, rq, query_stats, 0, max_bytes, false, multiget_no_meta);
timestamps = mgq.prepareRowBaseTimesRollup();
timestamps = mgq.prepareRowBaseTimesRollup();
assertEquals(2, timestamps.size());
expected = 1481155200;
for (final long ts : timestamps) {
assertEquals(expected, ts);
expected += 86400;
}
}
use of net.opentsdb.rollup.RollupQuery in project opentsdb by OpenTSDB.
the class TestFillingDownsampler method testDownsampler_rollupMissing.
@Test
public void testDownsampler_rollupMissing() {
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-sum-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());
}
use of net.opentsdb.rollup.RollupQuery in project opentsdb by OpenTSDB.
the class TestFillingDownsampler method testDownsampler_rollup.
@Test
public void testDownsampler_rollup() {
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 = 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-sum-nan");
final Downsampler downsampler = new FillingDownsampler(source, baseTime, baseTime + 12L * 25L, specification, 0, 0, rollup_query);
long timestamp = baseTime;
step(downsampler, timestamp, 42.);
step(downsampler, timestamp += 100, 26.);
step(downsampler, timestamp += 100, 10.);
assertFalse(downsampler.hasNext());
}
use of net.opentsdb.rollup.RollupQuery in project opentsdb by OpenTSDB.
the class TsdbQuery method transformDownSamplerToRollupQuery.
/**
* Transform downsampler properties to rollup properties, if the rollup
* is enabled at configuration level and down sampler is set.
* It falls back to raw data and down sampling if there is no
* RollupInterval is configured against this down sample interval
* @param group_by The group by aggregator.
* @param str_interval String representation of the interval, for logging
* @since 2.4
*/
public void transformDownSamplerToRollupQuery(final Aggregator group_by, final String str_interval) {
if (downsampler != null && downsampler.getInterval() > 0) {
if (tsdb.getRollupConfig() != null) {
try {
best_match_rollups = tsdb.getRollupConfig().getRollupInterval(downsampler.getInterval() / 1000, str_interval);
// It is thread safe as each thread will be working on unique
// TsdbQuery object
// RollupConfig.getRollupInterval guarantees that,
// it always return a non-empty list
// TODO
rollup_query = new RollupQuery(best_match_rollups.remove(0), downsampler.getFunction(), downsampler.getInterval(), group_by);
} catch (NoSuchRollupForIntervalException nre) {
LOG.error("There is no such rollup for the downsample interval " + str_interval + ". So fall back to the default tsdb down" + " sampling approach and it requires raw data scan.");
// nullify the rollup_query if this api is called explicitly
rollup_query = null;
return;
}
if (rollup_query.getRollupInterval().isDefaultInterval()) {
// Anyways it is a scan on raw data
rollup_query = null;
}
}
}
}
Aggregations