Skip to content

Conversation

@khanhtc1202
Copy link
Member

@khanhtc1202 khanhtc1202 commented Jan 18, 2021

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.49%. This pull request decreases coverage by -0.35%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/lambda/client.go client.AvailableFunctionName -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.PublishFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.GetTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.Apply 0.00% -- +-0.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.49%. This pull request decreases coverage by -0.35%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/lambda/client.go client.AvailableFunctionName -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.PublishFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.GetTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.Apply 0.00% -- +-0.00%

@khanhtc1202 khanhtc1202 changed the title Update lambda client interface Reimplement Lambda deployment QUICK_SYNC strategy Jan 18, 2021
@khanhtc1202 khanhtc1202 marked this pull request as ready for review January 18, 2021 10:42
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.52%. This pull request decreases coverage by -0.31%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/lambda/client.go client.AvailableFunctionName -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.PublishFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.GetTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.Apply 0.00% -- +-0.00%

Comment on lines +112 to +114
// Wait before ready to commit change.
in.LogPersister.Info("Waiting to update lambda function in progress...")
time.Sleep(3 * time.Minute)
Copy link
Member Author

Choose a reason for hiding this comment

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

fyi, the Lambda's CreateFunction/UpdateFunction API call returns right after we make a request to update the Lambda function code/config, but the update process still running internally in Lambda servers. If we make PublishFunction request immediately, the error ResourceConflictException: The operation cannot be performed at this time. will be raised.

Copy link
Member

Choose a reason for hiding this comment

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

Really? 😢 I think fixed 3 minutes is not safe for all cases, but we don't know how much is good.
So I think in addition to waiting for a fixed amount of time (e.g. 1m) we should also do PublishFunction with a constant backoff.
https://github.com/pipe-cd/pipe/tree/master/pkg/backoff

Copy link
Member

Choose a reason for hiding this comment

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

/ping

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'm working on it, but shall we make another PR to fix this separately from this PR 👀

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that is ok. Let's add a TODO and do it in another PR.


if err := client.Apply(ctx, fm); err != nil {
in.LogPersister.Errorf("Failed to apply the lambda function manifest (%v)", err)
ok, err := client.AvailableFunctionName(ctx, fm.Spec.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should rename this function AvailableFunctionName.
How about "IsFunctionExisting" or "FunctionExists"?

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, I will go for IsFunctionExist 👍

return true
}
if err != nil {
in.LogPersister.Errorf("Failed to prapare traffic routing for Lambda function %s: %v", fm.Spec.Name, err)
Copy link
Member

Choose a reason for hiding this comment

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

typo: "prepare"

PublishFunction(ctx context.Context, fm FunctionManifest) (version string, err error)
GetTrafficConfig(ctx context.Context, fm FunctionManifest) (routingTrafficCfg []VersionTraffic, err error)
CreateRoutingTraffic(ctx context.Context, fm FunctionManifest, version string) error
UpdateRoutingTraffic(ctx context.Context, fm FunctionManifest, routingTraffic []VersionTraffic) error
Copy link
Member

Choose a reason for hiding this comment

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

nit: How about CreateTrafficConfig and UpdateTrafficConfig?

time.Sleep(3 * time.Minute)

// Commit version for applied Lambda function.
version, err := client.PublishFunction(ctx, fm)
Copy link
Member

Choose a reason for hiding this comment

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

I'm concerned that when users clicked the SYNC button to sync the application without any changes.
In that case, no changes were added on AWS Lambda side and it is ok to publish the function?
I think we may receive a "NoChange" error or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

AWS Lambda doesn't publish a version if the function's configuration and code haven't changed since the last version. Use UpdateFunctionCode or UpdateFunctionConfiguration to update the function before publishing a version.

Yes, you guess right, due to the docs of PublishVersion, we have to make some changes on source/configuration of the function to be able to publish a new version of it. So the error returned here for that case is predictable. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a note about this lack on the AWS documentation.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.52%. This pull request decreases coverage by -0.32%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/lambda/client.go client.AvailableFunctionName -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.PublishFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.GetTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.Apply 0.00% -- +-0.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.51%. This pull request decreases coverage by -0.32%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/lambda/client.go client.AvailableFunctionName -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.PublishFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.GetTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateRoutingTraffic -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go precentToPercentage -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.Apply 0.00% -- +-0.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.51%. This pull request decreases coverage by -0.32%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/lambda/client.go client.IsFunctionExist -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.PublishFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.GetTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go precentToPercentage -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.Apply 0.00% -- +-0.00%

return fmt.Errorf("unknown error given: %w", err)
}

// TODO more configurable fields from here:
Copy link
Member

Choose a reason for hiding this comment

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

you know what, actually Kapetanios's TODO plugin uses only TODO: or FIXME: as a keyword by default. So you'd better use TODO: if you need to open a new issue.
https://kapetanios.dev/docs/plugins/todo/

err = fmt.Errorf("resource already existed or in progress: %w", err)
}
}
err = fmt.Errorf("unknown error given: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

This overrides all previous errors.

Copy link
Member

Choose a reason for hiding this comment

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

nit: Return fast to avoid deep nesting.

aerr, ok := err.(awserr.Error)
if !ok {
   return ...
}

switch aeer.Code() {
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch, let's me fix this part 🙏

err = ErrNotFound
}
}
err = fmt.Errorf("unknown error given: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

Here too.

return
}

if cfg.RoutingConfig != nil {
Copy link
Member

Choose a reason for hiding this comment

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

if cfg.RoutingConfig == nil {
   return ...
}

@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. Support more configurable fields using Lambda.UpdateFunctionConfiguration.

https://github.com/pipe-cd/pipe/blob/9d524656e6b34f0848e16cf35826a40e19189afd/pkg/app/piped/cloudprovider/lambda/client.go#L153-L156

This was created by todo plugin since "TODO:" was found in 9d52465 when #1443 was merged. cc: @khanhtc1202.

2. Fix Lambda.AliasConfiguration.RoutingConfig nil value.

https://github.com/pipe-cd/pipe/blob/9d524656e6b34f0848e16cf35826a40e19189afd/pkg/app/piped/cloudprovider/lambda/client.go#L222-L225

This was created by todo plugin since "TODO:" was found in 9d52465 when #1443 was merged. cc: @khanhtc1202.

3. Using backoff instead of time sleep waiting for a specific duration of time.

https://github.com/pipe-cd/pipe/blob/9d524656e6b34f0848e16cf35826a40e19189afd/pkg/app/piped/executor/lambda/lambda.go#L112-L115

This was created by todo plugin since "TODO:" was found in 9d52465 when #1443 was merged. cc: @khanhtc1202.

@pipecd-bot
Copy link
Collaborator

GO_LINTER

The golinter build is completed with FAILURE. The build will be triggered again when you push any other commits. Or you can trigger it manually by /golinter trigger command right now.

You can check the build log from here.

@khanhtc1202
Copy link
Member Author

@nghialv @nakabonne thanks for your comments, PTAL 🙏

@khanhtc1202
Copy link
Member Author

khanhtc1202 commented Jan 19, 2021

/golinter trigger

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.49%. This pull request decreases coverage by -0.34%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/lambda/client.go client.IsFunctionExist -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.PublishFunction -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.GetTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.CreateTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.UpdateTrafficConfig -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go precentToPercentage -- 0.00% +0.00%
pkg/app/piped/cloudprovider/lambda/client.go client.Apply 0.00% -- +-0.00%

@nghialv
Copy link
Member

nghialv commented Jan 19, 2021

Nice.
/lgtm

@nakabonne
Copy link
Member

👍
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by nakabonne.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants