Explorar o código

Merge branch 'master' into 11392_whats_new_v51

* master:
  build: only lint the pkg folder
  changelog: adds note about closing #11476
  singlestat: Fix optimization in setTableColumnToSensibleDefault
  influxdb: Check before assuming first column to be 'time'
bergquist %!s(int64=7) %!d(string=hai) anos
pai
achega
b5820d930c

+ 1 - 1
.circleci/config.yml

@@ -31,7 +31,7 @@ jobs:
           command: 'gometalinter --install'
           command: 'gometalinter --install'
       - run:
       - run:
           name: run some linters
           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:
   test-frontend:
     docker:
     docker:

+ 1 - 0
CHANGELOG.md

@@ -56,6 +56,7 @@
 * **Dashboard**: Sizing and positioning of settings menu icons [#11572](https://github.com/grafana/grafana/pull/11572)
 * **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)
 * **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)
 * **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
 ### Tech
 * Backend code simplification [#11613](https://github.com/grafana/grafana/pull/11613), thx [@knweiss](https://github.com/knweiss)
 * Backend code simplification [#11613](https://github.com/grafana/grafana/pull/11613), thx [@knweiss](https://github.com/knweiss)

+ 8 - 2
public/app/plugins/datasource/influxdb/influx_series.ts

@@ -151,11 +151,17 @@ export default class InfluxSeries {
 
 
     _.each(this.series, (series, seriesIndex) => {
     _.each(this.series, (series, seriesIndex) => {
       if (seriesIndex === 0) {
       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) {
         _.each(_.keys(series.tags), function(key) {
           table.columns.push({ text: 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] });
           table.columns.push({ text: series.columns[j] });
         }
         }
       }
       }

+ 24 - 0
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.type).toBe('table');
       expect(table.columns.length).toBe(5);
       expect(table.columns.length).toBe(5);
+      expect(table.columns[0].text).toEqual('Time');
       expect(table.rows[0]).toEqual([1431946625000, 'Africa', 'server2', 23, 10]);
       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('given annotation response', function() {
     describe('with empty tagsColumn', function() {
     describe('with empty tagsColumn', function() {
       var options = {
       var options = {

+ 2 - 2
public/app/plugins/panel/singlestat/module.ts

@@ -159,8 +159,8 @@ class SingleStatCtrl extends MetricsPanelCtrl {
   }
   }
 
 
   setTableColumnToSensibleDefault(tableData) {
   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 {
     } else {
       this.panel.tableColumn = _.find(tableData.columns, col => {
       this.panel.tableColumn = _.find(tableData.columns, col => {
         return col.type !== 'time';
         return col.type !== 'time';