Skip to content

exclude tags and reservedConcurrency from version hash - #8212

Merged
medikoo merged 12 commits into
serverless:masterfrom
thewizarodofoz:ignore-function-wide-properties-in-version-hash
Sep 22, 2020
Merged

medikoo merged 12 commits into
serverless:masterfrom
thewizarodofoz:ignore-function-wide-properties-in-version-hash

Conversation

@thewizarodofoz

Copy link
Copy Markdown
Contributor

Closes: #7822

@codecov-commenter

codecov-commenter commented Sep 10, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #8212 into master will decrease coverage by 0.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8212      +/-   ##
==========================================
- Coverage   88.16%   88.03%   -0.13%     
==========================================
  Files         248      248              
  Lines        9430     9320     -110     
==========================================
- Hits         8314     8205     -109     
+ Misses       1116     1115       -1     
Impacted Files Coverage Δ
lib/plugins/aws/package/compile/functions/index.js 97.03% <100.00%> (-0.22%) ⬇️
...plugins/aws/package/compile/events/stream/index.js 98.00% <0.00%> (-0.60%) ⬇️
.../package/compile/events/websockets/lib/validate.js 97.22% <0.00%> (-0.51%) ⬇️
lib/configSchema.js 100.00% <0.00%> (ø)
lib/utils/getCommandSuggestion.js 100.00% <0.00%> (ø)
lib/plugins/aws/invokeLocal/index.js 69.66% <0.00%> (ø)
lib/plugins/aws/provider/awsProvider.js 93.11% <0.00%> (ø)
lib/plugins/interactiveCli/initializeService.js 100.00% <0.00%> (ø)
...ib/plugins/aws/package/compile/events/sns/index.js 100.00% <0.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3177e40...e29da47. Read the comment docs.

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @thewizarodofoz ! That looks very promising. Please see my remarks

Comment on lines +497 to +502
const functionWideProperties = ['ReservedConcurrentExecutions', 'Tags'];
const properties = _.omit(
_.get(functionResource, 'Properties', {}),
'Code',
...functionWideProperties
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the added value of creating functionWideProperties variable.

Isn't it simpler to just do _.omit(..., ['Code', 'ReservedConcurrentExecutions', 'Tags'] ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought it would make it more clear as to why these fields are omitted

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@thewizarodofoz that's a good point , but it'll probably be fine to solve it with simple inline code comment:

_.omit(..., [
  'Code',
   // Properties applied to function globally (not specific to version or alias)
  'ReservedConcurrentExecutions', 'Tags'
])

});
});

it('should not create a new version object if only function-wide configuration changed', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All new tests should be written with help of runServerless util (see https://github.com/serverless/serverless/blob/master/test/README.md)

In this case I would rely on basic function fixture as follows

  1. Setup a fixture with fixture.setup, as e.g. it's done here:
    fixtures.setup('httpApi').then(({ servicePath }) =>
  2. Issue first runServerless and read all generated lambda version ids
  3. Modify reservedConcurrency and tags with help of updateConfig (returned by fixture.setup()) as it's done here:
    await updateConfig({
    provider: {
    tags: {
    foo: 'bar',
    baz: 'qux',
    },
    tracing: {
    apiGateway: true,
    },
    logs: {
    restApi: true,
    },
    },
    });
  4. Re-run runServerless, and confirm that version id didn't change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @medikoo I refactored the test, but it seems to me the second call to runServerless isn't reading the updated config. I debugged the test and I did see updateConfig updating the serverless.yml in the temp dir, but as you can see in this assertion (which fails), runServerless isn't picking up those changes.

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

runServerless isn't picking up those changes.

Thanks for pointing. Indeed there was an issue in memoization setup, due to which, in same process second serverless instance of same service was relying on previously resolved config. I've fixed that in #8231

Update with master and issue should be gone

_.get(functionResource, 'Properties', {}),
'Code',
// Properties applied to function globally (not specific to version or alias)
// https://github.com/serverless/serverless/issues/7822

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can remove the link to github issue.

If needed, it's easy to map given code lines to source PR and issue, by GitHub blame feature

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@thewizarodofoz that looks great! Thank you

I have just one final remark. Last week we've released v2 and dropped support for Node.js v6, which means we can freely now use async/await syntax, and ideally (for better maintenance) if all new code is introduced in that style.

Can you update the fixture so it's configured with async function and await keywords?

Sorry for late notice

Comment on lines +2837 to +2838
it('should not create a new version object if only function-wide configuration changed', () => {
return fixtures.setup('function').then(({ servicePath, updateConfig }) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we upgrade this to async/await syntax?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was really hoping to do that! Yay!

@medikoo

medikoo commented Sep 21, 2020

Copy link
Copy Markdown
Contributor

@thewizarodofoz is this ready for re-review? If so, please re-request review in Reviewers box

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @thewizarodofoz, It's all great, aside of that we should not commit describe.only.

Can you update it?

});
});

describe.only('function config', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.only I believe was committed in by accident

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @thewizarodofoz !

@medikoo
medikoo merged commit 1fceb89 into serverless:master Sep 22, 2020
@azizur

azizur commented Sep 27, 2020

Copy link
Copy Markdown

This PR has not resolved the issue. I am still getting A version for this Lambda function exists ( XXX ). Modify the function to create a new version..

@medikoo

medikoo commented Sep 28, 2020

Copy link
Copy Markdown
Contributor

@azizur see: #7822 (comment)

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.

Receiving "A version for this Lambda function exists" error when adding 'reservedConcurrency' property to existing function

4 participants