This reverts commit 7762839853.
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/tsdb"
|
||||
)
|
||||
@@ -14,9 +13,7 @@ import (
|
||||
// has more than one statistic defined, one cloudwatchQuery will be created for each statistic.
|
||||
// If the query doesn't have an Id defined by the user, we'll give it an with format `query[RefId]`. In the case
|
||||
// the incoming query had more than one stat, it will ge an id like `query[RefId]_[StatName]`, eg queryC_Average
|
||||
func (e *cloudWatchExecutor) transformRequestQueriesToCloudWatchQueries(requestQueries []*requestQuery) (
|
||||
map[string]*cloudWatchQuery, error) {
|
||||
plog.Debug("Transforming CloudWatch request queries")
|
||||
func (e *cloudWatchExecutor) transformRequestQueriesToCloudWatchQueries(requestQueries []*requestQuery) (map[string]*cloudWatchQuery, error) {
|
||||
cloudwatchQueries := make(map[string]*cloudWatchQuery)
|
||||
for _, requestQuery := range requestQueries {
|
||||
for _, stat := range requestQuery.Statistics {
|
||||
@@ -55,22 +52,17 @@ func (e *cloudWatchExecutor) transformRequestQueriesToCloudWatchQueries(requestQ
|
||||
|
||||
func (e *cloudWatchExecutor) transformQueryResponseToQueryResult(cloudwatchResponses []*cloudwatchResponse) map[string]*tsdb.QueryResult {
|
||||
responsesByRefID := make(map[string][]*cloudwatchResponse)
|
||||
refIDs := sort.StringSlice{}
|
||||
for _, res := range cloudwatchResponses {
|
||||
refIDs = append(refIDs, res.RefId)
|
||||
responsesByRefID[res.RefId] = append(responsesByRefID[res.RefId], res)
|
||||
}
|
||||
// Ensure stable results
|
||||
refIDs.Sort()
|
||||
|
||||
results := make(map[string]*tsdb.QueryResult)
|
||||
for _, refID := range refIDs {
|
||||
responses := responsesByRefID[refID]
|
||||
for refID, responses := range responsesByRefID {
|
||||
queryResult := tsdb.NewQueryResult()
|
||||
queryResult.RefId = refID
|
||||
queryResult.Meta = simplejson.New()
|
||||
queryResult.Series = tsdb.TimeSeriesSlice{}
|
||||
frames := make(data.Frames, 0, len(responses))
|
||||
timeSeries := make(tsdb.TimeSeriesSlice, 0)
|
||||
|
||||
requestExceededMaxLimit := false
|
||||
partialData := false
|
||||
@@ -80,7 +72,7 @@ func (e *cloudWatchExecutor) transformQueryResponseToQueryResult(cloudwatchRespo
|
||||
}{}
|
||||
|
||||
for _, response := range responses {
|
||||
frames = append(frames, response.DataFrames...)
|
||||
timeSeries = append(timeSeries, *response.series...)
|
||||
requestExceededMaxLimit = requestExceededMaxLimit || response.RequestExceededMaxLimit
|
||||
partialData = partialData || response.PartialData
|
||||
queryMeta = append(queryMeta, struct {
|
||||
@@ -93,8 +85,8 @@ func (e *cloudWatchExecutor) transformQueryResponseToQueryResult(cloudwatchRespo
|
||||
})
|
||||
}
|
||||
|
||||
sort.Slice(frames, func(i, j int) bool {
|
||||
return frames[i].Name < frames[j].Name
|
||||
sort.Slice(timeSeries, func(i, j int) bool {
|
||||
return timeSeries[i].Name < timeSeries[j].Name
|
||||
})
|
||||
|
||||
if requestExceededMaxLimit {
|
||||
@@ -104,7 +96,7 @@ func (e *cloudWatchExecutor) transformQueryResponseToQueryResult(cloudwatchRespo
|
||||
queryResult.ErrorString = "Cloudwatch GetMetricData error: Too many datapoints requested - your search has been limited. Please try to reduce the time range"
|
||||
}
|
||||
|
||||
queryResult.Dataframes = tsdb.NewDecodedDataFrames(frames)
|
||||
queryResult.Series = append(queryResult.Series, timeSeries...)
|
||||
queryResult.Meta.Set("gmdMeta", queryMeta)
|
||||
results[refID] = queryResult
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user