mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* CloudWatch: Datasource improvements * Add statistic as template variale * Add wildcard to list of values * Template variable intercept dimension key * Return row specific errors when transformation error occured * Add meta feedback * Make it possible to retrieve values without known metrics * Add curated dashboard for EC2 * Fix broken tests * Use correct dashboard name * Display alert in case multi template var is being used for some certain props in the cloudwatch query * Minor fixes after feedback * Update dashboard json * Update snapshot test * Make sure region default is intercepted in cloudwatch link * Update dashboards * Include ec2 dashboard in ds * Do not include ec2 dashboard in beta1 * Display actual region
102 lines
2.4 KiB
Go
102 lines
2.4 KiB
Go
package cloudwatch
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/tsdb"
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
func (e *CloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, queryContext *tsdb.TsdbQuery) (*tsdb.Response, error) {
|
|
results := &tsdb.Response{
|
|
Results: make(map[string]*tsdb.QueryResult),
|
|
}
|
|
|
|
requestQueriesByRegion, err := e.parseQueries(queryContext)
|
|
if err != nil {
|
|
return results, err
|
|
}
|
|
resultChan := make(chan *tsdb.QueryResult, len(queryContext.Queries))
|
|
eg, ectx := errgroup.WithContext(ctx)
|
|
|
|
if len(requestQueriesByRegion) > 0 {
|
|
for r, q := range requestQueriesByRegion {
|
|
requestQueries := q
|
|
region := r
|
|
eg.Go(func() error {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
plog.Error("Execute Get Metric Data Query Panic", "error", err, "stack", log.Stack(1))
|
|
if theErr, ok := err.(error); ok {
|
|
resultChan <- &tsdb.QueryResult{
|
|
Error: theErr,
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
|
|
client, err := e.getClient(region)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
queries, err := e.transformRequestQueriesToCloudWatchQueries(requestQueries)
|
|
if err != nil {
|
|
for _, query := range requestQueries {
|
|
resultChan <- &tsdb.QueryResult{
|
|
RefId: query.RefId,
|
|
Error: err,
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
metricDataInput, err := e.buildMetricDataInput(queryContext, queries)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
cloudwatchResponses := make([]*cloudwatchResponse, 0)
|
|
mdo, err := e.executeRequest(ectx, client, metricDataInput)
|
|
if err != nil {
|
|
for _, query := range requestQueries {
|
|
resultChan <- &tsdb.QueryResult{
|
|
RefId: query.RefId,
|
|
Error: err,
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
responses, err := e.parseResponse(mdo, queries)
|
|
if err != nil {
|
|
for _, query := range requestQueries {
|
|
resultChan <- &tsdb.QueryResult{
|
|
RefId: query.RefId,
|
|
Error: err,
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
cloudwatchResponses = append(cloudwatchResponses, responses...)
|
|
res := e.transformQueryResponseToQueryResult(cloudwatchResponses)
|
|
for _, queryRes := range res {
|
|
resultChan <- queryRes
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
}
|
|
|
|
if err := eg.Wait(); err != nil {
|
|
return nil, err
|
|
}
|
|
close(resultChan)
|
|
for result := range resultChan {
|
|
results.Results[result.RefId] = result
|
|
}
|
|
|
|
return results, nil
|
|
}
|