Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8a8f063
Merge pull request #1 from GoshPosh/period_granularity
Gauravshah Aug 3, 2017
c934b3c
Merge pull request #2 from GoshPosh/autocomplete_metrics
Gauravshah Aug 9, 2017
2d3dbcf
Merge pull request #3 from GoshPosh/edit_aggregations
Gauravshah Aug 9, 2017
574d950
Merge pull request #4 from GoshPosh/period_granularity
Gauravshah Aug 9, 2017
69ed520
Merge branch 'master' of github.com:GoshPosh/druidplugin into filter_…
Gauravshah Aug 9, 2017
288d2fc
Merge pull request #5 from GoshPosh/filter_values_auto_complete_lates…
Gauravshah Aug 9, 2017
6078555
Merge pull request #6 from GoshPosh/hide_metrics
Gauravshah Aug 11, 2017
0020365
added scoped vars
Gauravshah Sep 4, 2017
1e5d9c0
Merge branch 'master' of github.com:GoshPosh/druidplugin into enable_…
Gauravshah Sep 4, 2017
f66ef4e
Merge branch 'master' of github.com:GoshPosh/druidplugin into enable_…
Gauravshah Sep 4, 2017
b619ac8
Merge pull request #8 from GoshPosh/hide_metrics
Gauravshah Sep 4, 2017
4fe28a6
Merge branches 'enable_scoped_variables_master' and 'master' of githu…
Gauravshah Sep 4, 2017
d2f2bd2
Merge pull request #9 from GoshPosh/enable_scoped_variables_master
Gauravshah Sep 4, 2017
45c5d51
Merge branches 'abhisant_master' and 'master' of github.com:GoshPosh/…
Gauravshah Oct 6, 2017
7b672c1
Merge pull request #12 from GoshPosh/filter_values_autocomplete_rebas…
Gauravshah Nov 6, 2017
16ea751
Merge pull request #13 from GoshPosh/from_time_fix
Gauravshah Nov 6, 2017
903558b
added an option to ignore a filter when a predefined value is selected
ShilpaSivanesan Aug 16, 2018
53674d1
Merge pull request #14 from GoshPosh/druid_filter_fix_v2
Gauravshah Aug 16, 2018
7adeff5
adding filter.pattern for supporting regex
ShilpaSivanesan Aug 16, 2018
6091117
changed conditions
ShilpaSivanesan Aug 16, 2018
f48d906
Merge pull request #15 from GoshPosh/druid_filter_fix_v2
Gauravshah Aug 16, 2018
7eacf6f
condition fix
ShilpaSivanesan Aug 17, 2018
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
49 changes: 29 additions & 20 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 @@ -138,20 +138,20 @@ 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) {
var datasource = target.druidDS;
var filters = target.filters;
var aggregators = target.aggregators;
var postAggregators = target.postAggregators;
var groupBy = _.map(target.groupBy, (e) => { return templateSrv.replace(e) });
var groupBy = _.map(target.groupBy, (e) => { return templateSrv.replace(e, scopedVars) });
var limitSpec = null;
var metricNames = getMetricNames(aggregators, postAggregators);
var intervals = getQueryIntervals(from, to);
Expand All @@ -167,27 +167,27 @@ function (angular, _, dateMath, moment) {
if (target.queryType === 'topN') {
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)
var dimension = templateSrv.replace(target.dimension, scopedVars);
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 @@ -219,7 +219,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 @@ -231,13 +231,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 @@ -248,14 +248,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 @@ -270,14 +270,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 @@ -290,7 +290,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 @@ -317,11 +317,20 @@ 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);
})
.filter(function(filter) {
if(filter.pattern)
return filter.pattern!="_REMOVE_FILTER_"
else if(filter.value)
return filter.value!="_REMOVE_FILTER_"
else
return true
}
)
.map(function (filter) {
var finalFilter = _.omit(filter, 'negate');
if (filter.negate) {
Expand Down
51 changes: 30 additions & 21 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 @@ -76,7 +76,7 @@ function (angular, _, dateMath, moment) {
this.getFilterValues = function (target, panelRange, query) {
var topNquery = {
"queryType": "topN",
"dataSource": target.datasource,
"dataSource": target.druidDS,
"granularity": 'all',
"threshold": 10,
"dimension": target.currentFilter.dimension,
Expand Down Expand Up @@ -138,20 +138,20 @@ 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) {
var datasource = target.druidDS;
var filters = target.filters;
var aggregators = target.aggregators;
var postAggregators = target.postAggregators;
var groupBy = _.map(target.groupBy, (e) => { return templateSrv.replace(e) });
var groupBy = _.map(target.groupBy, (e) => { return templateSrv.replace(e, scopedVars) });
var limitSpec = null;
var metricNames = getMetricNames(aggregators, postAggregators);
var intervals = getQueryIntervals(from, to);
Expand All @@ -167,27 +167,27 @@ function (angular, _, dateMath, moment) {
if (target.queryType === 'topN') {
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)
var dimension = templateSrv.replace(target.dimension, scopedVars);
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 @@ -219,7 +219,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 @@ -231,13 +231,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 @@ -248,14 +248,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 @@ -270,14 +270,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 @@ -290,7 +290,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 @@ -317,11 +317,20 @@ 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);
})
.filter(function(filter) {
if(filter.pattern)
return filter.pattern!="_REMOVE_FILTER_"
else if(filter.value)
return filter.value!="_REMOVE_FILTER_"
else
return true
}
)
.map(function (filter) {
var finalFilter = _.omit(filter, 'negate');
if (filter.negate) {
Expand Down