Explorar o código

CloudWatch: fix color order (#16408)

* fix cloudwatch color order

* fix test

* use for-of
Mitsuhiro Tanda %!s(int64=6) %!d(string=hai) anos
pai
achega
d7d20a5b10

+ 5 - 4
public/app/plugins/datasource/cloudwatch/datasource.ts

@@ -138,15 +138,16 @@ export default class CloudWatchDatasource {
       const data = [];
 
       if (res.results) {
-        _.forEach(res.results, queryRes => {
-          _.forEach(queryRes.series, series => {
+        for (const query of request.queries) {
+          const queryRes = res.results[query.refId];
+          for (const series of queryRes.series) {
             const s = { target: series.name, datapoints: series.points } as any;
             if (queryRes.meta.unit) {
               s.unit = queryRes.meta.unit;
             }
             data.push(s);
-          });
-        });
+          }
+        }
       }
 
       return { data: data };

+ 5 - 0
public/app/plugins/datasource/cloudwatch/specs/datasource.test.ts

@@ -42,6 +42,7 @@ describe('CloudWatchDatasource', () => {
       rangeRaw: { from: 1483228800, to: 1483232400 },
       targets: [
         {
+          refId: 'A',
           region: 'us-east-1',
           namespace: 'AWS/EC2',
           metricName: 'CPUUtilization',
@@ -103,6 +104,7 @@ describe('CloudWatchDatasource', () => {
         rangeRaw: { from: 1483228800, to: 1483232400 },
         targets: [
           {
+            refId: 'A',
             region: 'us-east-1',
             namespace: 'AWS/EC2',
             metricName: 'CPUUtilization',
@@ -128,6 +130,7 @@ describe('CloudWatchDatasource', () => {
         rangeRaw: { from: 1483228800, to: 1483232400 },
         targets: [
           {
+            refId: 'A',
             region: 'us-east-1',
             namespace: 'AWS/EC2',
             metricName: 'CPUUtilization',
@@ -178,6 +181,7 @@ describe('CloudWatchDatasource', () => {
         rangeRaw: { from: 1483228800, to: 1483232400 },
         targets: [
           {
+            refId: 'A',
             region: 'default',
             namespace: 'AWS/EC2',
             metricName: 'CPUUtilization',
@@ -203,6 +207,7 @@ describe('CloudWatchDatasource', () => {
       rangeRaw: { from: 1483228800, to: 1483232400 },
       targets: [
         {
+          refId: 'A',
           region: 'us-east-1',
           namespace: 'AWS/ApplicationELB',
           metricName: 'TargetResponseTime',