(final TSDB tsdb, final HttpQuery query)
| 148 | // so we should refactor both classes to split the actual logic used to |
| 149 | // generate the data from the actual visualization (removing all duped code). |
| 150 | private void doGraph(final TSDB tsdb, final HttpQuery query) |
| 151 | throws IOException { |
| 152 | final String basepath = getGnuplotBasePath(tsdb, query); |
| 153 | long start_time = DateTime.parseDateTimeString( |
| 154 | query.getRequiredQueryStringParam("start"), |
| 155 | query.getQueryStringParam("tz")); |
| 156 | final boolean nocache = query.hasQueryStringParam("nocache"); |
| 157 | if (start_time == -1) { |
| 158 | throw BadRequestException.missingParameter("start"); |
| 159 | } else { |
| 160 | // temp fixup to seconds from ms until the rest of TSDB supports ms |
| 161 | // Note you can't append this to the DateTime.parseDateTimeString() call as |
| 162 | // it clobbers -1 results |
| 163 | start_time /= 1000; |
| 164 | } |
| 165 | long end_time = DateTime.parseDateTimeString( |
| 166 | query.getQueryStringParam("end"), |
| 167 | query.getQueryStringParam("tz")); |
| 168 | final long now = System.currentTimeMillis() / 1000; |
| 169 | if (end_time == -1) { |
| 170 | end_time = now; |
| 171 | } else { |
| 172 | // temp fixup to seconds from ms until the rest of TSDB supports ms |
| 173 | // Note you can't append this to the DateTime.parseDateTimeString() call as |
| 174 | // it clobbers -1 results |
| 175 | end_time /= 1000; |
| 176 | } |
| 177 | final int max_age = computeMaxAge(query, start_time, end_time, now); |
| 178 | if (!nocache && isDiskCacheHit(query, end_time, max_age, basepath)) { |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | // Parse TSQuery from HTTP query |
| 183 | final TSQuery tsquery = QueryRpc.parseQuery(tsdb, query); |
| 184 | tsquery.validateAndSetQuery(); |
| 185 | |
| 186 | // Build the queries for the parsed TSQuery |
| 187 | Query[] tsdbqueries = tsquery.buildQueries(tsdb); |
| 188 | |
| 189 | List<String> options = null; |
| 190 | final String options_allow_list = tsdb.getConfig().getString( |
| 191 | "tsd.gnuplot.options.allowlist"); |
| 192 | if (!Strings.isNullOrEmpty(options_allow_list)) { |
| 193 | String[] allow_list_strings = options_allow_list.split(";"); |
| 194 | Set<String> allow_list = Sets.newHashSet(); |
| 195 | for (int i = 0; i < allow_list_strings.length; i++) { |
| 196 | String allow = allow_list_strings[i]; |
| 197 | if (allow != null) { |
| 198 | allow = URLDecoder.decode(allow.trim()); |
| 199 | allow_list.add(allow); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | options = query.getQueryStringParams("o"); |
| 204 | for (int i = 0; i < options.size(); i++) { |
| 205 | if (!allow_list.contains(options.get(i))) { |
| 206 | throw new BadRequestException("Query option at index " + i |
| 207 | + " was not in the allow list."); |
no test coverage detected