Skip to content
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

Ec2 imds client logger fix #1891

Merged
merged 3 commits into from Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changelog/a3c2a480e3c9401a93ab4bafab06262c.json
@@ -0,0 +1,8 @@
{
"id": "a3c2a480-e3c9-401a-93ab-4bafab06262c",
"type": "bugfix",
"description": "added logger and request response logging middleware to the imds client, fixed respective tests to include the correct middleware in the tested stack",
"modules": [
"feature/ec2/imds"
]
}
6 changes: 4 additions & 2 deletions feature/ec2/imds/api_client.go
Expand Up @@ -106,8 +106,10 @@ func New(options Options, optFns ...func(*Options)) *Client {
// or adding custom middleware behavior.
func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client {
opts := Options{
APIOptions: append([]func(*middleware.Stack) error{}, cfg.APIOptions...),
HTTPClient: cfg.HTTPClient,
APIOptions: append([]func(*middleware.Stack) error{}, cfg.APIOptions...),
HTTPClient: cfg.HTTPClient,
ClientLogMode: cfg.ClientLogMode,
Logger: cfg.Logger,
}

if cfg.Retryer != nil {
Expand Down
19 changes: 19 additions & 0 deletions feature/ec2/imds/request_middleware.go
Expand Up @@ -86,13 +86,32 @@ func addRequestMiddleware(stack *middleware.Stack,
return err
}

err = stack.Deserialize.Add(&smithyhttp.RequestResponseLogger{
LogRequest: options.ClientLogMode.IsRequest(),
LogRequestWithBody: options.ClientLogMode.IsRequestWithBody(),
LogResponse: options.ClientLogMode.IsResponse(),
LogResponseWithBody: options.ClientLogMode.IsResponseWithBody(),
}, middleware.After)
if err != nil {
return err
}

err = addSetLoggerMiddleware(stack, options)
if err != nil {
return err
}

// Retry support
return retry.AddRetryMiddlewares(stack, retry.AddRetryMiddlewaresOptions{
Retryer: options.Retryer,
LogRetryAttempts: options.ClientLogMode.IsRetries(),
})
}

func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error {
return middleware.AddSetLoggerMiddleware(stack, o.Logger)
}

type serializeRequest struct {
GetPath func(interface{}) (string, error)
Method string
Expand Down
4 changes: 4 additions & 0 deletions feature/ec2/imds/request_middleware_test.go
Expand Up @@ -42,6 +42,7 @@ func TestAddRequestMiddleware(t *testing.T) {
},
ExpectInitialize: []string{
(*operationTimeout)(nil).ID(),
"SetLogger",
},
ExpectSerialize: []string{
"ResolveEndpoint",
Expand All @@ -58,6 +59,7 @@ func TestAddRequestMiddleware(t *testing.T) {
ExpectDeserialize: []string{
"APITokenProvider",
"OperationDeserializer",
"RequestResponseLogger",
},
},

Expand All @@ -74,6 +76,7 @@ func TestAddRequestMiddleware(t *testing.T) {
},
ExpectInitialize: []string{
(*operationTimeout)(nil).ID(),
"SetLogger",
},
ExpectSerialize: []string{
"ResolveEndpoint",
Expand All @@ -88,6 +91,7 @@ func TestAddRequestMiddleware(t *testing.T) {
},
ExpectDeserialize: []string{
"OperationDeserializer",
"RequestResponseLogger",
},
},
}
Expand Down