use of net.opentsdb.rollup.RollupConfig 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());
}
use of net.opentsdb.rollup.RollupConfig in project opentsdb by OpenTSDB.
the class TestMultiGetQuery method localBefore.
@Before
public void localBefore() {
max_bytes = 1000000;
multiget_no_meta = false;
start_ts = 1481227200;
end_ts = 1481284800;
q_tags = new ArrayList<ByteMap<byte[][]>>();
q_tags_AD = new ArrayList<ByteMap<byte[][]>>();
ByteMap<byte[][]> q_tags1;
q_tags1 = new ByteMap<byte[][]>();
byte[][] val;
val = new byte[1][];
val[0] = UIDS.get("A");
q_tags1.put(TAGK_BYTES, val);
val = new byte[1][];
val[0] = UIDS.get("D");
q_tags1.put(TAGK_B_BYTES, val);
ByteMap<byte[][]> q_tags2;
q_tags2 = new ByteMap<byte[][]>();
val = new byte[1][];
val[0] = UIDS.get("B");
q_tags2.put(TAGK_BYTES, val);
val = new byte[1][];
val[0] = UIDS.get("D");
q_tags2.put(TAGK_B_BYTES, val);
ByteMap<byte[][]> q_tags3;
q_tags3 = new ByteMap<byte[][]>();
val = new byte[1][];
val[0] = UIDS.get("C");
q_tags3.put(TAGK_BYTES, val);
val = new byte[1][];
val[0] = UIDS.get("D");
q_tags3.put(TAGK_B_BYTES, val);
q_tags.add(q_tags1);
q_tags.add(q_tags2);
q_tags.add(q_tags3);
q_tags_AD.add(q_tags1);
q_tags_nometa = new ArrayList<ByteMap<byte[][]>>();
ByteMap<byte[][]> q_tags_map = new ByteMap<byte[][]>();
q_tags_map.put(TAGK_BYTES, new byte[][] { UIDS.get("A"), UIDS.get("B"), UIDS.get("C") });
q_tags_map.put(TAGK_B_BYTES, new byte[][] { UIDS.get("D") });
q_tags_map.put(UIDS.get("E"), new byte[][] { UIDS.get("F"), UIDS.get("G") });
q_tags_nometa.add(q_tags_map);
// q_tags1.put(TAGK_BYTES, new byte[][] { UIDS.get("A"), UIDS.get("B"), UIDS.get("C") });
// q_tags1.put(TAGK_B_BYTES, new byte[][] { UIDS.get("D") });
// q_tags1.put(UIDS.get("E"), new byte[][] { UIDS.get("F"), UIDS.get("G") });
aggregator = Aggregators.get("sum");
RollupConfig rollup_config = RollupConfig.builder().addAggregationId("sum", 0).addAggregationId("count", 1).addAggregationId("max", 2).addAggregationId("min", 3).addInterval(RollupInterval.builder().setTable("tsdb-rollup-10m").setPreAggregationTable("tsdb-rollup-agg-10m").setInterval("10m").setRowSpan("6h")).addInterval(RollupInterval.builder().setTable("tsdb-rollup-1h").setPreAggregationTable("tsdb-rollup-agg-1h").setInterval("1h").setRowSpan("1d")).addInterval(RollupInterval.builder().setTable("tsdb-rollup-1d").setPreAggregationTable("tsdb-rollup-agg-1d").setInterval("1d").setRowSpan("1n")).build();
Whitebox.setInternalState(tsdb, "rollup_config", rollup_config);
}
use of net.opentsdb.rollup.RollupConfig in project opentsdb by OpenTSDB.
the class TestFsckWRollups method before.
@SuppressWarnings("unchecked")
@Before
public void before() throws Exception {
client = mock(HBaseClient.class);
metrics = mock(UniqueId.class);
tag_names = mock(UniqueId.class);
tag_values = mock(UniqueId.class);
options = mock(FsckOptions.class);
timer = new FakeTaskTimer();
PowerMockito.mockStatic(Threads.class);
PowerMockito.when(Threads.newTimer(anyString())).thenReturn(timer);
PowerMockito.when(Threads.newTimer(anyInt(), anyString())).thenReturn(timer);
PowerMockito.whenNew(HashedWheelTimer.class).withNoArguments().thenReturn(timer);
PowerMockito.whenNew(HBaseClient.class).withAnyArguments().thenReturn(client);
config = new Config(false);
tsdb = new TSDB(client, config);
when(client.flush()).thenReturn(Deferred.fromResult(null));
storage = new MockBase(tsdb, client, true, true, true, true);
storage.setFamily("t".getBytes(MockBase.ASCII()));
when(options.fix()).thenReturn(false);
when(options.compact()).thenReturn(false);
when(options.resolveDupes()).thenReturn(false);
when(options.lastWriteWins()).thenReturn(false);
when(options.deleteOrphans()).thenReturn(false);
when(options.deleteUnknownColumns()).thenReturn(false);
when(options.deleteBadValues()).thenReturn(false);
when(options.deleteBadRows()).thenReturn(false);
when(options.deleteBadCompacts()).thenReturn(false);
when(options.threads()).thenReturn(1);
// replace the "real" field objects with mocks
Field met = tsdb.getClass().getDeclaredField("metrics");
met.setAccessible(true);
met.set(tsdb, metrics);
Field tagk = tsdb.getClass().getDeclaredField("tag_names");
tagk.setAccessible(true);
tagk.set(tsdb, tag_names);
Field tagv = tsdb.getClass().getDeclaredField("tag_values");
tagv.setAccessible(true);
tagv.set(tsdb, tag_values);
// mock UniqueId
when(metrics.getId("sys.cpu.user")).thenReturn(new byte[] { 0, 0, 1 });
when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("sys.cpu.user"));
when(metrics.getId("sys.cpu.system")).thenThrow(new NoSuchUniqueName("sys.cpu.system", "metric"));
when(metrics.getId("sys.cpu.nice")).thenReturn(new byte[] { 0, 0, 2 });
when(metrics.getName(new byte[] { 0, 0, 2 })).thenReturn("sys.cpu.nice");
when(tag_names.getId("host")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_names.getName(new byte[] { 0, 0, 1 })).thenReturn("host");
when(tag_names.getOrCreateId("host")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_names.getId("dc")).thenThrow(new NoSuchUniqueName("dc", "metric"));
when(tag_values.getId("web01")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_values.getName(new byte[] { 0, 0, 1 })).thenReturn("web01");
when(tag_values.getOrCreateId("web01")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_values.getId("web02")).thenReturn(new byte[] { 0, 0, 2 });
when(tag_values.getName(new byte[] { 0, 0, 2 })).thenReturn("web02");
when(tag_values.getOrCreateId("web02")).thenReturn(new byte[] { 0, 0, 2 });
when(tag_values.getId("web03")).thenThrow(new NoSuchUniqueName("web03", "metric"));
PowerMockito.mockStatic(Tags.class);
when(Tags.resolveIds((TSDB) any(), (ArrayList<byte[]>) any())).thenReturn(// don't care
null);
when(metrics.width()).thenReturn((short) 3);
when(tag_names.width()).thenReturn((short) 3);
when(tag_values.width()).thenReturn((short) 3);
RollupConfig rollup_config = RollupConfig.builder().addAggregationId("sum", 0).addAggregationId("count", 1).addAggregationId("min", 2).addAggregationId("max", 3).addInterval(RollupInterval.builder().setInterval("1m").setRowSpan("24h").setTable("tsdb-1m").setPreAggregationTable("tsdb-preagg-1m")).addInterval(RollupInterval.builder().setInterval("1h").setRowSpan("1d").setTable("tsdb-1h").setPreAggregationTable("tsdb-preagg-1h")).build();
Whitebox.setInternalState(tsdb, "rollup_config", rollup_config);
}
Aggregations