Skip to content

Commit

Permalink
fix(influxdb): adds support for multi table values
Browse files Browse the repository at this point in the history
When quering for tag values without measurement
all tags and values should be shown

closes grafana#4726
  • Loading branch information
bergquist committed Apr 18, 2016
1 parent 7e66d0b commit fde6eee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
28 changes: 19 additions & 9 deletions public/app/plugins/datasource/influxdb/response_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@ export default class ResponseParser {
return [];
}

var series = influxResults.series[0];
return _.map(series.values, (value) => {
if (_.isArray(value)) {
if (query.toLowerCase().indexOf('show tag values') >= 0) {
return { text: (value[1] || value[0]) };
var res = [];
_.each(influxResults.series, (serie) => {
_.each(serie.values, (value) => {
if (_.isArray(value)) {
if (query.toLowerCase().indexOf('show tag values') >= 0) {
addUnique(res, { text: (value[1] || value[0])});
} else {
addUnique(res, { text: value[0]});
}
} else {
return { text: value[0] };
addUnique(res, {text: value});
}
} else {
return { text: value };
}
});
});

return res;
}
}

function addUnique(arr, value) {
if (!_.any(arr, value)) {
arr.push(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("influxdb response parser", () => {
{
"name": "hostnameTagValues",
"columns": ["hostname"],
"values": [ ["server1"], ["server2"] ]
"values": [ ["server1"], ["server2"], ["server2"] ]
}
]
}
Expand All @@ -54,16 +54,27 @@ describe("influxdb response parser", () => {
});
});

describe("response from 0.11.0", () => {
describe("response from 0.12.0", () => {
var response = {
"results": [
{
"series": [
{
"name": "cpu",
"columns": [ "key", "value"],
"values": [ [ "source", "site" ], [ "source", "api" ] ]
}
"values": [
[ "source", "site" ],
[ "source", "api" ]
]
},
{
"name": "logins",
"columns": [ "key", "value"],
"values": [
[ "source", "site" ],
[ "source", "webapi"]
]
},
]
}
]
Expand All @@ -72,15 +83,12 @@ describe("influxdb response parser", () => {
var result = this.parser.parse(query, response);

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[1].text).to.be('api');
expect(result[2].text).to.be('webapi');
});
});




});

describe("SHOW FIELD response", () => {
Expand Down

0 comments on commit fde6eee

Please sign in to comment.