Skip to content

Conversation

@sivchari
Copy link
Member

What this PR does / why we need it:

Last patch. I support to wait to update lambda function.
If lambda function state is pending, UpdateFunctionCode is failed. So I check the lambda satate.

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

@sivchari sivchari force-pushed the support-wait-function-update branch 2 times, most recently from c9502f9 to 4380779 Compare August 24, 2023 12:50
"github.com/aws/aws-sdk-go-v2/service/lambda/types"
"go.uber.org/zap"

helper "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use hashicorp retry but pipecd package 👀
ref: https://github.com/pipe-cd/pipecd/blob/master/pkg/backoff/backoff.go

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use retry package to get lambda function state.

@sivchari sivchari force-pushed the support-wait-function-update branch 3 times, most recently from a82e690 to f20ea30 Compare August 25, 2023 09:23
@codecov
Copy link

codecov bot commented Aug 25, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.03% ⚠️

Comparison is base (9f75446) 29.91% compared to head (e3ed289) 29.88%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4565      +/-   ##
==========================================
- Coverage   29.91%   29.88%   -0.03%     
==========================================
  Files         220      220              
  Lines       25873    25892      +19     
==========================================
- Hits         7741     7739       -2     
- Misses      17484    17506      +22     
+ Partials      648      647       -1     
Files Changed Coverage Δ
pkg/app/piped/platformprovider/lambda/client.go 4.55% <0.00%> (-0.18%) ⬇️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sivchari sivchari force-pushed the support-wait-function-update branch from f20ea30 to def49fe Compare August 25, 2023 09:36
@sivchari
Copy link
Member Author

@khanhtc1202 @kentakozuka
I'm ready to merge this PR 🕺

@khanhtc1202
Copy link
Member

@sivchari Could you remove grpc update and go packages update from this PR 👀

Comment on lines 305 to 322
retry := backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration))
input := &lambda.GetFunctionInput{
FunctionName: aws.String(functionName),
}
if _, err := retry.Do(ctx, func() (any, error) {
output, err := c.client.GetFunction(ctx, input)
if err != nil {
return nil, err
}
if output.Configuration.LastUpdateStatus != types.LastUpdateStatusSuccessful {
return nil, fmt.Errorf("failed to update Lambda function %s, status code %v, error reason %s",
functionName, output.Configuration.LastUpdateStatus, *output.Configuration.LastUpdateStatusReason)
}
return nil, nil
}); err != nil {
return err
}
Copy link
Member

@khanhtc1202 khanhtc1202 Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
retry := backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration))
input := &lambda.GetFunctionInput{
FunctionName: aws.String(functionName),
}
if _, err := retry.Do(ctx, func() (any, error) {
output, err := c.client.GetFunction(ctx, input)
if err != nil {
return nil, err
}
if output.Configuration.LastUpdateStatus != types.LastUpdateStatusSuccessful {
return nil, fmt.Errorf("failed to update Lambda function %s, status code %v, error reason %s",
functionName, output.Configuration.LastUpdateStatus, *output.Configuration.LastUpdateStatusReason)
}
return nil, nil
}); err != nil {
return err
}
input := &lambda.GetFunctionInput{
FunctionName: aws.String(functionName),
}
retry := backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration))
_, err := retry.Do(ctx, func() (interface{}, error) {
output, err := c.client.GetFunction(ctx, input)
if err != nil {
return nil, err
}
if output.Configuration.LastUpdateStatus != types.LastUpdateStatusSuccessful {
return nil, fmt.Errorf("failed to get Lambda function %s, status code %v, error reason %s",
functionName, output.Configuration.LastUpdateStatus, *output.Configuration.LastUpdateStatusReason)
}
return nil, nil
})
return err
}

How about this?

return nil
}

func (c *client) waitFunctionUpdated(ctx context.Context, functionName string, timeout time.Duration) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this timeout is not being used

@sivchari sivchari force-pushed the support-wait-function-update branch from 9b0afdb to f645600 Compare August 25, 2023 10:30
@sivchari
Copy link
Member Author

@khanhtc1202
Thanks, I fixed these comments.

@khanhtc1202
Copy link
Member

btw, @sivchari due to the comment here
Should we rearrange this function as well (to be called before the UpdateFunctionCode)
https://github.com/pipe-cd/pipecd/blob/master/pkg/app/piped/platformprovider/lambda/client.go#L252-L255

@sivchari sivchari force-pushed the support-wait-function-update branch from f645600 to 91f0475 Compare August 25, 2023 10:50
@sivchari
Copy link
Member Author

