Search in sources :

Example 1 with TagVRegexFilter

use of net.opentsdb.query.filter.TagVRegexFilter in project opentsdb by OpenTSDB.

the class TestTags method parseWithMetricAndFilters.

@Test
public void parseWithMetricAndFilters() {
    final List<TagVFilter> filters = new ArrayList<TagVFilter>();
    String metric = Tags.parseWithMetricAndFilters("sys.cpu.user", filters);
    assertEquals("sys.cpu.user", metric);
    assertEquals(0, filters.size());
    filters.clear();
    metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=web01}", filters);
    assertEquals("sys.cpu.user", metric);
    assertEquals(1, filters.size());
    assertEquals("host", filters.get(0).getTagk());
    assertTrue(filters.get(0).isGroupBy());
    assertTrue(filters.get(0) instanceof TagVLiteralOrFilter);
    filters.clear();
    metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=*}", filters);
    assertEquals("sys.cpu.user", metric);
    assertEquals(1, filters.size());
    assertEquals("host", filters.get(0).getTagk());
    assertTrue(filters.get(0).isGroupBy());
    assertTrue(filters.get(0) instanceof TagVWildcardFilter);
    filters.clear();
    metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=web01}{}", filters);
    assertEquals("sys.cpu.user", metric);
    assertEquals(1, filters.size());
    assertEquals("host", filters.get(0).getTagk());
    assertTrue(filters.get(0).isGroupBy());
    assertTrue(filters.get(0) instanceof TagVLiteralOrFilter);
    filters.clear();
    metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=*,owner=regexp(.*ob)}", filters);
    assertEquals("sys.cpu.user", metric);
    assertEquals(2, filters.size());
    for (final TagVFilter filter : filters) {
        if (filter instanceof TagVWildcardFilter) {
            assertEquals("host", filter.getTagk());
        } else if (filter instanceof TagVRegexFilter) {
            assertEquals("owner", filter.getTagk());
        }
        assertTrue(filter.isGroupBy());
    }
    filters.clear();
    metric = Tags.parseWithMetricAndFilters("sys.cpu.user{}{host=web01}", filters);
    assertEquals("sys.cpu.user", metric);
    assertEquals(1, filters.size());
    assertEquals("host", filters.get(0).getTagk());
    assertFalse(filters.get(0).isGroupBy());
    assertTrue(filters.get(0) instanceof TagVLiteralOrFilter);
    filters.clear();
    metric = Tags.parseWithMetricAndFilters("sys.cpu.user{}{host=iliteral_or(web01|Web02)}", filters);
    assertEquals("sys.cpu.user", metric);
    assertEquals(1, filters.size());
    assertEquals("host", filters.get(0).getTagk());
    assertFalse(filters.get(0).isGroupBy());
    assertTrue(filters.get(0) instanceof TagVILiteralOrFilter);
    filters.clear();
    metric = Tags.parseWithMetricAndFilters("sys.cpu.user{}{host=iliteral_or(web01|Web02),owner=*}", filters);
    assertEquals("sys.cpu.user", metric);
    assertEquals(2, filters.size());
    for (final TagVFilter filter : filters) {
        if (filter instanceof TagVWildcardFilter) {
            assertEquals("owner", filter.getTagk());
        } else if (filter instanceof TagVILiteralOrFilter) {
            assertEquals("host", filter.getTagk());
        }
        assertFalse(filter.isGroupBy());
    }
    filters.clear();
    metric = Tags.parseWithMetricAndFilters("sys.cpu.user{host=iliteral_or(web01|Web02)}{owner=*}", filters);
    assertEquals("sys.cpu.user", metric);
    System.out.println(filters);
    assertEquals(2, filters.size());
    for (final TagVFilter filter : filters) {
        if (filter instanceof TagVWildcardFilter) {
            assertEquals("owner", filter.getTagk());
            assertFalse(filter.isGroupBy());
        } else if (filter instanceof TagVILiteralOrFilter) {
            assertEquals("host", filter.getTagk());
            assertTrue(filter.isGroupBy());
        }
    }
}
Also used : TagVFilter(net.opentsdb.query.filter.TagVFilter) TagVRegexFilter(net.opentsdb.query.filter.TagVRegexFilter) TagVILiteralOrFilter(net.opentsdb.query.filter.TagVLiteralOrFilter.TagVILiteralOrFilter) TagVWildcardFilter(net.opentsdb.query.filter.TagVWildcardFilter) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) TagVLiteralOrFilter(net.opentsdb.query.filter.TagVLiteralOrFilter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with TagVRegexFilter

use of net.opentsdb.query.filter.TagVRegexFilter in project opentsdb by OpenTSDB.

the class TestQueryRpc method parseQueryMTypeWGroupByRegex.

@Test
public void parseQueryMTypeWGroupByRegex() throws Exception {
    HttpQuery query = NettyMocks.getQuery(tsdb, "/api/query?start=1h-ago&m=sum:sys.cpu.0{host=" + TagVRegexFilter.FILTER_NAME + "(something(foo|bar))}");
    TSQuery tsq = (TSQuery) parseQuery.invoke(rpc, tsdb, query, expressions);
    TSSubQuery sub = tsq.getQueries().get(0);
    sub.validateAndSetQuery();
    assertEquals(1, sub.getFilters().size());
    assertTrue(sub.getFilters().get(0) instanceof TagVRegexFilter);
}
Also used : TSQuery(net.opentsdb.core.TSQuery) TagVRegexFilter(net.opentsdb.query.filter.TagVRegexFilter) TSSubQuery(net.opentsdb.core.TSSubQuery) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TagVRegexFilter (net.opentsdb.query.filter.TagVRegexFilter)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ArrayList (java.util.ArrayList)1 TSQuery (net.opentsdb.core.TSQuery)1 TSSubQuery (net.opentsdb.core.TSSubQuery)1 TagVFilter (net.opentsdb.query.filter.TagVFilter)1 TagVLiteralOrFilter (net.opentsdb.query.filter.TagVLiteralOrFilter)1 TagVILiteralOrFilter (net.opentsdb.query.filter.TagVLiteralOrFilter.TagVILiteralOrFilter)1 TagVWildcardFilter (net.opentsdb.query.filter.TagVWildcardFilter)1 Matchers.anyString (org.mockito.Matchers.anyString)1