Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions dist/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function (angular, _, dateMath, moment) {
this.supportMetrics = true;
this.periodGranularity = instanceSettings.jsonData.periodGranularity;

function replaceTemplateValues(obj, attrList) {
function replaceTemplateValues(obj, scopedVars, attrList) {
var substitutedVals = attrList.map(function (attr) {
return templateSrv.replace(obj[attr]);
return templateSrv.replace(obj[attr], scopedVars);
});
return _.assign(_.clone(obj, true), _.zipObject(attrList, substitutedVals));
}
Expand Down Expand Up @@ -140,15 +140,15 @@ function (angular, _, dateMath, moment) {
granularity = {"type": "period", "period": "P1D", "timeZone": dataSource.periodGranularity}
}
}
return dataSource._doQuery(roundedFrom, to, granularity, target);
return dataSource._doQuery(roundedFrom, to, granularity, target, options.scopedVars);
});

return $q.all(promises).then(function(results) {
return { data: _.flatten(results) };
});
};

this._doQuery = function (from, to, granularity, target) {
this._doQuery = function (from, to, granularity, target, scopedVars) {

function splitCardinalityFields(aggregator) {
if (aggregator.type === 'cardinality' && typeof aggregator.fieldNames === 'string') {
Expand Down Expand Up @@ -178,26 +178,26 @@ function (angular, _, dateMath, moment) {
var threshold = target.limit;
var metric = target.druidMetric;
var dimension = templateSrv.replace(target.dimension);
promise = this._topNQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, threshold, metric, dimension)
promise = this._topNQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, threshold, metric, dimension, scopedVars)
.then(function(response) {
return convertTopNData(response.data, dimension, metric);
});
}
else if (target.queryType === 'groupBy') {
limitSpec = getLimitSpec(target.limit, target.orderBy);
promise = this._groupByQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, groupBy, limitSpec)
promise = this._groupByQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, groupBy, limitSpec, scopedVars)
.then(function(response) {
return convertGroupByData(response.data, groupBy, metricNames);
});
}
else if (target.queryType === 'select') {
promise = this._selectQuery(datasource, intervals, granularity, selectDimensions, selectMetrics, filters, selectThreshold);
promise = this._selectQuery(datasource, intervals, granularity, selectDimensions, selectMetrics, filters, selectThreshold, scopedVars);
return promise.then(function(response) {
return convertSelectData(response.data);
});
}
else {
promise = this._timeSeriesQuery(datasource, intervals, granularity, filters, aggregators, postAggregators)
promise = this._timeSeriesQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, scopedVars)
.then(function(response) {
return convertTimeSeriesData(response.data, metricNames);
});
Expand Down Expand Up @@ -229,7 +229,7 @@ function (angular, _, dateMath, moment) {
});
};

