2017-04-03 07:50:40 -05:00
|
|
|
package cloudwatch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-03-23 10:32:12 -05:00
|
|
|
"encoding/json"
|
2020-04-25 15:48:20 -05:00
|
|
|
"fmt"
|
2017-04-03 07:50:40 -05:00
|
|
|
"regexp"
|
2020-04-25 15:48:20 -05:00
|
|
|
"time"
|
2017-04-03 07:50:40 -05:00
|
|
|
|
2020-07-23 11:52:22 -05:00
|
|
|
"github.com/aws/aws-sdk-go/aws/client"
|
2020-07-14 01:23:23 -05:00
|
|
|
"github.com/aws/aws-sdk-go/aws/request"
|
2020-07-23 11:52:22 -05:00
|
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
2020-07-14 01:23:23 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
2020-07-23 11:52:22 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
|
2020-04-25 15:48:20 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
2020-07-23 01:17:20 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/cloudwatchlogs/cloudwatchlogsiface"
|
2020-07-23 11:52:22 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2019-04-15 10:55:07 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
|
2020-07-23 11:52:22 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
|
2019-04-15 10:55:07 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi/resourcegroupstaggingapiiface"
|
2021-03-23 10:32:12 -05:00
|
|
|
"github.com/grafana/grafana-aws-sdk/pkg/awsds"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
2020-04-25 15:48:20 -05:00
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2019-05-13 01:45:54 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
2021-03-23 10:32:12 -05:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
2020-10-28 03:36:57 -05:00
|
|
|
"github.com/grafana/grafana/pkg/registry"
|
2020-07-14 01:23:23 -05:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2017-04-03 07:50:40 -05:00
|
|
|
)
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
type datasourceInfo struct {
|
|
|
|
profile string
|
|
|
|
region string
|
|
|
|
authType awsds.AuthType
|
|
|
|
assumeRoleARN string
|
|
|
|
externalID string
|
|
|
|
namespace string
|
|
|
|
endpoint string
|
|
|
|
|
|
|
|
accessKey string
|
|
|
|
secretKey string
|
|
|
|
|
|
|
|
datasourceID int64
|
|
|
|
}
|
|
|
|
|
2020-05-13 14:17:06 -05:00
|
|
|
const cloudWatchTSFormat = "2006-01-02 15:04:05.000"
|
2020-07-14 01:23:23 -05:00
|
|
|
const defaultRegion = "default"
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2020-05-13 08:34:23 -05:00
|
|
|
// Constants also defined in datasource/cloudwatch/datasource.ts
|
2020-05-13 14:17:06 -05:00
|
|
|
const logIdentifierInternal = "__log__grafana_internal__"
|
|
|
|
const logStreamIdentifierInternal = "__logstream__grafana_internal__"
|
2020-05-13 08:34:23 -05:00
|
|
|
|
2020-07-14 01:23:23 -05:00
|
|
|
var plog = log.New("tsdb.cloudwatch")
|
|
|
|
var aliasFormat = regexp.MustCompile(`\{\{\s*(.+?)\s*\}\}`)
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2020-07-14 01:23:23 -05:00
|
|
|
func init() {
|
2020-10-28 03:36:57 -05:00
|
|
|
registry.Register(®istry.Descriptor{
|
|
|
|
Name: "CloudWatchService",
|
|
|
|
InitPriority: registry.Low,
|
|
|
|
Instance: &CloudWatchService{},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type CloudWatchService struct {
|
2021-03-23 10:32:12 -05:00
|
|
|
LogsService *LogsService `inject:""`
|
|
|
|
BackendPluginManager backendplugin.Manager `inject:""`
|
|
|
|
Cfg *setting.Cfg `inject:""`
|
2020-10-28 03:36:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *CloudWatchService) Init() error {
|
2021-03-23 10:32:12 -05:00
|
|
|
plog.Debug("initing")
|
|
|
|
|
|
|
|
im := datasource.NewInstanceManager(NewInstanceSettings())
|
|
|
|
|
|
|
|
factory := coreplugin.New(backend.ServeOpts{
|
|
|
|
QueryDataHandler: newExecutor(s.LogsService, im, s.Cfg, awsds.NewSessionCache()),
|
|
|
|
})
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-05-12 13:05:16 -05:00
|
|
|
if err := s.BackendPluginManager.RegisterAndStart(context.Background(), "cloudwatch", factory); err != nil {
|
2021-03-23 10:32:12 -05:00
|
|
|
plog.Error("Failed to register plugin", "error", err)
|
|
|
|
}
|
|
|
|
return nil
|
2021-03-12 07:30:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type SessionCache interface {
|
|
|
|
GetSession(region string, s awsds.AWSDatasourceSettings) (*session.Session, error)
|
2021-03-08 00:02:49 -06:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func newExecutor(logsService *LogsService, im instancemgmt.InstanceManager, cfg *setting.Cfg, sessions SessionCache) *cloudWatchExecutor {
|
2020-07-23 11:52:22 -05:00
|
|
|
return &cloudWatchExecutor{
|
2021-03-12 07:30:21 -06:00
|
|
|
logsService: logsService,
|
2021-03-23 10:32:12 -05:00
|
|
|
im: im,
|
|
|
|
cfg: cfg,
|
2021-03-12 07:30:21 -06:00
|
|
|
sessions: sessions,
|
2020-07-14 01:23:23 -05:00
|
|
|
}
|
|
|
|
}
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func NewInstanceSettings() datasource.InstanceFactoryFunc {
|
|
|
|
return func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
|
|
|
var jsonData map[string]string
|
|
|
|
|
|
|
|
err := json.Unmarshal(settings.JSONData, &jsonData)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error reading settings: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
model := datasourceInfo{
|
|
|
|
profile: jsonData["profile"],
|
|
|
|
region: jsonData["defaultRegion"],
|
|
|
|
assumeRoleARN: jsonData["assumeRoleArn"],
|
|
|
|
externalID: jsonData["externalId"],
|
|
|
|
endpoint: jsonData["endpoint"],
|
|
|
|
namespace: jsonData["customMetricsNamespaces"],
|
|
|
|
datasourceID: settings.ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
atStr := jsonData["authType"]
|
|
|
|
at := awsds.AuthTypeDefault
|
|
|
|
switch atStr {
|
|
|
|
case "credentials":
|
|
|
|
at = awsds.AuthTypeSharedCreds
|
|
|
|
case "keys":
|
|
|
|
at = awsds.AuthTypeKeys
|
|
|
|
case "default":
|
|
|
|
at = awsds.AuthTypeDefault
|
|
|
|
case "ec2_iam_role":
|
|
|
|
at = awsds.AuthTypeEC2IAMRole
|
|
|
|
case "arn":
|
|
|
|
at = awsds.AuthTypeDefault
|
|
|
|
plog.Warn("Authentication type \"arn\" is deprecated, falling back to default")
|
|
|
|
default:
|
|
|
|
plog.Warn("Unrecognized AWS authentication type", "type", atStr)
|
|
|
|
}
|
|
|
|
|
|
|
|
model.authType = at
|
|
|
|
|
|
|
|
if model.profile == "" {
|
|
|
|
model.profile = settings.Database // legacy support
|
|
|
|
}
|
|
|
|
|
|
|
|
model.accessKey = settings.DecryptedSecureJSONData["accessKey"]
|
|
|
|
model.secretKey = settings.DecryptedSecureJSONData["secretKey"]
|
|
|
|
|
|
|
|
return model, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 01:23:23 -05:00
|
|
|
// cloudWatchExecutor executes CloudWatch requests.
|
|
|
|
type cloudWatchExecutor struct {
|
2020-10-28 03:36:57 -05:00
|
|
|
ec2Client ec2iface.EC2API
|
|
|
|
rgtaClient resourcegroupstaggingapiiface.ResourceGroupsTaggingAPIAPI
|
|
|
|
|
|
|
|
logsService *LogsService
|
2021-03-23 10:32:12 -05:00
|
|
|
im instancemgmt.InstanceManager
|
2021-03-09 14:20:59 -06:00
|
|
|
cfg *setting.Cfg
|
2021-03-12 07:30:21 -06:00
|
|
|
sessions SessionCache
|
2020-04-25 15:48:20 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func (e *cloudWatchExecutor) newSession(region string, pluginCtx backend.PluginContext) (*session.Session, error) {
|
|
|
|
dsInfo, err := e.getDSInfo(pluginCtx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if region == defaultRegion {
|
|
|
|
region = dsInfo.region
|
|
|
|
}
|
2020-10-12 10:58:58 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
return e.sessions.GetSession(region, awsds.AWSDatasourceSettings{
|
|
|
|
Profile: dsInfo.profile,
|
|
|
|
Region: region,
|
|
|
|
AuthType: dsInfo.authType,
|
|
|
|
AssumeRoleARN: dsInfo.assumeRoleARN,
|
|
|
|
ExternalID: dsInfo.externalID,
|
|
|
|
Endpoint: dsInfo.endpoint,
|
|
|
|
DefaultRegion: dsInfo.region,
|
|
|
|
AccessKey: dsInfo.accessKey,
|
|
|
|
SecretKey: dsInfo.secretKey,
|
|
|
|
})
|
2020-07-23 11:52:22 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func (e *cloudWatchExecutor) getCWClient(region string, pluginCtx backend.PluginContext) (cloudwatchiface.CloudWatchAPI, error) {
|
|
|
|
sess, err := e.newSession(region, pluginCtx)
|
2020-04-25 15:48:20 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-07 04:36:13 -06:00
|
|
|
return NewCWClient(sess), nil
|
2017-04-03 07:50:40 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func (e *cloudWatchExecutor) getCWLogsClient(region string, pluginCtx backend.PluginContext) (cloudwatchlogsiface.CloudWatchLogsAPI, error) {
|
|
|
|
sess, err := e.newSession(region, pluginCtx)
|
2020-07-14 01:23:23 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-07 04:36:13 -06:00
|
|
|
logsClient := NewCWLogsClient(sess)
|
2020-07-23 11:52:22 -05:00
|
|
|
|
|
|
|
return logsClient, nil
|
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func (e *cloudWatchExecutor) getEC2Client(region string, pluginCtx backend.PluginContext) (ec2iface.EC2API, error) {
|
2020-07-23 11:52:22 -05:00
|
|
|
if e.ec2Client != nil {
|
|
|
|
return e.ec2Client, nil
|
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
sess, err := e.newSession(region, pluginCtx)
|
2020-07-23 11:52:22 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
e.ec2Client = newEC2Client(sess)
|
2020-07-14 01:23:23 -05:00
|
|
|
|
2020-07-23 11:52:22 -05:00
|
|
|
return e.ec2Client, nil
|
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func (e *cloudWatchExecutor) getRGTAClient(region string, pluginCtx backend.PluginContext) (resourcegroupstaggingapiiface.ResourceGroupsTaggingAPIAPI,
|
2020-07-23 11:52:22 -05:00
|
|
|
error) {
|
|
|
|
if e.rgtaClient != nil {
|
|
|
|
return e.rgtaClient, nil
|
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
sess, err := e.newSession(region, pluginCtx)
|
2020-07-23 11:52:22 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
e.rgtaClient = newRGTAClient(sess)
|
|
|
|
|
|
|
|
return e.rgtaClient, nil
|
2017-04-03 07:50:40 -05:00
|
|
|
}
|
|
|
|
|
2020-07-23 01:17:20 -05:00
|
|
|
func (e *cloudWatchExecutor) alertQuery(ctx context.Context, logsClient cloudwatchlogsiface.CloudWatchLogsAPI,
|
2021-03-23 10:32:12 -05:00
|
|
|
queryContext backend.DataQuery, model *simplejson.Json) (*cloudwatchlogs.GetQueryResultsOutput, error) {
|
2020-04-25 15:48:20 -05:00
|
|
|
const maxAttempts = 8
|
|
|
|
const pollPeriod = 1000 * time.Millisecond
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
startQueryOutput, err := e.executeStartQuery(ctx, logsClient, model, queryContext.TimeRange)
|
2020-04-25 15:48:20 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
requestParams := simplejson.NewFromAny(map[string]interface{}{
|
2021-03-23 10:32:12 -05:00
|
|
|
"region": model.Get("region").MustString(""),
|
2020-04-25 15:48:20 -05:00
|
|
|
"queryId": *startQueryOutput.QueryId,
|
|
|
|
})
|
|
|
|
|
|
|
|
ticker := time.NewTicker(pollPeriod)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
attemptCount := 1
|
|
|
|
for range ticker.C {
|
2020-06-29 07:08:32 -05:00
|
|
|
res, err := e.executeGetQueryResults(ctx, logsClient, requestParams)
|
|
|
|
if err != nil {
|
2020-04-25 15:48:20 -05:00
|
|
|
return nil, err
|
2020-06-29 07:08:32 -05:00
|
|
|
}
|
|
|
|
if isTerminated(*res.Status) {
|
2020-04-25 15:48:20 -05:00
|
|
|
return res, err
|
2020-06-29 07:08:32 -05:00
|
|
|
}
|
|
|
|
if attemptCount >= maxAttempts {
|
2020-04-25 15:48:20 -05:00
|
|
|
return res, fmt.Errorf("fetching of query results exceeded max number of attempts")
|
|
|
|
}
|
|
|
|
|
|
|
|
attemptCount++
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func (e *cloudWatchExecutor) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
2020-04-25 15:48:20 -05:00
|
|
|
/*
|
2021-03-08 00:02:49 -06:00
|
|
|
Unlike many other data sources, with Cloudwatch Logs query requests don't receive the results as the response
|
|
|
|
to the query, but rather an ID is first returned. Following this, a client is expected to send requests along
|
|
|
|
with the ID until the status of the query is complete, receiving (possibly partial) results each time. For
|
|
|
|
queries made via dashboards and Explore, the logic of making these repeated queries is handled on the
|
|
|
|
frontend, but because alerts are executed on the backend the logic needs to be reimplemented here.
|
2020-04-25 15:48:20 -05:00
|
|
|
*/
|
2021-03-23 10:32:12 -05:00
|
|
|
q := req.Queries[0]
|
|
|
|
model, err := simplejson.NewJson(q.JSON)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
_, fromAlert := req.Headers["FromAlert"]
|
|
|
|
isLogAlertQuery := fromAlert && model.Get("queryMode").MustString("") == "Logs"
|
2020-04-25 15:48:20 -05:00
|
|
|
|
|
|
|
if isLogAlertQuery {
|
2021-03-23 10:32:12 -05:00
|
|
|
return e.executeLogAlertQuery(ctx, req)
|
2020-04-25 15:48:20 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
queryType := model.Get("type").MustString("")
|
2017-09-22 04:07:10 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
var result *backend.QueryDataResponse
|
2017-09-09 14:24:39 -05:00
|
|
|
switch queryType {
|
|
|
|
case "metricFindQuery":
|
2021-03-23 10:32:12 -05:00
|
|
|
result, err = e.executeMetricFindQuery(ctx, model, q, req.PluginContext)
|
2017-09-25 04:16:40 -05:00
|
|
|
case "annotationQuery":
|
2021-03-23 10:32:12 -05:00
|
|
|
result, err = e.executeAnnotationQuery(ctx, model, q, req.PluginContext)
|
2020-04-25 15:48:20 -05:00
|
|
|
case "logAction":
|
2021-03-23 10:32:12 -05:00
|
|
|
result, err = e.executeLogActions(ctx, req)
|
2020-10-28 03:36:57 -05:00
|
|
|
case "liveLogAction":
|
2021-03-23 10:32:12 -05:00
|
|
|
result, err = e.executeLiveLogQuery(ctx, req)
|
2017-09-23 22:30:34 -05:00
|
|
|
case "timeSeriesQuery":
|
|
|
|
fallthrough
|
2017-09-22 04:07:10 -05:00
|
|
|
default:
|
2021-03-23 10:32:12 -05:00
|
|
|
result, err = e.executeTimeSeriesQuery(ctx, req)
|
2017-09-09 14:24:39 -05:00
|
|
|
}
|
2017-09-22 04:07:10 -05:00
|
|
|
|
|
|
|
return result, err
|
2017-09-09 14:24:39 -05:00
|
|
|
}
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func (e *cloudWatchExecutor) executeLogAlertQuery(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
|
|
|
resp := backend.NewQueryDataResponse()
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
for _, q := range req.Queries {
|
|
|
|
model, err := simplejson.NewJson(q.JSON)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
model.Set("subtype", "StartQuery")
|
|
|
|
model.Set("queryString", model.Get("expression").MustString(""))
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
region := model.Get("region").MustString(defaultRegion)
|
|
|
|
if region == defaultRegion {
|
|
|
|
dsInfo, err := e.getDSInfo(req.PluginContext)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
model.Set("region", dsInfo.region)
|
|
|
|
}
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
logsClient, err := e.getCWLogsClient(region, req.PluginContext)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
result, err := e.executeStartQuery(ctx, logsClient, model, q.TimeRange)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
model.Set("queryId", *result.QueryId)
|
2020-04-25 15:48:20 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
getQueryResultsOutput, err := e.alertQuery(ctx, logsClient, q, model)
|
2020-05-21 09:18:09 -05:00
|
|
|
if err != nil {
|
2021-03-23 10:32:12 -05:00
|
|
|
return nil, err
|
2020-05-21 09:18:09 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
dataframe, err := logsResultsToDataframes(getQueryResultsOutput)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-05-21 09:18:09 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
var frames []*data.Frame
|
|
|
|
|
|
|
|
statsGroups := model.Get("statsGroups").MustStringArray()
|
|
|
|
if len(statsGroups) > 0 && len(dataframe.Fields) > 0 {
|
|
|
|
frames, err = groupResults(dataframe, statsGroups)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
frames = data.Frames{dataframe}
|
2020-05-21 09:18:09 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
respD := resp.Responses["A"]
|
|
|
|
respD.Frames = frames
|
|
|
|
resp.Responses["A"] = respD
|
2020-05-21 09:18:09 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
return resp, nil
|
2020-04-25 15:48:20 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
func (e *cloudWatchExecutor) getDSInfo(pluginCtx backend.PluginContext) (*datasourceInfo, error) {
|
|
|
|
i, err := e.im.Get(pluginCtx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-10-12 10:58:58 -05:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
instance := i.(datasourceInfo)
|
2020-09-24 11:21:17 -05:00
|
|
|
|
2021-03-23 10:32:12 -05:00
|
|
|
return &instance, nil
|
2020-07-14 01:23:23 -05:00
|
|
|
}
|
|
|
|
|
2020-07-23 11:52:22 -05:00
|
|
|
func isTerminated(queryStatus string) bool {
|
|
|
|
return queryStatus == "Complete" || queryStatus == "Cancelled" || queryStatus == "Failed" || queryStatus == "Timeout"
|
|
|
|
}
|
2020-07-14 01:23:23 -05:00
|
|
|
|
2021-01-07 04:36:13 -06:00
|
|
|
// NewCWClient is a CloudWatch client factory.
|
2020-07-23 11:52:22 -05:00
|
|
|
//
|
|
|
|
// Stubbable by tests.
|
2021-01-07 04:36:13 -06:00
|
|
|
var NewCWClient = func(sess *session.Session) cloudwatchiface.CloudWatchAPI {
|
2020-07-23 11:52:22 -05:00
|
|
|
client := cloudwatch.New(sess)
|
|
|
|
client.Handlers.Send.PushFront(func(r *request.Request) {
|
|
|
|
r.HTTPRequest.Header.Set("User-Agent", fmt.Sprintf("Grafana/%s", setting.BuildVersion))
|
|
|
|
})
|
2020-07-14 01:23:23 -05:00
|
|
|
|
2020-07-23 11:52:22 -05:00
|
|
|
return client
|
|
|
|
}
|
2020-07-14 01:23:23 -05:00
|
|
|
|
2021-01-07 04:36:13 -06:00
|
|
|
// NewCWLogsClient is a CloudWatch logs client factory.
|
2020-07-23 11:52:22 -05:00
|
|
|
//
|
|
|
|
// Stubbable by tests.
|
2021-01-07 04:36:13 -06:00
|
|
|
var NewCWLogsClient = func(sess *session.Session) cloudwatchlogsiface.CloudWatchLogsAPI {
|
2020-07-23 11:52:22 -05:00
|
|
|
client := cloudwatchlogs.New(sess)
|
2020-07-14 01:23:23 -05:00
|
|
|
client.Handlers.Send.PushFront(func(r *request.Request) {
|
|
|
|
r.HTTPRequest.Header.Set("User-Agent", fmt.Sprintf("Grafana/%s", setting.BuildVersion))
|
|
|
|
})
|
|
|
|
|
2020-07-23 11:52:22 -05:00
|
|
|
return client
|
2020-07-14 01:23:23 -05:00
|
|
|
}
|
|
|
|
|
2020-07-23 11:52:22 -05:00
|
|
|
// EC2 client factory.
|
|
|
|
//
|
|
|
|
// Stubbable by tests.
|
|
|
|
var newEC2Client = func(provider client.ConfigProvider) ec2iface.EC2API {
|
|
|
|
return ec2.New(provider)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RGTA client factory.
|
|
|
|
//
|
|
|
|
// Stubbable by tests.
|
|
|
|
var newRGTAClient = func(provider client.ConfigProvider) resourcegroupstaggingapiiface.ResourceGroupsTaggingAPIAPI {
|
|
|
|
return resourcegroupstaggingapi.New(provider)
|
2020-04-25 15:48:20 -05:00
|
|
|
}
|