Mitsuhiro Tanda 8 лет назад
Родитель
Сommit
f3a2dc7c5f
2 измененных файлов с 33 добавлено и 30 удалено
  1. 4 3
      pkg/tsdb/cloudwatch/annotation_query.go
  2. 29 27
      pkg/tsdb/cloudwatch/metric_find_query.go

+ 4 - 3
pkg/tsdb/cloudwatch/annotation_query.go

@@ -110,9 +110,10 @@ func (e *CloudWatchExecutor) executeAnnotationQuery(ctx context.Context, queryCo
 	annotations := make([]map[string]string, 0)
 	for _, alarmName := range alarmNames {
 		params := &cloudwatch.DescribeAlarmHistoryInput{
-			AlarmName: alarmName,
-			StartDate: aws.Time(startTime),
-			EndDate:   aws.Time(endTime),
+			AlarmName:  alarmName,
+			StartDate:  aws.Time(startTime),
+			EndDate:    aws.Time(endTime),
+			MaxRecords: aws.Int64(100),
 		}
 		resp, err := svc.DescribeAlarmHistory(params)
 		if err != nil {

+ 29 - 27
pkg/tsdb/cloudwatch/metric_find_query.go

@@ -392,40 +392,42 @@ func (e *CloudWatchExecutor) handleGetEc2InstanceAttribute(ctx context.Context,
 
 	result := make([]suggestData, 0)
 	dupCheck := make(map[string]bool)
-	for _, instance := range instances.Reservations[0].Instances {
-		tags := make(map[string]string)
-		for _, tag := range instance.Tags {
-			tags[*tag.Key] = *tag.Value
-		}
+	for _, reservation := range instances.Reservations {
+		for _, instance := range reservation.Instances {
+			tags := make(map[string]string)
+			for _, tag := range instance.Tags {
+				tags[*tag.Key] = *tag.Value
+			}
 
-		var data string
-		if strings.Index(attributeName, "Tags.") == 0 {
-			tagName := attributeName[5:]
-			data = tags[tagName]
-		} else {
-			attributePath := strings.Split(attributeName, ".")
-			v := reflect.ValueOf(instance)
-			for _, key := range attributePath {
-				if v.Kind() == reflect.Ptr {
-					v = v.Elem()
+			var data string
+			if strings.Index(attributeName, "Tags.") == 0 {
+				tagName := attributeName[5:]
+				data = tags[tagName]
+			} else {
+				attributePath := strings.Split(attributeName, ".")
+				v := reflect.ValueOf(instance)
+				for _, key := range attributePath {
+					if v.Kind() == reflect.Ptr {
+						v = v.Elem()
+					}
+					if v.Kind() != reflect.Struct {
+						return nil, errors.New("invalid attribute path")
+					}
+					v = v.FieldByName(key)
 				}
-				if v.Kind() != reflect.Struct {
+				if attr, ok := v.Interface().(*string); ok {
+					data = *attr
+				} else {
 					return nil, errors.New("invalid attribute path")
 				}
-				v = v.FieldByName(key)
-			}
-			if attr, ok := v.Interface().(*string); ok {
-				data = *attr
-			} else {
-				return nil, errors.New("invalid attribute path")
 			}
-		}
 
-		if _, exists := dupCheck[data]; exists {
-			continue
+			if _, exists := dupCheck[data]; exists {
+				continue
+			}
+			dupCheck[data] = true
+			result = append(result, suggestData{Text: data, Value: data})
 		}
-		dupCheck[data] = true
-		result = append(result, suggestData{Text: data, Value: data})
 	}
 
 	sort.Slice(result, func(i, j int) bool {