Search in sources :

Example 1 with MockScanner

use of net.opentsdb.storage.MockBase.MockScanner in project opentsdb by OpenTSDB.

the class TestTsdbQueryQueries method filterExplicitTagsGroupByOK.

@Test
public void filterExplicitTagsGroupByOK() throws Exception {
    tsdb.getConfig().overrideConfig("tsd.query.enable_fuzzy", "true");
    storeLongTimeSeriesSeconds(true, false);
    HashMap<String, String> tags = new HashMap<String, String>(1);
    tags.put("host", "*");
    query.setStartTime(1356998400);
    query.setEndTime(1357041600);
    query.setExplicitTags(true);
    query.setTimeSeries("sys.cpu.user", tags, Aggregators.SUM, false);
    final DataPoints[] dps = query.run();
    assertNotNull(dps);
    assertEquals("sys.cpu.user", dps[0].metricName());
    assertTrue(dps[0].getAggregatedTags().isEmpty());
    assertNull(dps[0].getAnnotations());
    assertEquals("web01", dps[0].getTags().get("host"));
    int value = 1;
    for (DataPoint dp : dps[0]) {
        assertEquals(value, dp.longValue());
        value++;
    }
    assertEquals(300, dps[0].aggregatedSize());
    // assert fuzzy
    for (final MockScanner scanner : storage.getScanners()) {
        assertTrue(scanner.getFilter() instanceof FilterList);
        FilterList filter_list = (FilterList) scanner.getFilter();
        assertEquals(2, filter_list.size());
        assertTrue(filter_list.filters().get(0) instanceof FuzzyRowFilter);
        assertTrue(filter_list.filters().get(1) instanceof KeyRegexpFilter);
    }
}
Also used : MockScanner(net.opentsdb.storage.MockBase.MockScanner) HashMap(java.util.HashMap) KeyRegexpFilter(org.hbase.async.KeyRegexpFilter) FilterList(org.hbase.async.FilterList) FuzzyRowFilter(org.hbase.async.FuzzyRowFilter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with MockScanner

use of net.opentsdb.storage.MockBase.MockScanner in project opentsdb by OpenTSDB.

the class TestTsdbQueryQueries method filterExplicitTagsMissing.

@Test
public void filterExplicitTagsMissing() throws Exception {
    tsdb.getConfig().overrideConfig("tsd.query.enable_fuzzy", "true");
    when(tag_names.getIdAsync("colo")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 0, 4 }));
    when(tag_values.getIdAsync("lga")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 0, 4 }));
    storeLongTimeSeriesSeconds(true, false);
    HashMap<String, String> tags = new HashMap<String, String>(1);
    tags.put("host", "web01");
    tags.put("colo", "lga");
    query.setStartTime(1356998400);
    query.setEndTime(1357041600);
    query.setExplicitTags(true);
    query.setTimeSeries("sys.cpu.user", tags, Aggregators.SUM, false);
    final DataPoints[] dps = query.run();
    assertNotNull(dps);
    assertEquals(0, dps.length);
    // assert fuzzy
    for (final MockScanner scanner : storage.getScanners()) {
        assertTrue(scanner.getFilter() instanceof FilterList);
        FilterList filter_list = (FilterList) scanner.getFilter();
        assertEquals(2, filter_list.size());
        assertTrue(filter_list.filters().get(0) instanceof FuzzyRowFilter);
        assertTrue(filter_list.filters().get(1) instanceof KeyRegexpFilter);
    }
}
Also used : MockScanner(net.opentsdb.storage.MockBase.MockScanner) HashMap(java.util.HashMap) KeyRegexpFilter(org.hbase.async.KeyRegexpFilter) FilterList(org.hbase.async.FilterList) FuzzyRowFilter(org.hbase.async.FuzzyRowFilter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with MockScanner

use of net.opentsdb.storage.MockBase.MockScanner in project opentsdb by OpenTSDB.

the class TestTsdbQueryQueries method filterExplicitTagsOK.

@Test
public void filterExplicitTagsOK() throws Exception {
    tsdb.getConfig().overrideConfig("tsd.query.enable_fuzzy", "true");
    storeLongTimeSeriesSeconds(true, false);
    HashMap<String, String> tags = new HashMap<String, String>(1);
    tags.put("host", "web01");
    query.setStartTime(1356998400);
    query.setEndTime(1357041600);
    query.setExplicitTags(true);
    query.setTimeSeries("sys.cpu.user", tags, Aggregators.SUM, false);
    final DataPoints[] dps = query.run();
    assertNotNull(dps);
    assertEquals("sys.cpu.user", dps[0].metricName());
    assertTrue(dps[0].getAggregatedTags().isEmpty());
    assertNull(dps[0].getAnnotations());
    assertEquals("web01", dps[0].getTags().get("host"));
    int value = 1;
    for (DataPoint dp : dps[0]) {
        assertEquals(value, dp.longValue());
        value++;
    }
    assertEquals(300, dps[0].aggregatedSize());
    // assert fuzzy
    for (final MockScanner scanner : storage.getScanners()) {
        assertTrue(scanner.getFilter() instanceof FilterList);
        FilterList filter_list = (FilterList) scanner.getFilter();
        assertEquals(2, filter_list.size());
        assertTrue(filter_list.filters().get(0) instanceof FuzzyRowFilter);
        assertTrue(filter_list.filters().get(1) instanceof KeyRegexpFilter);
    }
}
Also used : MockScanner(net.opentsdb.storage.MockBase.MockScanner) HashMap(java.util.HashMap) KeyRegexpFilter(org.hbase.async.KeyRegexpFilter) FilterList(org.hbase.async.FilterList) FuzzyRowFilter(org.hbase.async.FuzzyRowFilter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)3 MockScanner (net.opentsdb.storage.MockBase.MockScanner)3 FilterList (org.hbase.async.FilterList)3 FuzzyRowFilter (org.hbase.async.FuzzyRowFilter)3 KeyRegexpFilter (org.hbase.async.KeyRegexpFilter)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3