diff --git a/pkg/cloud/cloud.go b/pkg/cloud/cloud.go index a0615593b4..48607e5109 100644 --- a/pkg/cloud/cloud.go +++ b/pkg/cloud/cloud.go @@ -327,7 +327,6 @@ func newEC2Cloud(region string, awsSdkDebugLog bool, userAgentExtra string, batc svc := ec2.NewFromConfig(cfg, func(o *ec2.Options) { o.APIOptions = append(o.APIOptions, RecordRequestsMiddleware(), - RecordThrottledRequestsMiddleware(), ) o.RetryMaxAttempts = retryMaxAttempt // Retry EC2 API calls at sdk level until request contexts are cancelled diff --git a/pkg/cloud/handlers.go b/pkg/cloud/handlers.go index dc5b0648cd..dd45ddfcb5 100644 --- a/pkg/cloud/handlers.go +++ b/pkg/cloud/handlers.go @@ -37,35 +37,26 @@ func RecordRequestsMiddleware() func(*middleware.Stack) error { start := time.Now() output, metadata, err = next.HandleFinalize(ctx, input) labels := createLabels(ctx) - if err != nil { - metrics.Recorder().IncreaseCount("cloudprovider_aws_api_request_errors", labels) - } else { - duration := time.Since(start).Seconds() - metrics.Recorder().ObserveHistogram("cloudprovider_aws_api_request_duration_seconds", duration, labels, nil) - } - return output, metadata, err - }), middleware.Before) - } -} - -// RecordThrottledRequestsHandler is added to the AfterRetry chain; called after any error -func RecordThrottledRequestsMiddleware() func(*middleware.Stack) error { - return func(stack *middleware.Stack) error { - return stack.Finalize.Add(middleware.FinalizeMiddlewareFunc("RecordThrottledRequestsMiddleware", func(ctx context.Context, input middleware.FinalizeInput, next middleware.FinalizeHandler) (output middleware.FinalizeOutput, metadata middleware.Metadata, err error) { - output, metadata, err = next.HandleFinalize(ctx, input) if err != nil { var apiErr smithy.APIError - if errors.As(err, &apiErr) && apiErr.ErrorCode() == requestLimitExceededErrorCode { - operationName := awsmiddleware.GetOperationName(ctx) - labels := map[string]string{ - "operation_name": operationName, + if errors.As(err, &apiErr) { + if apiErr.ErrorCode() == requestLimitExceededErrorCode { + operationName := awsmiddleware.GetOperationName(ctx) + labels = map[string]string{ + "operation_name": operationName, + } + metrics.Recorder().IncreaseCount("cloudprovider_aws_api_throttled_requests_total", labels) + klog.InfoS("Got RequestLimitExceeded error on AWS request", "request", operationName) + } else { + metrics.Recorder().IncreaseCount("cloudprovider_aws_api_request_errors", labels) } - metrics.Recorder().IncreaseCount("cloudprovider_aws_api_throttled_requests_total", labels) - klog.InfoS("Got RequestLimitExceeded error on AWS request", "request", operationName) } + } else { + duration := time.Since(start).Seconds() + metrics.Recorder().ObserveHistogram("cloudprovider_aws_api_request_duration_seconds", duration, labels, nil) } return output, metadata, err - }), middleware.Before) + }), middleware.After) } }