-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(sfn): handle pagination and ignore errors for expired executions history #1934
fix(sfn): handle pagination and ignore errors for expired executions history #1934
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdecat Thanks for opening this PR! Can you please see my comments/questions?
var apiErr smithy.APIError | ||
if errors.As(err, &apiErr) { | ||
switch apiErr.(type) { | ||
case *types.ExecutionDoesNotExist: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a known error code for this error type? If so, could we add it to an IgnoreConfig
in the ListConfig
, similar to
steampipe-plugin-aws/aws/table_aws_ec2_instance.go
Lines 29 to 31 in d7dac4d
IgnoreConfig: &plugin.IgnoreConfig{ | |
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"InvalidInstanceID.NotFound", "InvalidInstanceID.Unavailable", "InvalidInstanceID.Malformed"}), | |
}, |
GetConfig
, but ListConfig
supports adding the same thing)?
The ShouldIgnoreErrorFunc
in the config has a similar effect of returning nil
if we encounter from the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess ExecutionDoesNotExist
should be known: https://github.com/aws/aws-sdk-go-v2/blob/v1.21.2/service/sfn/types/errors.go#L166
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried this change:
diff --git a/aws/table_aws_sfn_state_machine_execution_history.go b/aws/table_aws_sfn_state_machine_execution_history.go
index c6ae08ce..9384b73a 100644
--- a/aws/table_aws_sfn_state_machine_execution_history.go
+++ b/aws/table_aws_sfn_state_machine_execution_history.go
@@ -2,7 +2,6 @@ package aws
import (
"context"
- "errors"
"strconv"
"strings"
"sync"
@@ -10,7 +9,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sfn"
"github.com/aws/aws-sdk-go-v2/service/sfn/types"
- "github.com/aws/smithy-go"
sfnv1 "github.com/aws/aws-sdk-go/service/sfn"
@@ -27,6 +25,9 @@ func tableAwsStepFunctionsStateMachineExecutionHistory(_ context.Context) *plugi
Hydrate: listStepFunctionsStateMachineExecutionHistories,
Tags: map[string]string{"service": "states", "action": "ListExecutions"},
ParentHydrate: listStepFunctionsStateMachines,
+ IgnoreConfig: &plugin.IgnoreConfig{
+ ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ExecutionDoesNotExist"}),
+ },
},
GetMatrixItemFunc: SupportedRegionMatrix(sfnv1.EndpointsID),
Columns: awsRegionalColumns([]*plugin.Column{
@@ -373,15 +374,6 @@ func getRowDataForExecutionHistory(ctx context.Context, d *plugin.QueryData, arn
plugin.Logger(ctx).Trace("aws_sfn_state_machine_execution_history.getRowDataForExecutionHistory", "api_call GetExecutionHistory", arn)
output, err := paginator.NextPage(ctx)
if err != nil {
- var apiErr smithy.APIError
- if errors.As(err, &apiErr) {
- switch apiErr.(type) {
- case *types.ExecutionDoesNotExist:
- // Ignore expired executions for which history is no longer available
- plugin.Logger(ctx).Trace("aws_sfn_state_machine_execution_history.getRowDataForExecutionHistory", "api_error ignore_expired", err)
- return nil, nil
- }
- }
plugin.Logger(ctx).Error("aws_sfn_state_machine_execution_history.getRowDataForExecutionHistory", "api_error", err)
return nil, err
}
But it does not seem to work:
> with constants (r, s_arn, e_arn) as (
values (
'eu-west-3',
'arn:aws:states:eu-west-3:012345678901:stateMachine:mysfn',
'arn:aws:states:eu-west-3:012345678901:execution:mysfn:%'
)
)
select id,
execution_arn,
execution_failed_event_details
from aws_sfn_state_machine_execution_history,
constants
where region = r
and execution_arn in (
select execution_arn
from aws_sfn_state_machine_execution,
constants
where region = r
and state_machine_arn = s_arn
and execution_arn like e_arn
)
and execution_failed_event_details is null;
Error: operation error SFN: GetExecutionHistory, https response error StatusCode: 400, RequestID: 0ce49d57-9f15-4636-8398-8ddaf01af24b, ExecutionDoesNotExist: Execution Does Not Exist: 'arn:aws:states:eu-west-3:012345678901:execution:mysfn:a4fdeb5a-0f8f-4bee-b36b-2ae036665817' (SQLSTATE HV000)
+----+---------------+--------------------------------+
| id | execution_arn | execution_failed_event_details |
+----+---------------+--------------------------------+
+----+---------------+--------------------------------+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pdecat for testing (sorry for the long response time!), I think this is due to a bug where IgnoreConfig
doesn't work when a ParentHydrate
is used (turbot/steampipe-plugin-sdk#544), so can you please add a comment mentioning why we need to handle errors here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
} | ||
|
||
var items []historyInfo | ||
|
||
listHistory, err := svc.GetExecutionHistory(ctx, params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the AWS SDK offer any pagination with svc.GetExecutionHistory
? Or was this table never iterating through pages before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This table did not implement the required pagination handling before: https://docs.aws.amazon.com/sdk-for-go/api/service/sfn/#SFN.GetExecutionHistory
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Not stale |
Signed-off-by: Patrick Decat <pdecat@gmail.com>
675386e
to
4b0d5cb
Compare
This PR updates the
aws_sfn_state_machine_execution_history
table to implement pagination and ignore errors for expired executions history, which are only preserved for a maximum of 90 days.Without this latter change, one would get errors like this one:
Integration test logs
Logs
Example query results
Results