this._selectQuery = function (datasource, intervals, granularity, dimension, metric, filters, selectThreshold) {
this._selectQuery = function (datasource, intervals, granularity, dimension, metric, filters, selectThreshold, scopedVars) {
var query = {
"queryType": "select",
"dataSource": datasource,
Expand All @@ -241,13 +241,13 @@ function (angular, _, dateMath, moment) {
};

if (filters && filters.length > 0) {
query.filter = buildFilterTree(filters);
query.filter = buildFilterTree(filters, scopedVars);
}

return this._druidQuery(query);
};

this._timeSeriesQuery = function (datasource, intervals, granularity, filters, aggregators, postAggregators) {
this._timeSeriesQuery = function (datasource, intervals, granularity, filters, aggregators, postAggregators, scopedVars) {
var query = {
"queryType": "timeseries",
"dataSource": datasource,
Expand All @@ -258,14 +258,14 @@ function (angular, _, dateMath, moment) {
};

if (filters && filters.length > 0) {
query.filter = buildFilterTree(filters);
query.filter = buildFilterTree(filters, scopedVars);
}

return this._druidQuery(query);
};

this._topNQuery = function (datasource, intervals, granularity, filters, aggregators, postAggregators,
threshold, metric, dimension) {
threshold, metric, dimension, scopedVars) {
var query = {
"queryType": "topN",
"dataSource": datasource,
Expand All @@ -280,14 +280,14 @@ function (angular, _, dateMath, moment) {
};

if (filters && filters.length > 0) {
query.filter = buildFilterTree(filters);
query.filter = buildFilterTree(filters, scopedVars);
}

return this._druidQuery(query);
};

this._groupByQuery = function (datasource, intervals, granularity, filters, aggregators, postAggregators,
groupBy, limitSpec) {
groupBy, limitSpec, scopedVars) {
var query = {
"queryType": "groupBy",
"dataSource": datasource,
Expand All @@ -300,7 +300,7 @@ function (angular, _, dateMath, moment) {
};

if (filters && filters.length > 0) {
query.filter = buildFilterTree(filters);
query.filter = buildFilterTree(filters, scopedVars);
}

return this._druidQuery(query);
Expand All @@ -327,10 +327,10 @@ function (angular, _, dateMath, moment) {
};
}

function buildFilterTree(filters) {
function buildFilterTree(filters, scopedVars) {
//Do template variable replacement
var replacedFilters = filters.map(function (filter) {
return filterTemplateExpanders[filter.type](filter);
return filterTemplateExpanders[filter.type](filter, scopedVars);
})
.map(function (filter) {
var finalFilter = _.omit(filter, 'negate');
Expand Down
36 changes: 18 additions & 18 deletions src/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function (angular, _, dateMath, moment) {
this.supportMetrics = true;
this.periodGranularity = instanceSettings.jsonData.periodGranularity;

function replaceTemplateValues(obj, attrList) {
function replaceTemplateValues(obj, scopedVars, attrList) {
var substitutedVals = attrList.map(function (attr) {
return templateSrv.replace(obj[attr]);
return templateSrv.replace(obj[attr], scopedVars);
});
return _.assign(_.clone(obj, true), _.zipObject(attrList, substitutedVals));
}
Expand Down Expand Up @@ -140,15 +140,15 @@ function (angular, _, dateMath, moment) {
granularity = {"type": "period", "period": "P1D", "timeZone": dataSource.periodGranularity}
}
}
return dataSource._doQuery(roundedFrom, to, granularity, target);
return dataSource._doQuery(roundedFrom, to, granularity, target, options.scopedVars);
});

return $q.all(promises).then(function(results) {
return { data: _.flatten(results) };
});
};

this._doQuery = function (from, to, granularity, target) {
this._doQuery = function (from, to, granularity, target, scopedVars) {

function splitCardinalityFields(aggregator) {
if (aggregator.type === 'cardinality' && typeof aggregator.fieldNames === 'string') {
Expand Down Expand Up @@ -178,26 +178,26 @@ function (angular, _, dateMath, moment) {
var threshold = target.limit;
var metric = target.druidMetric;
var dimension = templateSrv.replace(target.dimension);
promise = this._topNQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, threshold, metric, dimension)
promise = this._topNQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, threshold, metric, dimension, scopedVars)
.then(function(response) {
return convertTopNData(response.data, dimension, metric);
});
}
else if (target.queryType === 'groupBy') {
limitSpec = getLimitSpec(target.limit, target.orderBy);
promise = this._groupByQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, groupBy, limitSpec)
promise = this._groupByQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, groupBy, limitSpec, scopedVars)
.then(function(response) {
return convertGroupByData(response.data, groupBy, metricNames);
});
}
else if (target.queryType === 'select') {
promise = this._selectQuery(datasource, intervals, granularity, selectDimensions, selectMetrics, filters, selectThreshold);
promise = this._selectQuery(datasource, intervals, granularity, selectDimensions, selectMetrics, filters, selectThreshold, scopedVars);
return promise.then(function(response) {
return convertSelectData(response.data);
});
}
else {
promise = this._timeSeriesQuery(datasource, intervals, granularity, filters, aggregators, postAggregators)
promise = this._timeSeriesQuery(datasource, intervals, granularity, filters, aggregators, postAggregators, scopedVars)
.then(function(response) {
return convertTimeSeriesData(response.data, metricNames);
});
Expand Down Expand Up @@ -229,7 +229,7 @@ function (angular, _, dateMath, moment) {
});
};

this._selectQuery = function (datasource, intervals, granularity, dimension, metric, filters, selectThreshold) {
this._selectQuery = function (datasource, intervals, granularity, dimension, metric, filters, selectThreshold, scopedVars) {
var query = {
"queryType": "select",
"dataSource": datasource,
Expand All @@ -241,13 +241,13 @@ function (angular, _, dateMath, moment) {
};

if (filters && filters.length > 0) {
query.filter = buildFilterTree(filters);
query.filter = buildFilterTree(filters, scopedVars);
}

return this._druidQuery(query);
};

this._timeSeriesQuery = function (datasource, intervals, granularity, filters, aggregators, postAggregators) {
this._timeSeriesQuery = function (datasource, intervals, granularity, filters, aggregators, postAggregators, scopedVars) {
var query = {
"queryType": "timeseries",
"dataSource": datasource,
Expand All @@ -258,14 +258,14 @@ function (angular, _, dateMath, moment) {
};

if (filters && filters.length > 0) {
query.filter = buildFilterTree(filters);
query.filter = buildFilterTree(filters, scopedVars);
}

return this._druidQuery(query);
};

this._topNQuery = function (datasource, intervals, granularity, filters, aggregators, postAggregators,
threshold, metric, dimension) {
threshold, metric, dimension, scopedVars) {
var query = {
"queryType": "topN",
"dataSource": datasource,
Expand All @@ -280,14 +280,14 @@ function (angular, _, dateMath, moment) {
};

if (filters && filters.length > 0) {
query.filter = buildFilterTree(filters);
query.filter = buildFilterTree(filters, scopedVars);
}

return this._druidQuery(query);
};

this._groupByQuery = function (datasource, intervals, granularity, filters, aggregators, postAggregators,
groupBy, limitSpec) {
groupBy, limitSpec, scopedVars) {
var query = {
"queryType": "groupBy",
"dataSource": datasource,
Expand All @@ -300,7 +300,7 @@ function (angular, _, dateMath, moment) {
};

if (filters && filters.length > 0) {
query.filter = buildFilterTree(filters);
query.filter = buildFilterTree(filters, scopedVars);
}

return this._druidQuery(query);
Expand All @@ -327,10 +327,10 @@ function (angular, _, dateMath, moment) {
};
}

function buildFilterTree(filters) {
function buildFilterTree(filters, scopedVars) {
//Do template variable replacement
var replacedFilters = filters.map(function (filter) {
return filterTemplateExpanders[filter.type](filter);
return filterTemplateExpanders[filter.type](filter, scopedVars);
})
.map(function (filter) {
var finalFilter = _.omit(filter, 'negate');
Expand Down