mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
influxdb: Check before assuming first column to be 'time'
When running queries like 'SHOW [...] CARDINALITY' introduced with InfluxDB 1.4 there is only a single column 'count'. However, the data source always assumed 'time' which threw an error because the code couldn't find a non-time column to display. This change actually checks this assumption and thereby fixes displaying the result in a Singlestat in Table mode (closes #11476).
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user