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

Retain console properties on function deploy #11849

Merged
merged 10 commits into from Mar 23, 2023

Conversation

Danwakeem
Copy link
Contributor

Description

Fixed an issue when deploying a single function that has been instrumented by serverless console.

Should retain environment variables and layers externally added by serverless console 👍

@Danwakeem Danwakeem requested a review from medikoo March 21, 2023 18:52
@Danwakeem Danwakeem self-assigned this Mar 21, 2023
@medikoo medikoo changed the title fix: Retain console properties on function deploy Retain console properties on function deploy Mar 21, 2023
@medikoo medikoo added enhancement and removed bug labels Mar 21, 2023
@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Patch coverage: 95.91% and project coverage change: +0.66 🎉

Comparison is base (9c7e5b4) 85.97% compared to head (e88a482) 86.64%.

❗ Current head e88a482 differs from pull request most recent head a1e711a. Consider uploading reports for the commit a1e711a to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11849      +/-   ##
==========================================
+ Coverage   85.97%   86.64%   +0.66%     
==========================================
  Files         316      316              
  Lines       13377    13401      +24     
==========================================
+ Hits        11501    11611     +110     
+ Misses       1876     1790      -86     
Impacted Files Coverage Δ
lib/classes/utils.js 95.74% <ø> (ø)
lib/classes/yaml-parser.js 100.00% <ø> (ø)
lib/plugins/aws/deploy-function.js 96.53% <94.11%> (+0.31%) ⬆️
lib/cli/interactive-setup/console-dev-mode-feed.js 87.59% <100.00%> (+69.85%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Thanks @Danwakeem for taking care of that.

It'll be great to also have that covered with unit tests (setup with runServerless) that test scenario where layers are configured remotely and (1) not configured explicitly in service config (2) configured explicitly in service config

lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
@Danwakeem
Copy link
Contributor Author

@medikoo I noticed that the updateFunctionConfiguration configuration was stubbed in the unit tests. Would you mind if I extracted out the update layers and environment variable logic and unit test those functions individually?

I feels like there is a lot going on in the updateFunctionConfiguration and it might be worth breaking out a few of these steps into their own functions so they are easily testable. What do you think?

@medikoo
Copy link
Contributor

medikoo commented Mar 22, 2023

@Danwakeem ideally this should be handled as other tests that are configured with runServerless.

What you need to here is believe introduce some extra representations of lambda configurations to be returned by Lambda.getFunction. This should be pretty easy I think. It's a question of reconfiguring this:

getFunction: {
Configuration: {
LastModified: '2020-05-20T15:34:16.494+0000',
State: 'Active',
LastUpdateStatus: 'Successful',
},
},

Into dynamic resolution as follows:

getFunction: (params) {
  if (params.FunctionName === 'console') {
    // return configuration with layers
  } else {
    return {
          LastModified: '2020-05-20T15:34:16.494+0000',
          State: 'Active',
          LastUpdateStatus: 'Successful',
        };
  }
}

And then in your test cases when you want to test against functions with layers you just pick name which will return you configurations with layers

@Danwakeem
Copy link
Contributor Author

Danwakeem commented Mar 22, 2023

@medikoo But isn't the function this code is written in stubbed in those same tests? So runServerless wouldn't run the logic in the updateFunctionCode? 🤔 👇

updateFunctionConfiguration: updateFunctionConfigurationStub,

If this is the case, it might make sense to just extract the two logic blocks where we merge layers and environment variables into small functions so we can test those bits of logic individually. I was thinking this could make this block of code a bit more readable and easier to test.

@medikoo
Copy link
Contributor

medikoo commented Mar 22, 2023

updateFunctionConfigurationStub is a stub for AWS SDK Function.updateFunctionConfiguration request, so no real request is issued but you can track with what arguments it was called. We do not provide any internal logic for this stub, it's a pure sinon stub.

In test I believe you need to confirm that this stub was triggered with expected layers set and environment variables

@Danwakeem Danwakeem force-pushed the updated-deploy-function-for-console branch from 2e0cbe3 to 7b123e8 Compare March 22, 2023 16:19
@Danwakeem
Copy link
Contributor Author

Thanks @medikoo. After poking around with the tests for a bit I see how these fit together. I ended up adding the tests you had suggested and some more fine grain tests on merging environment and layer properties.

Let me know what you think about the tests I added in the most recent commit 🙏

@Danwakeem Danwakeem requested a review from medikoo March 22, 2023 16:34
test/unit/lib/plugins/aws/deploy-function.test.js Outdated Show resolved Hide resolved
lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
@Danwakeem Danwakeem requested a review from medikoo March 22, 2023 19:29
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Thank you @Danwakeem. It looks very promising. We're getting close 👍

lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
test/unit/lib/plugins/aws/deploy-function.test.js Outdated Show resolved Hide resolved
@Danwakeem Danwakeem requested a review from medikoo March 22, 2023 21:53
@Danwakeem
Copy link
Contributor Author

@medikoo Thanks for pointing out that I could convert the getFunction property to a function. It would have taken me a while to figure that out 😅

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Thank you @Danwakeem ! I have just a few final suggestions

lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
test/unit/lib/plugins/aws/deploy-function.test.js Outdated Show resolved Hide resolved
@Danwakeem Danwakeem requested a review from medikoo March 23, 2023 15:00
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Thanks @Danwakeem, we're close!

lib/plugins/aws/deploy-function.js Outdated Show resolved Hide resolved
test/unit/lib/plugins/aws/deploy-function.test.js Outdated Show resolved Hide resolved
@Danwakeem Danwakeem requested a review from medikoo March 23, 2023 15:56
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Looks great 👍 🎉

@medikoo medikoo merged commit 4ee5505 into serverless:main Mar 23, 2023
5 checks passed
@Danwakeem Danwakeem deleted the updated-deploy-function-for-console branch March 23, 2023 18:44
@Danwakeem
Copy link
Contributor Author

Thanks again @medikoo 🎸 lol I think with all the help you have offered me I owe you a beer or something 🍻

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.

None yet

2 participants