feat(influxdb): support for policy selection in query editor, closes #2018

This commit is contained in:
Torkel Ödegaard 2016-01-18 18:38:36 +01:00
parent 3b5a583903
commit 510a21195a
4 changed files with 39 additions and 13 deletions

View File

@ -3,6 +3,7 @@
### New Features ###
* **Playlists**: Playlists can now be persisted and started from urls, closes [#3655](https://github.com/grafana/grafana/pull/3655)
* **Metadata**: Settings panel now shows dashboard metadata, closes [#3304](https://github.com/grafana/grafana/issues/3304)
* **InfluxDB**: Support for policy selection in query editor, closes [#2018](https://github.com/grafana/grafana/issues/2018)
### Breaking changes
**Plugin API**: Both datasource and panel plugin api (and plugin.json schema) as been updated, requiring a minor update to plugins. See [plugin api](https://github.com/grafana/grafana/blob/master/public/app/plugins/plugin_api.md) for more info.

View File

@ -117,14 +117,15 @@ function (angular, _, dateMath, InfluxSeries, InfluxQuery) {
if (!influxResults.series) {
return [];
}
var series = influxResults.series[0];
if (query.indexOf('SHOW MEASUREMENTS') === 0) {
return _.map(series.values, function(value) { return { text: value[0], expandable: true }; });
}
var flattenedValues = _.flatten(series.values);
return _.map(flattenedValues, function(value) { return { text: value, expandable: true }; });
return _.map(series.values, function(value) {
if (_.isArray(value)) {
return { text: value[0] };
} else {
return { text: value };
}
});
});
};

View File

@ -150,6 +150,23 @@ export default class InfluxQuery {
return str + '"' + tag.key + '" ' + operator + ' ' + value;
}
getMeasurementAndPolicy() {
var policy = this.target.policy
var measurement = this.target.measurement;
if (!measurement.match('^/.*/')) {
measurement = '"' + measurement+ '"';
}
if (policy !== 'default') {
policy = '"' + this.target.policy + '".';
} else {
policy = "";
}
return policy + measurement;
}
render() {
var target = this.target;
@ -177,12 +194,7 @@ export default class InfluxQuery {
query += selectText;
}
var measurement = target.measurement;
if (!measurement.match('^/.*/') && !measurement.match(/^merge\(.*\)/)) {
measurement = '"' + measurement+ '"';
}
query += ' FROM ' + measurement + ' WHERE ';
query += ' FROM ' + this.getMeasurementAndPolicy() + ' WHERE ';
var conditions = _.map(target.tags, (tag, index) => {
return this.renderTagCondition(tag, index);
});

View File

@ -15,6 +15,18 @@ describe('InfluxQuery', function() {
});
});
describe('render series with policy only', function() {
it('should generate correct query', function() {
var query = new InfluxQuery({
measurement: 'cpu',
policy: '5m_avg'
});
var queryText = query.render();
expect(queryText).to.be('SELECT mean("value") FROM "5m_avg"."cpu" WHERE $timeFilter GROUP BY time($interval) fill(null)');
});
});
describe('render series with math and alias', function() {
it('should generate correct query', function() {
var query = new InfluxQuery({