use of net.opentsdb.query.filter.TagVLiteralOrFilter 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());
}
}
}
use of net.opentsdb.query.filter.TagVLiteralOrFilter in project opentsdb by OpenTSDB.
the class TestQueryRpc method parseQueryMTypeWGroupByAndWildcardFilterSameTagK.
@Test
public void parseQueryMTypeWGroupByAndWildcardFilterSameTagK() throws Exception {
HttpQuery query = NettyMocks.getQuery(tsdb, "/api/query?start=1h-ago&m=sum:sys.cpu.0{host=quirm|tsort}" + "{host=wildcard(*quirm)}");
TSQuery tsq = (TSQuery) parseQuery.invoke(rpc, tsdb, query, expressions);
TSSubQuery sub = tsq.getQueries().get(0);
sub.validateAndSetQuery();
assertTrue(sub.getFilters().get(0) instanceof TagVWildcardFilter);
assertTrue(sub.getFilters().get(1) instanceof TagVLiteralOrFilter);
}
use of net.opentsdb.query.filter.TagVLiteralOrFilter in project opentsdb by OpenTSDB.
the class TestQueryRpc method parseQueryMTypeWGroupByAndWildcardFilterExplicit.
@Test
public void parseQueryMTypeWGroupByAndWildcardFilterExplicit() throws Exception {
HttpQuery query = NettyMocks.getQuery(tsdb, "/api/query?start=1h-ago&m=sum:sys.cpu.0{colo=lga}{host=wildcard(*quirm)}");
TSQuery tsq = (TSQuery) parseQuery.invoke(rpc, tsdb, query, expressions);
TSSubQuery sub = tsq.getQueries().get(0);
sub.validateAndSetQuery();
assertTrue(sub.getFilters().get(0) instanceof TagVWildcardFilter);
assertTrue(sub.getFilters().get(1) instanceof TagVLiteralOrFilter);
}
Aggregations