Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

fix: Added not found errors handlers in athena resources #1021

Merged
merged 3 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions resources/services/athena/data_catalogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func fetchAthenaDataCatalogs(ctx context.Context, meta schema.ClientMeta, parent
func(summary types.DataCatalogSummary) {
errs.Go(func() error {
defer sem.Release(1)
return fetchDataCatalog(ctx, res, svc, c.Region, summary)
return fetchDataCatalog(ctx, res, c, summary)
})
}(d)
}
Expand Down Expand Up @@ -335,11 +335,12 @@ func fetchAthenaDataCatalogDatabaseTablePartitionKeys(ctx context.Context, meta
// User Defined Helpers
// ====================================================================================================================

func fetchDataCatalog(ctx context.Context, res chan<- interface{}, svc client.AthenaClient, region string, catalogSummary types.DataCatalogSummary) error {
func fetchDataCatalog(ctx context.Context, res chan<- interface{}, c *client.Client, catalogSummary types.DataCatalogSummary) error {
svc := c.Services().Athena
dc, err := svc.GetDataCatalog(ctx, &athena.GetDataCatalogInput{
Name: catalogSummary.CatalogName,
}, func(options *athena.Options) {
options.Region = region
options.Region = c.Region
})
if err != nil {
// retrieving of default data catalog (AwsDataCatalog) returns "not found error" but it exists and its
Expand All @@ -348,6 +349,9 @@ func fetchDataCatalog(ctx context.Context, res chan<- interface{}, svc client.At
res <- types.DataCatalog{Name: catalogSummary.CatalogName, Type: catalogSummary.Type}
return nil
}
if c.IsNotFoundError(err) {
return nil
}
return diag.WrapError(err)
}
res <- *dc.DataCatalog
Expand Down
31 changes: 27 additions & 4 deletions resources/services/athena/work_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package athena

import (
"context"
"errors"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/athena"
"github.com/aws/aws-sdk-go-v2/service/athena/types"
"github.com/aws/smithy-go"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
Expand Down Expand Up @@ -428,7 +431,7 @@ func fetchAthenaWorkGroups(ctx context.Context, meta schema.ClientMeta, parent *
func(summary types.WorkGroupSummary) {
errs.Go(func() error {
defer sem.Release(1)
return fetchWorkGroup(ctx, res, svc, c.Region, summary)
return fetchWorkGroup(ctx, res, c, summary)
})
}(d)
}
Expand Down Expand Up @@ -491,6 +494,9 @@ func fetchAthenaWorkGroupPreparedStatements(ctx context.Context, meta schema.Cli
options.Region = c.Region
})
if err != nil {
if c.IsNotFoundError(err) {
continue
}
return diag.WrapError(err)
}
res <- *dc.PreparedStatement
Expand All @@ -517,12 +523,14 @@ func fetchAthenaWorkGroupQueryExecutions(ctx context.Context, meta schema.Client
}
for _, d := range response.QueryExecutionIds {
dc, err := svc.GetQueryExecution(ctx, &athena.GetQueryExecutionInput{

QueryExecutionId: aws.String(d),
}, func(options *athena.Options) {
options.Region = c.Region
})
if err != nil {
if c.IsNotFoundError(err) || isQueryExecutionNotFound(err) {
continue
}
return diag.WrapError(err)
}
res <- *dc.QueryExecution
Expand Down Expand Up @@ -554,6 +562,9 @@ func fetchAthenaWorkGroupNamedQueries(ctx context.Context, meta schema.ClientMet
options.Region = c.Region
})
if err != nil {
if c.IsNotFoundError(err) {
continue
}
return diag.WrapError(err)
}
res <- *dc.NamedQuery
Expand All @@ -571,13 +582,17 @@ func fetchAthenaWorkGroupNamedQueries(ctx context.Context, meta schema.ClientMet
// User Defined Helpers
// ====================================================================================================================

func fetchWorkGroup(ctx context.Context, res chan<- interface{}, svc client.AthenaClient, region string, groupSummary types.WorkGroupSummary) error {
func fetchWorkGroup(ctx context.Context, res chan<- interface{}, c *client.Client, groupSummary types.WorkGroupSummary) error {
svc := c.Services().Athena
dc, err := svc.GetWorkGroup(ctx, &athena.GetWorkGroupInput{
WorkGroup: groupSummary.Name,
}, func(options *athena.Options) {
options.Region = region
options.Region = c.Region
})
if err != nil {
if c.IsNotFoundError(err) {
return nil
}
return diag.WrapError(err)
}
res <- *dc.WorkGroup
Expand All @@ -587,3 +602,11 @@ func fetchWorkGroup(ctx context.Context, res chan<- interface{}, svc client.Athe
func createWorkGroupArn(cl *client.Client, groupName string) string {
return cl.ARN(client.Athena, "workgroup", groupName)
}

func isQueryExecutionNotFound(err error) bool {
var ae smithy.APIError
if !errors.As(err, &ae) {
return false
}
return ae.ErrorCode() == "InvalidRequestException" && strings.Contains(ae.ErrorMessage(), "was not found")
}