Skip to content

Commit

Permalink
feat: make AWS SDK log retries at DEBUG or TRACE levels
Browse files Browse the repository at this point in the history
  • Loading branch information
pdecat committed Jan 23, 2024
1 parent 732ab6d commit 33f57ab
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions aws/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ import (
"github.com/aws/aws-sdk-go-v2/service/wafv2"
"github.com/aws/aws-sdk-go-v2/service/wellarchitected"
"github.com/aws/aws-sdk-go-v2/service/workspaces"
"github.com/aws/smithy-go/logging"
"github.com/hashicorp/go-hclog"
"github.com/rs/dnscache"
"golang.org/x/sync/semaphore"

"github.com/turbot/go-kit/helpers"
"github.com/turbot/steampipe-plugin-sdk/v5/memoize"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"golang.org/x/sync/semaphore"

amplifyEndpoint "github.com/aws/aws-sdk-go/service/amplify"
apigatewayv2Endpoint "github.com/aws/aws-sdk-go/service/apigatewayv2"
Expand Down Expand Up @@ -1949,6 +1950,12 @@ func getBaseClientForAccountUncached(ctx context.Context, d *plugin.QueryData, h
configOptions = append(configOptions, config.WithCredentialsProvider(provider))
}

if plugin.Logger(ctx).GetLevel() <= hclog.Debug {
logger := plugin.Logger(ctx)
configOptions = append(configOptions, config.WithLogger(NewHCLoggerToSmithyLoggerWrapper(&logger)))
configOptions = append(configOptions, config.WithClientLogMode(aws.LogRetries))
}

plugin.Logger(ctx).Info("getBaseClientForAccountUncached", "connection_name", d.Connection.Name, "status", "loading_config")

// NOTE: EC2 metadata service IMDS throttling and retries
Expand Down Expand Up @@ -2017,6 +2024,19 @@ func getBaseClientForAccountUncached(ctx context.Context, d *plugin.QueryData, h

}

// HCLoggerToSmithyLoggerWrapper wraps an hclog Logger in order to pass it as an AWS SDK smithy Logger
type HCLoggerToSmithyLoggerWrapper struct {
hclogger *hclog.Logger
}

func (logger *HCLoggerToSmithyLoggerWrapper) Logf(classification logging.Classification, format string, v ...interface{}) {
(*logger.hclogger).Debug(fmt.Sprintf(format, v...))
}

func NewHCLoggerToSmithyLoggerWrapper(l *hclog.Logger) *HCLoggerToSmithyLoggerWrapper {
return &HCLoggerToSmithyLoggerWrapper{l}
}

// ExponentialJitterBackoff provides backoff delays with jitter based on the
// number of attempts.
type ExponentialJitterBackoff struct {
Expand Down

0 comments on commit 33f57ab

Please sign in to comment.