Skip to content

Commit

Permalink
Fix timeshift() function with multiple targets, closes grafana#338
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed May 16, 2017
1 parent ea59983 commit 48d2183
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions dist/datasource-zabbix/datasource.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/datasource-zabbix/datasource.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/test/datasource-zabbix/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ var ZabbixAPIDatasource = function () {
value: function query(options) {
var _this = this;

var timeFrom = Math.ceil(dateMath.parse(options.range.from) / 1000);
var timeTo = Math.ceil(dateMath.parse(options.range.to) / 1000);

var useTrendsFrom = Math.ceil(dateMath.parse('now-' + this.trendsFrom) / 1000);
var useTrendsRange = Math.ceil(utils.parseInterval(this.trendsRange) / 1000);
var useTrends = this.trends && (timeFrom <= useTrendsFrom || timeTo - timeFrom >= useTrendsRange);

// Get alerts for current panel
if (this.alertingEnabled) {
this.alertQuery(options).then(function (alert) {
Expand All @@ -129,6 +122,9 @@ var ZabbixAPIDatasource = function () {

// Create request for each target
var promises = _lodash2.default.map(options.targets, function (target) {
var timeFrom = Math.ceil(dateMath.parse(options.range.from) / 1000);
var timeTo = Math.ceil(dateMath.parse(options.range.to) / 1000);

// Prevent changes of original object
target = _lodash2.default.cloneDeep(target);
_this.replaceTargetVariables(target, options);
Expand All @@ -145,6 +141,10 @@ var ZabbixAPIDatasource = function () {
timeTo = time_to;
}

var useTrendsFrom = Math.ceil(dateMath.parse('now-' + _this.trendsFrom) / 1000);
var useTrendsRange = Math.ceil(utils.parseInterval(_this.trendsRange) / 1000);
var useTrends = _this.trends && (timeFrom <= useTrendsFrom || timeTo - timeFrom >= useTrendsRange);

// Metrics or Text query mode
if (target.mode !== 1) {
// Migrate old targets
Expand Down
20 changes: 10 additions & 10 deletions src/datasource-zabbix/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ class ZabbixAPIDatasource {
* @return {Object} Grafana metrics object with timeseries data for each target.
*/
query(options) {
let timeFrom = Math.ceil(dateMath.parse(options.range.from) / 1000);
let timeTo = Math.ceil(dateMath.parse(options.range.to) / 1000);

let useTrendsFrom = Math.ceil(dateMath.parse('now-' + this.trendsFrom) / 1000);
let useTrendsRange = Math.ceil(utils.parseInterval(this.trendsRange) / 1000);
let useTrends = this.trends && (
(timeFrom <= useTrendsFrom) ||
(timeTo - timeFrom >= useTrendsRange)
);

// Get alerts for current panel
if (this.alertingEnabled) {
this.alertQuery(options).then(alert => {
Expand All @@ -84,6 +74,9 @@ class ZabbixAPIDatasource {

// Create request for each target
let promises = _.map(options.targets, target => {
let timeFrom = Math.ceil(dateMath.parse(options.range.from) / 1000);
let timeTo = Math.ceil(dateMath.parse(options.range.to) / 1000);

// Prevent changes of original object
target = _.cloneDeep(target);
this.replaceTargetVariables(target, options);
Expand All @@ -96,6 +89,13 @@ class ZabbixAPIDatasource {
timeTo = time_to;
}

let useTrendsFrom = Math.ceil(dateMath.parse('now-' + this.trendsFrom) / 1000);
let useTrendsRange = Math.ceil(utils.parseInterval(this.trendsRange) / 1000);
let useTrends = this.trends && (
(timeFrom <= useTrendsFrom) ||
(timeTo - timeFrom >= useTrendsRange)
);

// Metrics or Text query mode
if (target.mode !== 1) {
// Migrate old targets
Expand Down

0 comments on commit 48d2183

Please sign in to comment.