Commit 99ae38a2 by Torkel Ödegaard

Merge pull request #4750 from bergquist/fix_influxb_showtag_values

[Influxb] Support for multible measurement results in showtag values
parents 80818f80 c148e54b
...@@ -12,17 +12,29 @@ export default class ResponseParser { ...@@ -12,17 +12,29 @@ export default class ResponseParser {
return []; return [];
} }
var series = influxResults.series[0]; var influxdb11format = query.toLowerCase().indexOf('show tag values') >= 0;
return _.map(series.values, (value) => {
if (_.isArray(value)) { var res = {};
if (query.toLowerCase().indexOf('show tag values') >= 0) { _.each(influxResults.series, serie => {
return { text: (value[1] || value[0]) }; _.each(serie.values, value => {
if (_.isArray(value)) {
if (influxdb11format) {
addUnique(res, value[1] || value[0]);
} else {
addUnique(res, value[0]);
}
} else { } else {
return { text: value[0] }; addUnique(res, value);
} }
} else { });
return { text: value }; });
}
return _.map(res, value => {
return { text: value};
}); });
} }
} }
function addUnique(arr, value) {
arr[value] = value;
}
...@@ -38,7 +38,7 @@ describe("influxdb response parser", () => { ...@@ -38,7 +38,7 @@ describe("influxdb response parser", () => {
{ {
"name": "hostnameTagValues", "name": "hostnameTagValues",
"columns": ["hostname"], "columns": ["hostname"],
"values": [ ["server1"], ["server2"] ] "values": [ ["server1"], ["server2"], ["server2"] ]
} }
] ]
} }
...@@ -54,7 +54,7 @@ describe("influxdb response parser", () => { ...@@ -54,7 +54,7 @@ describe("influxdb response parser", () => {
}); });
}); });
describe("response from 0.11.0", () => { describe("response from 0.12.0", () => {
var response = { var response = {
"results": [ "results": [
{ {
...@@ -62,8 +62,19 @@ describe("influxdb response parser", () => { ...@@ -62,8 +62,19 @@ describe("influxdb response parser", () => {
{ {
"name": "cpu", "name": "cpu",
"columns": [ "key", "value"], "columns": [ "key", "value"],
"values": [ [ "source", "site" ], [ "source", "api" ] ] "values": [
} [ "source", "site" ],
[ "source", "api" ]
]
},
{
"name": "logins",
"columns": [ "key", "value"],
"values": [
[ "source", "site" ],
[ "source", "webapi"]
]
},
] ]
} }
] ]
...@@ -72,15 +83,12 @@ describe("influxdb response parser", () => { ...@@ -72,15 +83,12 @@ describe("influxdb response parser", () => {
var result = this.parser.parse(query, response); var result = this.parser.parse(query, response);
it("should get two responses", () => { it("should get two responses", () => {
expect(_.size(result)).to.be(2); expect(_.size(result)).to.be(3);
expect(result[0].text).to.be('site'); expect(result[0].text).to.be('site');
expect(result[1].text).to.be('api'); expect(result[1].text).to.be('api');
expect(result[2].text).to.be('webapi');
}); });
}); });
}); });
describe("SHOW FIELD response", () => { describe("SHOW FIELD response", () => {
......
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