@khanhtc1202
This answer is very strong Yes ! I rearranged it.

Comment on lines 235 to 239
// Update function configuration.
if err := c.updateFunctionConfiguration(ctx, fm); err != nil {
return err
}

Copy link
Member

@khanhtc1202 khanhtc1202 Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be at the top of this function (before L230 reading zip) to avoid unnecessary disk read if the update function configuration returns error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Thnaks.

@sivchari sivchari force-pushed the support-wait-function-update branch from 6a6e441 to 5f278a9 Compare August 25, 2023 10:59
return nil
}

func (c *client) waitFunctionUpdated(ctx context.Context, functionName string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this function body to L298? Looks like this function is specified to be used only by updateFunctionConfiguration, so I don't think we have enough reason to separate it as an independent function 🤔 Also, the current function name is quite common, waitFunctionUpdated while we have many UpdateFunctionXXX, which could cause misleading. So removing this function and moving all of its body to be part of updateFunctionConfiguration could be a better choice if you only want to wait after updating function configuration. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

Also, the current function name is quite common, waitFunctionUpdated while we have many UpdateFunctionXXX, which could cause misleading.

I thinks so too.

@sivchari sivchari force-pushed the support-wait-function-update branch from 5f278a9 to c577c6e Compare August 25, 2023 11:07
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look neat, just left nits comments 😀

Comment on lines 313 to 316
if err != nil {
return err
}
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	return err

nits

@sivchari sivchari force-pushed the support-wait-function-update branch from c577c6e to 32f955b Compare August 25, 2023 17:45
input := &lambda.GetFunctionInput{
FunctionName: aws.String(fm.Spec.Name),
}
_, err = retry.Do(ctx, func() (any, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I just noticed that we reused the previous retry object here. I think we should recreate a new one instead since the same object may contain previously updated backoff internal, thus the number of retry times is not as expected.

Suggested change
_, err = retry.Do(ctx, func() (any, error) {
retry = backoff.NewRetry(RequestRetryTime, backoff.NewConstant(RetryIntervalDuration))
_, err = retry.Do(ctx, func() (any, error) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khanhtc1202
I fixed it.

@khanhtc1202
Copy link
Member

@sivchari After this got merge, I will release v0.45.3-rc1 then you can test it before we make release v0.45.3 😄

@sivchari sivchari force-pushed the support-wait-function-update branch from 32f955b to e3ed289 Compare August 28, 2023 03:25
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks 🍏

@khanhtc1202 khanhtc1202 merged commit 6e9660d into pipe-cd:master Aug 28, 2023
khanhtc1202 pushed a commit that referenced this pull request Aug 28, 2023
* update: support to wait to update function

Signed-off-by: sivchari <[email protected]>

* rearrange: updatefunctionfromsource

Signed-off-by: sivchari <[email protected]>

---------

Signed-off-by: sivchari <[email protected]>
khanhtc1202 added a commit that referenced this pull request Aug 28, 2023
* update: support to wait to update function (#4565)

* update: support to wait to update function

Signed-off-by: sivchari <[email protected]>

* rearrange: updatefunctionfromsource

Signed-off-by: sivchari <[email protected]>

---------

Signed-off-by: sivchari <[email protected]>

* Wait ECS taskset stable (#4573)

* Wait ECS taskset stable

Signed-off-by: khanhtc1202 <[email protected]>

* Change number of retry time

Signed-off-by: khanhtc1202 <[email protected]>

* No sleep required

Signed-off-by: khanhtc1202 <[email protected]>

---------

Signed-off-by: khanhtc1202 <[email protected]>

---------

Signed-off-by: sivchari <[email protected]>
Signed-off-by: khanhtc1202 <[email protected]>
Co-authored-by: sivchari <[email protected]>
moko-poi pushed a commit to moko-poi/pipecd that referenced this pull request Nov 3, 2023
* update: support to wait to update function

Signed-off-by: sivchari <[email protected]>

* rearrange: updatefunctionfromsource

Signed-off-by: sivchari <[email protected]>

---------

Signed-off-by: sivchari <[email protected]>
Signed-off-by: moko-poi <[email protected]>
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Nov 5, 2023
* update: support to wait to update function

Signed-off-by: sivchari <[email protected]>

* rearrange: updatefunctionfromsource

Signed-off-by: sivchari <[email protected]>

---------

Signed-off-by: sivchari <[email protected]>
@github-actions github-actions bot mentioned this pull request Dec 1, 2023
@github-actions github-actions bot mentioned this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants