Browse Source

stackdriver: adds null check to query

Erik Sundell 7 years ago
parent
commit
fa6e31c6d5
1 changed files with 17 additions and 9 deletions
  1. 17 9
      public/app/plugins/datasource/stackdriver/datasource.ts

+ 17 - 9
public/app/plugins/datasource/stackdriver/datasource.ts

@@ -12,15 +12,23 @@ export default class StackdriverDatasource {
   }
 
   async getTimeSeries(options) {
-    const queries = options.targets.filter(target => !target.hide).map(t => ({
-      refId: t.refId,
-      datasourceId: this.id,
-      metricType: t.metricType,
-      primaryAggregation: t.aggregation.crossSeriesReducer,
-      groupBys: t.aggregation.groupBys,
-      view: t.view || 'FULL',
-      filters: t.filters,
-    }));
+    const queries = options.targets.filter(target => !target.hide).map(t => {
+      if (!t.hasOwnProperty('aggregation')) {
+        t.aggregation = {
+          crossSeriesReducer: 'REDUCE_MEAN',
+          groupBys: [],
+        };
+      }
+      return {
+        refId: t.refId,
+        datasourceId: this.id,
+        metricType: t.metricType,
+        primaryAggregation: t.aggregation.crossSeriesReducer,
+        groupBys: t.aggregation.groupBys,
+        view: t.view || 'FULL',
+        filters: t.filters,
+      };
+    });
 
     const { data } = await this.backendSrv.datasourceRequest({
       url: '/api/tsdb/query',