MCPcopy
hub / github.com/OpenTSDB/opentsdb / SearchRpc

Class SearchRpc

src/tsd/SearchRpc.java:49–298  ·  view source on GitHub ↗

Handles very basic search calls by passing the user's query to the configured search plugin and pushing the response back through the serializers. Also allows for time series lookups given a metric, tag name, tag value or combination thereof using the tsdb-meta table. @since 2.0

Source from the content-addressed store, hash-verified

47 * @since 2.0
48 */
49final class SearchRpc implements HttpRpc {
50
51 /**
52 * Handles the /api/search/<type> endpoint
53 * @param tsdb The TSDB to which we belong
54 * @param query The HTTP query to work with
55 */
56 @Override
57 public void execute(TSDB tsdb, HttpQuery query) {
58
59 final HttpMethod method = query.getAPIMethod();
60 if (method != HttpMethod.GET && method != HttpMethod.POST) {
61 throw new BadRequestException("Unsupported method: " + method.getName());
62 }
63
64 // the uri will be /api/vX/search/<type> or /api/search/<type>
65 final String[] uri = query.explodeAPIPath();
66 final String endpoint = uri.length > 1 ? uri[1] : "";
67 final SearchType type;
68 final SearchQuery search_query;
69
70 try {
71 type = SearchQuery.parseSearchType(endpoint);
72 } catch (IllegalArgumentException e) {
73 throw new BadRequestException("Invalid search query type supplied", e);
74 }
75
76 if (query.hasContent()) {
77 search_query = query.serializer().parseSearchQueryV1();
78 } else {
79 search_query = parseQueryString(query, type);
80 }
81
82 search_query.setType(type);
83
84 if (type == SearchType.LOOKUP) {
85 processLookup(tsdb, query, search_query);
86 return;
87 }
88
89 try {
90 final SearchQuery results =
91 tsdb.executeSearch(search_query).joinUninterruptibly();
92 query.sendReply(query.serializer().formatSearchResultsV1(results));
93 } catch (IllegalStateException e) {
94 throw new BadRequestException("Searching is not enabled", e);
95 } catch (Exception e) {
96 throw new RuntimeException(e);
97 }
98 }
99
100 /**
101 * Parses required search values from the query string
102 * @param query The HTTP query to work with
103 * @param type The type of search query requested
104 * @return A parsed SearchQuery object
105 */
106 private final SearchQuery parseQueryString(final HttpQuery query,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…