use of net.opentsdb.core.TSQuery in project opentsdb by OpenTSDB.
the class TestQueryStats method getStat.
@Test
public void getStat() throws Exception {
final TSQuery query = new TSQuery();
query.setStart("1h-ago");
final QueryStats stats = new QueryStats(remote, query, headers);
stats.addStat(QueryStat.AGGREGATED_SIZE, 42);
stats.markSerializationSuccessful();
assertEquals(42, stats.getStat(QueryStat.AGGREGATED_SIZE));
assertEquals(-1, stats.getStat(QueryStat.BYTES_FROM_STORAGE));
}
use of net.opentsdb.core.TSQuery in project opentsdb by OpenTSDB.
the class TestHttpJsonSerializer method getTestQuery.
/** @return Returns a test TSQuery object to pass on to the serializer */
private TSQuery getTestQuery(final boolean show_stats, final boolean show_summary) {
final TSQuery data_query = new TSQuery();
data_query.setStart("1356998400");
data_query.setEnd("1388534400");
data_query.setShowStats(show_stats);
data_query.setShowSummary(show_summary);
final TSSubQuery sub_query = new TSSubQuery();
sub_query.setMetric("sys.cpu.user");
sub_query.setAggregator("sum");
final ArrayList<TSSubQuery> sub_queries = new ArrayList<TSSubQuery>(1);
sub_queries.add(sub_query);
data_query.setQueries(sub_queries);
return data_query;
}
use of net.opentsdb.core.TSQuery in project opentsdb by OpenTSDB.
the class TestHttpJsonSerializer method formatQueryAsyncV1NoSuchMetricId.
@Test(expected = DeferredGroupException.class)
public void formatQueryAsyncV1NoSuchMetricId() throws Exception {
setupFormatQuery();
HttpQuery query = NettyMocks.getQuery(tsdb, "");
HttpJsonSerializer serdes = new HttpJsonSerializer(query);
final TSQuery data_query = getTestQuery(false);
validateTestQuery(data_query);
final DataPoints dps = new MockDataPoints().getMock();
final List<DataPoints[]> results = new ArrayList<DataPoints[]>(1);
results.add(new DataPoints[] { dps });
when(dps.metricNameAsync()).thenReturn(Deferred.<String>fromError(new NoSuchUniqueId("No such metric", new byte[] { 0, 0, 1 })));
serdes.formatQueryAsyncV1(data_query, results, Collections.<Annotation>emptyList()).joinUninterruptibly();
}
use of net.opentsdb.core.TSQuery in project opentsdb by OpenTSDB.
the class TestHttpJsonSerializer method formatQueryAsyncV1wQuery.
@Test
public void formatQueryAsyncV1wQuery() throws Exception {
setupFormatQuery();
HttpQuery query = NettyMocks.getQuery(tsdb, "");
HttpJsonSerializer serdes = new HttpJsonSerializer(query);
final TSQuery data_query = getTestQuery(false);
data_query.setShowQuery(true);
validateTestQuery(data_query);
final List<DataPoints[]> results = new ArrayList<DataPoints[]>(1);
results.add(new DataPoints[] { new MockDataPoints().getMock() });
ChannelBuffer cb = serdes.formatQueryAsyncV1(data_query, results, Collections.<Annotation>emptyList()).joinUninterruptibly();
assertNotNull(cb);
final String json = cb.toString(Charset.forName("UTF-8"));
assertTrue(json.contains("\"metric\":\"system.cpu.user\","));
assertTrue(json.contains("\"1356998700\":1,"));
assertTrue(json.contains("\"1357058700\":201"));
assertFalse(json.contains("\"timeTotal\""));
assertTrue(json.contains("\"tsuid\":\"000001000001000001\""));
assertTrue(json.contains("\"query\":"));
}
use of net.opentsdb.core.TSQuery in project opentsdb by OpenTSDB.
the class TestQueryRpc method parseQueryMTypeWGroupByWildcardExplicit.
@Test
public void parseQueryMTypeWGroupByWildcardExplicit() throws Exception {
HttpQuery query = NettyMocks.getQuery(tsdb, "/api/query?start=1h-ago&m=sum:sys.cpu.0{host=" + TagVWildcardFilter.FILTER_NAME + "(*quirm)}");
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 TagVWildcardFilter);
}
Aggregations