use of net.opentsdb.utils.Pair in project opentsdb by OpenTSDB.
the class Search method lookup.
/**
* Performs a time series lookup given a query like "metric tagk=tagv" where
* a list of all time series containing the given metric and tag pair will be
* dumped to standard out. Tag pairs can be given with empty tagk or tagvs to
* and the metric is option. E.g. a query of "=web01" will return all time
* series with a tag value of "web01".
* By default the lookup is performed against the tsdb-meta table. If the
* "--use_data_table" flag is supplied, the main data table will be scanned.
* @param tsdb The TSDB to use for communication
* @param use_data_table Whether or not lookups should be done on the full
* data table
* @param args Arguments to parse
* @return An exit code
*/
private static int lookup(final TSDB tsdb, final boolean use_data_table, final String[] args) throws Exception {
if (!use_data_table) {
tsdb.getClient().ensureTableExists(tsdb.getConfig().getString("tsd.storage.hbase.meta_table")).joinUninterruptibly();
}
final SearchQuery query = new SearchQuery();
query.setType(SearchType.LOOKUP);
int index = 1;
if (!args[index].contains("=")) {
query.setMetric(args[index++]);
}
final List<Pair<String, String>> tags = new ArrayList<Pair<String, String>>(args.length - index);
for (; index < args.length; index++) {
Tags.parse(tags, args[index]);
}
query.setTags(tags);
if (use_data_table) {
query.setUseMeta(false);
LOG.warn("NOTE: Scanning the full data table may take a long time");
}
final TimeSeriesLookup lookup = new TimeSeriesLookup(tsdb, query);
lookup.setToStdout(true);
lookup.lookup();
return 0;
}
use of net.opentsdb.utils.Pair in project opentsdb by OpenTSDB.
the class SearchRpc method parseQueryString.
/**
* Parses required search values from the query string
* @param query The HTTP query to work with
* @param type The type of search query requested
* @return A parsed SearchQuery object
*/
private final SearchQuery parseQueryString(final HttpQuery query, final SearchType type) {
final SearchQuery search_query = new SearchQuery();
if (type == SearchType.LOOKUP) {
final String query_string = query.getRequiredQueryStringParam("m");
search_query.setTags(new ArrayList<Pair<String, String>>());
try {
search_query.setMetric(Tags.parseWithMetric(query_string, search_query.getTags()));
} catch (IllegalArgumentException e) {
throw new BadRequestException("Unable to parse query", e);
}
if (query.hasQueryStringParam("limit")) {
final String limit = query.getQueryStringParam("limit");
try {
search_query.setLimit(Integer.parseInt(limit));
} catch (NumberFormatException e) {
throw new BadRequestException("Unable to convert 'limit' to a valid number");
}
}
return search_query;
}
// process a regular search query
search_query.setQuery(query.getRequiredQueryStringParam("query"));
if (query.hasQueryStringParam("limit")) {
final String limit = query.getQueryStringParam("limit");
try {
search_query.setLimit(Integer.parseInt(limit));
} catch (NumberFormatException e) {
throw new BadRequestException("Unable to convert 'limit' to a valid number");
}
}
if (query.hasQueryStringParam("start_index")) {
final String idx = query.getQueryStringParam("start_index");
try {
search_query.setStartIndex(Integer.parseInt(idx));
} catch (NumberFormatException e) {
throw new BadRequestException("Unable to convert 'start_index' to a valid number");
}
}
return search_query;
}
use of net.opentsdb.utils.Pair in project opentsdb by OpenTSDB.
the class BaseTimeSyncedIteratorTest method runQueries.
/**
* Executes the queries against MockBase through the regular pipeline and stores
* the results in {@linke #results}
* @param subs The queries to execute
*/
protected void runQueries(final ArrayList<TSSubQuery> subs) throws Exception {
query = new TSQuery();
query.setStart(Long.toString(START_TS));
query.setQueries(subs);
query.validateAndSetQuery();
final Query[] compiled = query.buildQueries(tsdb);
results = new HashMap<String, Pair<TSSubQuery, DataPoints[]>>(compiled.length);
iterators = new HashMap<String, ITimeSyncedIterator>(compiled.length);
int index = 0;
for (final Query q : compiled) {
final DataPoints[] dps = q.runAsync().join();
results.put(Integer.toString(index), new Pair<TSSubQuery, DataPoints[]>(query.getQueries().get(index), dps));
final ITimeSyncedIterator it = new TimeSyncedIterator(Integer.toString(index), query.getQueries().get(index).getFilterTagKs(), dps);
it.setFillPolicy(new NumericFillPolicy(FillPolicy.NOT_A_NUMBER));
iterators.put(Integer.toString(index), it);
index++;
}
}
use of net.opentsdb.utils.Pair in project opentsdb by OpenTSDB.
the class TestTags method parseWithMetricListWTag.
@Test
public void parseWithMetricListWTag() {
final List<Pair<String, String>> tags = new ArrayList<Pair<String, String>>(1);
final String metric = Tags.parseWithMetric("sys.cpu.user{host=web01}", tags);
assertEquals("sys.cpu.user", metric);
assertEquals(1, tags.size());
assertEquals("host", tags.get(0).getKey());
assertEquals("web01", tags.get(0).getValue());
}
use of net.opentsdb.utils.Pair in project opentsdb by OpenTSDB.
the class TestTags method parseWithMetricListNullTagk3.
@Test
public void parseWithMetricListNullTagk3() {
final List<Pair<String, String>> tags = new ArrayList<Pair<String, String>>(3);
final String metric = Tags.parseWithMetric("sys.cpu.user{host=web01,=lga,owner=}", tags);
assertEquals("sys.cpu.user", metric);
assertEquals(3, tags.size());
assertEquals("host", tags.get(0).getKey());
assertEquals("web01", tags.get(0).getValue());
assertNull(tags.get(1).getKey());
assertEquals("lga", tags.get(1).getValue());
assertEquals("owner", tags.get(2).getKey());
assertNull(tags.get(2).getValue());
}
Aggregations