MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / doGraph

Method doGraph

src/tsd/GraphHandler.java:150–292  ·  view source on GitHub ↗
(final TSDB tsdb, final HttpQuery query)

Source from the content-addressed store, hash-verified

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.");

Callers 1

executeMethod · 0.95

Calls 15

getGnuplotBasePathMethod · 0.95
parseDateTimeStringMethod · 0.95
missingParameterMethod · 0.95
computeMaxAgeMethod · 0.95
isDiskCacheHitMethod · 0.95
parseQueryMethod · 0.95
validateAndSetQueryMethod · 0.95
buildQueriesMethod · 0.95
setPlotDimensionsMethod · 0.95
setPlotParamsMethod · 0.95
addMethod · 0.95
logInfoMethod · 0.95

Tested by

no test coverage detected