Skip to content

Commit

Permalink
Merge pull request #38 from GlobalNOC/manual-query-vars
Browse files Browse the repository at this point in the history
adding auto-bucket size for the $quantify variable
  • Loading branch information
daldoyle authored Feb 9, 2018
2 parents ec1f2b7 + 147f308 commit b85f4c2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,22 @@ class GenericDatasource {
let formatQ = oldQ.replace(/,/gi, " or ");
query = query.replace(oldQ, formatQ);

let defaultBucket = duration / options.maxDataPoints;
// get defaultBucket rounded to nearest 10 for pretty
let size = Math.ceil(defaultBucket / 10) * 10;

if (duration >= 7776000) {
size = Math.max(86400, size);
} else if (duration >= 259200) {
size = Math.max(3600, size);
} else {
size = Math.max(60, size);
}

query = query.replace("$START", start.toString());
query = query.replace("$END", end.toString());
query = query.replace("$TIMESPAN", duration.toString());
query = query.replace(/\$quantify/g, size.toString());
query = this.templateSrv.replace(query, null, 'regex');

return resolve({
Expand Down

0 comments on commit b85f4c2

Please sign in to comment.