Skip to content

Fix: LogGroup & function name ignores stage flag passed in from CLI tool. #4929 - #5508

Closed
vkkis93 wants to merge 1 commit into
serverless:masterfrom
techmagic-team:fix/stageCli
Closed

vkkis93 wants to merge 1 commit into
serverless:masterfrom
techmagic-team:fix/stageCli

Conversation

@vkkis93

@vkkis93 vkkis93 commented Nov 20, 2018

Copy link
Copy Markdown
Contributor

What did you implement:

Closes #4929

When the serverless.yml has no stage key, and you use the --stage flag, the LogGroup and function name will be named using the default dev stage.

For example we have serverless file like this

service: banana

provider:
  name: aws
  runtime: nodejs6.10

functions:
  hello:
    handler: handler.hello
    name: hello-${self:provider.stage}

If look you can see that provider does not have stage but function name has reference on ${self:provider.stage}.
When user deploys it and pass --stage flag in cli it works a little bit strange.
Cloudformation stack will be named OK but cloudwatch group name and function name will ignore it and will use always default stage('dev')

How did you implement it:

If --stage flag was passed in cli it rewrites default stage 'dev', but it does not rewrite stage which was specified in provider section.

How can we verify it:

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@vkkis93 vkkis93 changed the title fix stage when it was passed through cli Fix: LogGroup & function name ignores stage flag passed in from CLI tool. #4929 Nov 20, 2018

@dschep dschep 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.

Hmm. I personally like this but I'm not entirely sure of the implications. I always use ${opt:stage, self:provider.stage} to avoid the issue and often add a shortcut in custom so that I can use ${self:custom.stage} instead:

custom:
  stage: ${opt:stage, self:provider.stage}

@vkkis93

vkkis93 commented Nov 20, 2018 •

Copy link
Copy Markdown
Contributor Author

Hi @dschep .
I totally agree with you about

custom:
  stage: ${opt:stage, self:provider.stage}

But @bvanderlugt found a bug when user does not know/use this approach.
Potenitially can be affected only new users who started use framework

@pmuens pmuens 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.

Thanks for working on this fix @vkkis93! 👍

🤔 I see the value but I'm also unsure whether we want to introduce the stage concept in lib/Serverless.js (although stages are a first-class citizen).

Also not entirely sure about the implications of this change (especially not when using Serverless in a non-AWS context).

@dschep dschep self-assigned this Nov 29, 2018

@pmuens pmuens 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.

Just looked into this again today. Is there any way we could bake this into the Variables system? I see the value here and it seems like this is an all to common mistake user usually make.

Generaally speaking ${self:} should reference only values which are present in serverless.yml, so if e.g. there's no foo then ${self:foo} should be undefined but given that we're mixing serverless.yml and it's Serverless Variables system with the internal Serverless object we pass around it becomes unpredictable and hard to understand when working with it.


Edit: I think the best way would be to use defaults here. Defaults are the exact use-case for the desired outcome.

Tweaking ${self:} to do some magic would make it unpredictable. Varaibles which are not defined but referenced via ${self:} in serverless.yml should result in undefined.

Maybe we should update the documentation to make the default / fallback functionality more prominent.

@pmuens pmuens mentioned this pull request Apr 30, 2019
7 tasks done
@pmuens
pmuens requested review from medikoo and removed request for HyperBrain, eahefnawy and horike37 June 6, 2019 10:48

@pmuens pmuens 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.

Still on the fence on this one. I'd love to see a way that this is fixed since it caused a lot of confusion (especially for beginner) in the past.

@medikoo do you maybe have an idea how we could implement / fix this?

@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.

I think it's a good call, and best would be to we have a single source of truth.

In my opinion {self:provider.stage} should just work without surprises, and there should be no need for ${opt:stage, self:provider.stage} which looks as undesired complexity.

Implementation wise, I agree this should not be solved in lib/Serverless.js, but rather here:

stage: 'dev',

@pmuens

pmuens commented Jun 7, 2019

Copy link
Copy Markdown
Contributor

Good idea! Thanks for the feedback and the idea to put it into Service.js @medikoo 👍

@vkkis93 I know it's been a while. Do you want to pick this up or should we finish this PR?

@pmuens

pmuens commented Jul 31, 2019

Copy link
Copy Markdown
Contributor

Since this PR got quite stale I'll close this for now. We still have #4929 to track the core issue. Feel free to re-open the PR if the aforementioned review comments can be addressed or if you need any help with the implementation.

@vkkis93 thanks again for taking the time to look into this! 👍 💯

@pmuens pmuens closed this Jul 31, 2019
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.

LogGroup ignores stage flag passed in from CLI tool.

4 participants