@ -29,14 +31,14 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
statistic=*model.Statistic
}
varperiodint64
varperiodint32
ifmodel.Period!=nil&&*model.Period!=""{
p,err:=strconv.ParseInt(*model.Period,10,64)
p,err:=strconv.ParseInt(*model.Period,10,32)
iferr!=nil{
returnnil,backend.DownstreamError(fmt.Errorf("query period must be an int"))
}
period=p
period=int32(p)
}
prefixMatching:=false
@ -69,11 +71,11 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
ifprefixMatching{
params:=&cloudwatch.DescribeAlarmsInput{
MaxRecords:aws.Int64(100),
MaxRecords:aws.Int32(100),
ActionPrefix:actionPrefix,
AlarmNamePrefix:alarmNamePrefix,
}
resp,err:=cli.DescribeAlarms(params)
resp,err:=cli.DescribeAlarms(ctx,params)
iferr!=nil{
result.Responses[query.RefID]=backend.ErrorResponseWithErrorSource(backend.DownstreamError(fmt.Errorf("%v: %w","failed to call cloudwatch:DescribeAlarms",err)))
returnresult,nil
@ -84,10 +86,10 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
@ -97,10 +99,10 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
Namespace:aws.String(model.Namespace),
MetricName:aws.String(metricName),
Dimensions:qd,
Statistic:aws.String(statistic),
Period:aws.Int64(period),
Statistic:cloudwatchtypes.Statistic(statistic),
Period:aws.Int32(period),
}
resp,err:=cli.DescribeAlarmsForMetric(params)
resp,err:=cli.DescribeAlarmsForMetric(ctx,params)
iferr!=nil{
result.Responses[query.RefID]=backend.ErrorResponseWithErrorSource(backend.DownstreamError(fmt.Errorf("%v: %w","failed to call cloudwatch:DescribeAlarmsForMetric",err)))
returnresult,nil
@ -116,9 +118,9 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
AlarmName:alarmName,
StartDate:aws.Time(query.TimeRange.From),
EndDate:aws.Time(query.TimeRange.To),
MaxRecords:aws.Int64(100),
MaxRecords:aws.Int32(100),
}
resp,err:=cli.DescribeAlarmHistory(params)
resp,err:=cli.DescribeAlarmHistory(ctx,params)
iferr!=nil{
result.Responses[query.RefID]=backend.ErrorResponseWithErrorSource(backend.DownstreamError(fmt.Errorf("%v: %w","failed to call cloudwatch:DescribeAlarmHistory",err)))
returnresult,nil
@ -127,7 +129,7 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
QueryString:aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
QueryString:aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
QueryString:aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
QueryString:aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
QueryString:aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
QueryString:aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
QueryString:aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
return*input.QueryString=="fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|query string for A"
return*input.QueryString=="fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|query string for B"
expectedLogFieldFromFirstCall:=data.NewField("@log",nil,[]*string{utils.Pointer("A result")})// verifies the response from GetQueryResultsWithContext matches the input RefId A
expectedLogFieldFromFirstCall:=data.NewField("@log",nil,[]*string{utils.Pointer("A result")})// verifies the response from GetQueryResults matches the input RefId A
expectedLogFieldFromSecondCall:=data.NewField("@log",nil,[]*string{utils.Pointer("B result")})// verifies the response from GetQueryResultsWithContext matches the input RefId B
expectedLogFieldFromSecondCall:=data.NewField("@log",nil,[]*string{utils.Pointer("B result")})// verifies the response from GetQueryResults matches the input RefId B
{name:"when timezoneUTCOffset is provided",timezoneUTCOffset:"+1234",expectedLabelOptions:&cloudwatch.LabelOptions{Timezone:aws.String("+1234")}},
{name:"when timezoneUTCOffset is provided",timezoneUTCOffset:"+1234",expectedLabelOptions:&cloudwatchtypes.LabelOptions{Timezone:aws.String("+1234")}},
{name:"when timezoneUTCOffset is not provided",timezoneUTCOffset:"",expectedLabelOptions:nil},
@ -54,20 +55,42 @@ type MetricsClientProvider interface {
// APIs - instead of using the API defined in the services within the aws-sdk-go directly, specify a subset of the API with methods that are actually used in a service or a client
t.Run("returns 500 if GetLogGroupFields method fails",func(t*testing.T){
mockLogsService:=mocks.LogsService{}
mockLogsService.On("GetLogGroupFieldsWithContext",mock.Anything).Return([]resources.ResourceResponse[resources.LogGroupField]{},fmt.Errorf("error from api"))
mockLogsService.On("GetLogGroupFields",mock.Anything).Return([]resources.ResourceResponse[resources.LogGroupField]{},fmt.Errorf("error from api"))
t.Run("Queries with the same region should call GetSessionWithAuthSettings with that region 1 time and call GetMetricDataWithContext 1 time",func(t*testing.T){