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

Method computeMaxAge

src/tsd/GraphHandler.java:314–337  ·  view source on GitHub ↗

Decides how long we're going to allow the client to cache our response. Based on the query, we'll decide whether or not we want to allow the client to cache our response and for how long. @param query The query to serve. @param start_time The start time on the query (32-bit unsigned int, secs).

(final HttpQuery query,
                                   final long start_time, final long end_time,
                                   final long now)

Source from the content-addressed store, hash-verified

312 * @return A positive integer, in seconds.
313 */
314 private static int computeMaxAge(final HttpQuery query,
315 final long start_time, final long end_time,
316 final long now) {
317 // If the end time is in the future (1), make the graph uncacheable.
318 // Otherwise, if the end time is far enough in the past (2) such that
319 // no TSD can still be writing to rows for that time span and it's not
320 // specified in a relative fashion (3) (e.g. "1d-ago"), make the graph
321 // cacheable for a day since it's very unlikely that any data will change
322 // for this time span.
323 // Otherwise (4), allow the client to cache the graph for ~0.1% of the
324 // time span covered by the request e.g., for 1h of data, it's OK to
325 // serve something 3s stale, for 1d of data, 84s stale.
326 if (end_time > now) { // (1)
327 return 0;
328 } else if (end_time < now - Const.MAX_TIMESPAN // (2)
329 && !DateTime.isRelativeDate(
330 query.getQueryStringParam("start")) // (3)
331 && !DateTime.isRelativeDate(
332 query.getQueryStringParam("end"))) {
333 return 86400;
334 } else { // (4)
335 return (int) (end_time - start_time) >> 10;
336 }
337 }
338
339 // Runs Gnuplot in a subprocess to generate the graph.
340 private static final class RunGnuplot implements Runnable {

Callers 1

doGraphMethod · 0.95

Calls 2

isRelativeDateMethod · 0.95
getQueryStringParamMethod · 0.45

Tested by

no test coverage detected