-
Notifications
You must be signed in to change notification settings - Fork 618
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
Migrate ECS client to aws-sdk-go-v2 #4447
base: dev
Are you sure you want to change the base?
Conversation
6b18859
to
a1a9480
Compare
1c2d4b8
to
7d2a689
Compare
7d2a689
to
0d3c3a7
Compare
84b24b0
to
874dc29
Compare
874dc29
to
447b0eb
Compare
@@ -64,12 +53,20 @@ func Uint16SliceToStringSlice(slice []uint16) []string { | |||
return stringSlice | |||
} | |||
|
|||
// Int64PtrToIntPtr converts a *int64 to *int. | |||
func Int64PtrToIntPtr(int64ptr *int64) *int { | |||
// Int32PtrToIntPtr converts a *int64 to *int. |
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.
// Int32PtrToIntPtr converts a *int32 to *int.
ecs-agent/utils/utils_test.go
Outdated
@@ -83,36 +83,28 @@ func TestUint16SliceToStringSlice(t *testing.T) { | |||
stringSlice := Uint16SliceToStringSlice(tc.param) | |||
assert.Equal(t, tc.expected, len(stringSlice), tc.name) | |||
|
|||
stringPtrSlice := Uint16SliceToStringPtrSlice(tc.param) |
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.
Can we remove this unit test entirely, since the function Uint16SliceToStringPtrSlice
is removed? And add a new unit test for the new Int64PtrToInt32Ptr
method?
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.
sure, will add it
"fmt" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/ecs/types" | ||
"github.com/aws/aws-sdk-go/aws/awserr" |
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.
we need to move to using this awserr
stuff from aws-sdk-v2 too?
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.
yes, v1 error handling will be removed after all clients have been migrated to aws-sdk-go-v2.
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 see, thanks. Can we add a comment to both the modified methods below about this? It isnt immediately clear why we do error handling both v1 and v2 way right now.
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.
sure, will add
return client | ||
} | ||
|
||
// oneDayRetrier is a retrier for the AWS SDK that retries up to one day. | ||
// Each retry will have an exponential backoff from 30ms to 5 minutes. Once the | ||
// backoff has reached 5 minutes, it will not increase further. | ||
// Conforms to the request.Retryer interface https://github.com/aws/aws-sdk-go/blob/v1.0.0/aws/request/retryer.go#L13 | ||
// Confirms to the aws.Retryer interface https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws#Retryer |
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.
nit: I think "Conforms" should be the correct word choice here
} | ||
|
||
return &tasknetworkconfig.TaskNetworkConfig{ | ||
NetworkNamespaces: netNSs, | ||
NetworkMode: mode, | ||
NetworkMode: types.NetworkMode(mode), |
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.
Isn't mode
already type types.NetworkMode
here? Type conversion seems unnecessary here, let's remove it.
@@ -481,7 +481,7 @@ func (AttachmentStateChange) GetEventType() statechange.EventType { | |||
return statechange.AttachmentEvent | |||
} | |||
|
|||
func buildManagedAgentStateChangePayload(change ManagedAgentStateChange) *ecsmodel.ManagedAgentStateChange { | |||
func buildManagedAgentStateChangePayload(change ManagedAgentStateChange) *types.ManagedAgentStateChange { |
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 any specific reason why we don't just return type types.ManagedAgentStateChange
here? Returning pointer type *types.ManagedAgentStateChange
here seems unnecessary to me (i.e., we just end up dereferencing on L427 anyway), but I may be missing something. It seems like in most other places in this pull request we replace *ecsmodel.<INSERT TYPE HERE>
with types.<INSERT TYPE HERE>
as opposed to *types.<INSERT TYPE HERE>
.
ContainerName: aws.String(change.Container.Name), | ||
Status: aws.String(change.Status.String()), | ||
Reason: aws.String(change.Reason), | ||
} | ||
} | ||
|
||
func buildContainerStateChangePayload(change ContainerStateChange) (*ecsmodel.ContainerStateChange, error) { | ||
func buildContainerStateChangePayload(change ContainerStateChange) (*types.ContainerStateChange, error) { |
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.
Same comment as this previous comment applies here too.
res: 400, | ||
}, | ||
{ | ||
name: "TestGetRequestFailureStatusCodeSuccess SDKv2", |
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.
Test case names on L152 and L165 should be swapped (or alternatively, L154-L162 and L166-L167 should be swapped).
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/smithy-go" | ||
"github.com/cihub/seelog" | ||
"github.com/pkg/errors" |
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 import block should go below with other external imports. import order -
- standard imports, 2. ecs agent imports, 3. external imports
|
||
logger.Error(fmt.Sprintf( | ||
"got a %T exception that does not implement ResponseError. This should not happen, return statusCode 500 for whatever errorCode. Original err: %v.", | ||
err, err)) |
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.
logging the err twice in the same log statement doesn't help much. I would suggest removing the first one and just logging the error under "Original err:"
logger.Error(fmt.Sprintf("Got an exception that does not implement ResponseError. This should not happen, return statusCode 500 for whatever errorCode. Original err: %v.",err))
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.
also, can you update all logger.Error statements in this file to start with a capitalized letter?
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" | ||
"github.com/aws/aws-sdk-go-v2/service/ecs" | ||
ecstypes "github.com/aws/aws-sdk-go-v2/service/ecs/types" |
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.
these sdk imports should go along with the other external import block below.
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.
applicable to multiple files throughout this PR, please take a look
} | ||
|
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.
please add a comment here that this is the aws-sdk-go-v2 error handling and the above error handling (L407-422) will be removed once we complete our migration.
@@ -59,6 +61,10 @@ type TaskProtectionRequest struct { | |||
ExpiresInMinutes *int64 | |||
} | |||
|
|||
type CanceledError interface { |
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.
please add a comment explaining what this is useful for, and a link to https://pkg.go.dev/github.com/aws/smithy-go#CanceledError.CanceledError
Summary
Migrate ECS client to
aws-sdk-go-v2
.#4406 added our bespoke codegen'd
aws-sdk-go-v2
ECS client. This PR integrates the v2 ECS client with Agent and removes all uses of our v1 ECS client.Implementation details
In
go.mod
for theagent
andecs-agent
modules,github.com/aws/aws-sdk-go-v2/service/ecs
Update ECS client construction per the docs.
Replace all uses of our v1 ECS client with the v2 ECS client.
aws/aws-sdk-go/service/ecs
is now split betweenaws/aws-sdk-go-v2/service/ecs
andaws/aws-sdk-go-v2/service/ecs/types
.ContainerStateChange.NetworkBindings
changed from[]*NetworkBinding
to[]NetworkBinding
). See the docs for more info.int64
types are nowint32
(e.g.NetworkBinding.ContainerPort
andNetworkBinding.HostPort
changed from*int64
to*int32
).string
constants now have their own enum types aliased tostring
(e.g. theAgentUpdateStatus*
constants changed fromstring
to typeAgentUpdateStatus
.ErrCode*Exception
string constants have been replaced with Exception types (e.g.ErrCodeAccessDeniedException
("AccessDeniedException") now corresponds to theAccessDeniedException
type).Update error handling to handle SDKv1 and SDKv2 errors. v1 error handling can be removed after all clients have been migrated to
aws-sdk-go-v2
. See the docs for more info on error handling in v2.aws.Error
is analogous tosmithy.APIError
.string
error codes now have modeled error types (compare this v1 example with this v2 example).aws.RequestFailure
, which includes the request ID, is analogous tohttp.ResponseError
(see the docs for more info).Rewrite the
oneDayRetrier
to be compatible withaws-sdk-go-v2
per the docs.Testing
GitHub checks pass.
New tests cover the changes: no
Description for the changelog
Migrate ECS client to
aws-sdk-go-v2
.Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.