diff --git a/public/app/plugins/datasource/influxdb/influx_series.ts b/public/app/plugins/datasource/influxdb/influx_series.ts index a177ef3bb73..89e2d01b85b 100644 --- a/public/app/plugins/datasource/influxdb/influx_series.ts +++ b/public/app/plugins/datasource/influxdb/influx_series.ts @@ -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] }); } } diff --git a/public/app/plugins/datasource/influxdb/specs/influx_series.jest.ts b/public/app/plugins/datasource/influxdb/specs/influx_series.jest.ts index 8ae4a335828..8c8fee9ab9f 100644 --- a/public/app/plugins/datasource/influxdb/specs/influx_series.jest.ts +++ b/public/app/plugins/datasource/influxdb/specs/influx_series.jest.ts @@ -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 = {