Commit 2dfa576c by Carl Bergquist Committed by GitHub

Merge pull request #11504 from hahnjo/11476-influxdb-show-cardinality

influxdb: Check before assuming first column to be 'time'
parents e6f38591 dfccabab
......@@ -151,11 +151,17 @@ export default class InfluxSeries {
_.each(this.series, (series, seriesIndex) => {
if (seriesIndex === 0) {
table.columns.push({ text: 'Time', type: 'time' });
j = 0;
// Check that the first column is indeed 'time'
if (series.columns[0] === 'time') {
// Push this now before the tags and with the right type
table.columns.push({ text: 'Time', type: 'time' });
j++;
}
_.each(_.keys(series.tags), function(key) {
table.columns.push({ text: key });
});
for (j = 1; j < series.columns.length; j++) {
for (; j < series.columns.length; j++) {
table.columns.push({ text: series.columns[j] });
}
}
......
......@@ -195,10 +195,34 @@ describe('when generating timeseries from influxdb response', function() {
expect(table.type).toBe('table');
expect(table.columns.length).toBe(5);
expect(table.columns[0].text).toEqual('Time');
expect(table.rows[0]).toEqual([1431946625000, 'Africa', 'server2', 23, 10]);
});
});
describe('given table response from SHOW CARDINALITY', function() {
var options = {
alias: '',
series: [
{
name: 'cpu',
columns: ['count'],
values: [[37]],
},
],
};
it('should return table', function() {
var series = new InfluxSeries(options);
var table = series.getTable();
expect(table.type).toBe('table');
expect(table.columns.length).toBe(1);
expect(table.columns[0].text).toEqual('count');
expect(table.rows[0]).toEqual([37]);
});
});
describe('given annotation response', function() {
describe('with empty tagsColumn', function() {
var options = {
......
......@@ -159,8 +159,8 @@ class SingleStatCtrl extends MetricsPanelCtrl {
}
setTableColumnToSensibleDefault(tableData) {
if (this.tableColumnOptions.length === 1) {
this.panel.tableColumn = this.tableColumnOptions[0];
if (tableData.columns.length === 1) {
this.panel.tableColumn = tableData.columns[0].text;
} else {
this.panel.tableColumn = _.find(tableData.columns, col => {
return col.type !== 'time';
......
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