mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 02:10:45 -06:00
improve cloudwatch tsdb
This commit is contained in:
parent
a21f53cf82
commit
f3a2dc7c5f
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user