From e3dbef755ae418d2f8ff1356a2bd85eb137dae45 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 5 Apr 2018 20:53:22 +0200 Subject: [PATCH 1/4] 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). --- .../datasource/influxdb/influx_series.ts | 10 ++++++-- .../influxdb/specs/influx_series.jest.ts | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) 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 = { From dfccabab75ae6d99ba5057f4dc2c8598b697760c Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Thu, 5 Apr 2018 20:59:11 +0200 Subject: [PATCH 2/4] singlestat: Fix optimization in setTableColumnToSensibleDefault tableColumnOptions is an associative array that has no property length. Use tableData.columns as in the default case which works just fine. --- public/app/plugins/panel/singlestat/module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 776033536dd..c7f523a9591 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -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'; From f50bcb6aae452da0970975338d34c0a4dfa1ab08 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 19 Apr 2018 11:20:29 +0200 Subject: [PATCH 3/4] changelog: adds note about closing #11476 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 334fa47eae9..5edc8397412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ * **Dashboard**: Sizing and positioning of settings menu icons [#11572](https://github.com/grafana/grafana/pull/11572) * **Dashboard**: Add search filter/tabs to new panel control [#10427](https://github.com/grafana/grafana/issues/10427) * **Folders**: User with org viewer role should not be able to save/move dashboards in/to general folder [#11553](https://github.com/grafana/grafana/issues/11553) +* **Influxdb**: Dont assume the first column in table response is time. [#11476](https://github.com/grafana/grafana/issues/11476), thx [@hahnjo](https://github.com/hahnjo) ### Tech * Backend code simplification [#11613](https://github.com/grafana/grafana/pull/11613), thx [@knweiss](https://github.com/knweiss) From 7a622318168f2b113ef7396742f307f23db35eed Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 19 Apr 2018 11:29:02 +0200 Subject: [PATCH 4/4] build: only lint the pkg folder --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8b6d8506800..603c5fe0720 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,7 +31,7 @@ jobs: command: 'gometalinter --install' - run: name: run some linters - command: 'gometalinter --vendor --deadline 6m --disable-all --enable=structcheck --enable=unconvert --enable=varcheck ./...' + command: 'gometalinter --vendor --deadline 6m --disable-all --enable=structcheck --enable=unconvert --enable=varcheck ./pkg/...' test-frontend: docker: