Commit ba48f40d by bergquist

feat(influxdb): bases parsing upon query

parent 6fafc8db
......@@ -112,7 +112,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
}
return this._seriesQuery(interpolated)
.then(_.curry(this.responseParser.parse)(queryType));
.then(_.curry(this.responseParser.parse)(query));
};
this._seriesQuery = function(query) {
......
......@@ -4,7 +4,7 @@ import _ from 'lodash';
export default class ResponseParser {
parse(queryType, results) {
parse(query, results) {
if (!results || results.results.length === 0) { return []; }
var influxResults = results.results[0];
......@@ -13,9 +13,9 @@ export default class ResponseParser {
}
var series = influxResults.series[0];
return _.map(series.values, function(value) {
return _.map(series.values, (value) => {
if (_.isArray(value)) {
if (queryType === 'SHOW_TAGS') {
if (query.indexOf('SHOW TAG VALUES') >= 0) {
return { text: (value[1] || value[0]) };
} else {
return { text: value[0] };
......
......@@ -4,7 +4,56 @@ import ResponseParser from '../response_parser';
describe("influxdb response parser", () => {
this.parser = new ResponseParser();
describe("SHOW_TAGS response", () => {
describe("SHOW TAG response", () => {
var query = 'SHOW TAG KEYS FROM "cpu"';
describe("response from 0.10.0", () => {
var response = {
"results": [
{
"series": [
{
"name": "cpu",
"columns": ["tagKey"],
"values": [ ["datacenter"], ["hostname"], ["source"] ]
}
]
}
]
};
var result = this.parser.parse(query, response);
it("expects three results", () => {
expect(_.size(result)).to.be(3);
});
});
describe("response from 0.11.0", () => {
var response = {
"results": [
{
"series": [
{
"name": "cpu",
"columns": ["tagKey"],
"values": [ ["datacenter"], ["hostname"], ["source"] ]
}
]
}
]
};
var result = this.parser.parse(query, response);
it("expects three results", () => {
expect(_.size(result)).to.be(3);
});
});
});
describe("SHOW TAG VALUES response", () => {
var query = 'SHOW TAG VALUES FROM "cpu" WITH KEY = "hostname"';
describe("response from 0.10.0", () => {
var response = {
"results": [
......@@ -20,7 +69,7 @@ describe("influxdb response parser", () => {
]
};
var result = this.parser.parse('SHOW_TAGS', response);
var result = this.parser.parse(query, response);
it("should get two responses", () => {
expect(_.size(result)).to.be(2);
......@@ -44,7 +93,7 @@ describe("influxdb response parser", () => {
]
};
var result = this.parser.parse('SHOW_TAGS', response);
var result = this.parser.parse(query, response);
it("should get two responses", () => {
expect(_.size(result)).to.be(2);
......@@ -52,9 +101,14 @@ describe("influxdb response parser", () => {
expect(result[1].text).to.be('api');
});
});
});
describe("SHOW_FIELDS response", () => {
describe("SHOW FIELD response", () => {
var query = 'SHOW FIELD KEYS FROM "cpu"';
describe("response from 0.10.0", () => {
var response = {
"results": [
......@@ -72,7 +126,7 @@ describe("influxdb response parser", () => {
]
};
var result = this.parser.parse('SHOW_FIELDS', response);
var result = this.parser.parse(query, response);
it("should get two responses", () => {
expect(_.size(result)).to.be(6);
});
......@@ -93,7 +147,7 @@ describe("influxdb response parser", () => {
]
};
var result = this.parser.parse('SHOW_FIELDS', response);
var result = this.parser.parse(query, response);
it("should get two responses", () => {
expect(_.size(result)).to.be(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment