Processing for a data point query @param tsdb The TSDB to which we belong @param query The HTTP query to parse/respond @param allow_expressions Whether or not expressions should be parsed (based on the endpoint)
(final TSDB tsdb, final HttpQuery query,
final boolean allow_expressions)
| 126 | * (based on the endpoint) |
| 127 | */ |
| 128 | private void handleQuery(final TSDB tsdb, final HttpQuery query, |
| 129 | final boolean allow_expressions) { |
| 130 | final long start = DateTime.currentTimeMillis(); |
| 131 | final TSQuery data_query; |
| 132 | final List<ExpressionTree> expressions; |
| 133 | if (query.method() == HttpMethod.POST) { |
| 134 | switch (query.apiVersion()) { |
| 135 | case 0: |
| 136 | case 1: |
| 137 | data_query = query.serializer().parseQueryV1(); |
| 138 | break; |
| 139 | default: |
| 140 | query_invalid.incrementAndGet(); |
| 141 | throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, |
| 142 | "Requested API version not implemented", "Version " + |
| 143 | query.apiVersion() + " is not implemented"); |
| 144 | } |
| 145 | expressions = null; |
| 146 | } else { |
| 147 | expressions = new ArrayList<ExpressionTree>(); |
| 148 | data_query = parseQuery(tsdb, query, expressions); |
| 149 | } |
| 150 | |
| 151 | if (query.getAPIMethod() == HttpMethod.DELETE && |
| 152 | tsdb.getConfig().getBoolean("tsd.http.query.allow_delete")) { |
| 153 | data_query.setDelete(true); |
| 154 | } |
| 155 | |
| 156 | // validate and then compile the queries |
| 157 | try { |
| 158 | LOG.debug(data_query.toString()); |
| 159 | data_query.validateAndSetQuery(); |
| 160 | } catch (Exception e) { |
| 161 | throw new BadRequestException(HttpResponseStatus.BAD_REQUEST, |
| 162 | e.getMessage(), data_query.toString(), e); |
| 163 | } |
| 164 | |
| 165 | checkAuthorization(tsdb, query.channel(), data_query); |
| 166 | |
| 167 | // if the user tried this query multiple times from the same IP and src port |
| 168 | // they'll be rejected on subsequent calls |
| 169 | final QueryStats query_stats = |
| 170 | new QueryStats(query.getRemoteAddress(), data_query, |
| 171 | query.getPrintableHeaders()); |
| 172 | data_query.setQueryStats(query_stats); |
| 173 | query.setStats(query_stats); |
| 174 | |
| 175 | final int nqueries = data_query.getQueries().size(); |
| 176 | final ArrayList<DataPoints[]> results = new ArrayList<DataPoints[]>(nqueries); |
| 177 | final List<Annotation> globals = new ArrayList<Annotation>(); |
| 178 | |
| 179 | /** This has to be attached to callbacks or we may never respond to clients */ |
| 180 | class ErrorCB implements Callback<Object, Exception> { |
| 181 | public Object call(final Exception e) throws Exception { |
| 182 | Throwable ex = e; |
| 183 | try { |
| 184 | LOG.error("Query exception: ", e); |
| 185 | if (ex instanceof DeferredGroupException) { |
no test coverage detected