CloudWatch: small logs refactors (#44677)
This commit is contained in:
@@ -47,12 +47,17 @@ type datasourceInfo struct {
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
const cloudWatchTSFormat = "2006-01-02 15:04:05.000"
|
||||
const defaultRegion = "default"
|
||||
const (
|
||||
cloudWatchTSFormat = "2006-01-02 15:04:05.000"
|
||||
defaultRegion = "default"
|
||||
|
||||
// Constants also defined in datasource/cloudwatch/datasource.ts
|
||||
const logIdentifierInternal = "__log__grafana_internal__"
|
||||
const logStreamIdentifierInternal = "__logstream__grafana_internal__"
|
||||
// Constants also defined in datasource/cloudwatch/datasource.ts
|
||||
logIdentifierInternal = "__log__grafana_internal__"
|
||||
logStreamIdentifierInternal = "__logstream__grafana_internal__"
|
||||
|
||||
alertMaxAttempts = 8
|
||||
alertPollPeriod = 1000 * time.Millisecond
|
||||
)
|
||||
|
||||
var plog = log.New("tsdb.cloudwatch")
|
||||
var aliasFormat = regexp.MustCompile(`\{\{\s*(.+?)\s*\}\}`)
|
||||
@@ -222,9 +227,6 @@ func (e *cloudWatchExecutor) getRGTAClient(region string, pluginCtx backend.Plug
|
||||
|
||||
func (e *cloudWatchExecutor) alertQuery(ctx context.Context, logsClient cloudwatchlogsiface.CloudWatchLogsAPI,
|
||||
queryContext backend.DataQuery, model *simplejson.Json) (*cloudwatchlogs.GetQueryResultsOutput, error) {
|
||||
const maxAttempts = 8
|
||||
const pollPeriod = 1000 * time.Millisecond
|
||||
|
||||
startQueryOutput, err := e.executeStartQuery(ctx, logsClient, model, queryContext.TimeRange)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -235,7 +237,7 @@ func (e *cloudWatchExecutor) alertQuery(ctx context.Context, logsClient cloudwat
|
||||
"queryId": *startQueryOutput.QueryId,
|
||||
})
|
||||
|
||||
ticker := time.NewTicker(pollPeriod)
|
||||
ticker := time.NewTicker(alertPollPeriod)
|
||||
defer ticker.Stop()
|
||||
|
||||
attemptCount := 1
|
||||
@@ -247,7 +249,7 @@ func (e *cloudWatchExecutor) alertQuery(ctx context.Context, logsClient cloudwat
|
||||
if isTerminated(*res.Status) {
|
||||
return res, err
|
||||
}
|
||||
if attemptCount >= maxAttempts {
|
||||
if attemptCount >= alertMaxAttempts {
|
||||
return res, fmt.Errorf("fetching of query results exceeded max number of attempts")
|
||||
}
|
||||
|
||||
@@ -322,13 +324,6 @@ func (e *cloudWatchExecutor) executeLogAlertQuery(ctx context.Context, req *back
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result, err := e.executeStartQuery(ctx, logsClient, model, q.TimeRange)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
model.Set("queryId", *result.QueryId)
|
||||
|
||||
getQueryResultsOutput, err := e.alertQuery(ctx, logsClient, q, model)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -18,7 +18,10 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
var LimitExceededException = "LimitExceededException"
|
||||
const (
|
||||
LimitExceededException = "LimitExceededException"
|
||||
defaultLimit = 10
|
||||
)
|
||||
|
||||
type AWSError struct {
|
||||
Code string
|
||||
@@ -126,7 +129,7 @@ func (e *cloudWatchExecutor) executeLogAction(ctx context.Context, model *simple
|
||||
func (e *cloudWatchExecutor) handleGetLogEvents(ctx context.Context, logsClient cloudwatchlogsiface.CloudWatchLogsAPI,
|
||||
parameters *simplejson.Json) (*data.Frame, error) {
|
||||
queryRequest := &cloudwatchlogs.GetLogEventsInput{
|
||||
Limit: aws.Int64(parameters.Get("limit").MustInt64(10)),
|
||||
Limit: aws.Int64(parameters.Get("limit").MustInt64(defaultLimit)),
|
||||
StartFromHead: aws.Bool(parameters.Get("startFromHead").MustBool(false)),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user