Skip to content

Add option to specify when to emit st2.generic.actiontrigger #4315

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

Merged
merged 4 commits into from
Sep 5, 2018

Conversation

shusugmt
Copy link
Contributor

As per motivation addressed in #4312

  • Introduced new config parameter action_sensor.emit_when which specifies the states when to emit st2.generic.actiontrigger
  • If not specified, it defaults to LIVEACTION_COMPLETED_STATES that is the exact same behavior as before. Meaning this change will not affect any existing deployments.
  • If any state is given, it overrides the default. So users can even choose only to make actiontrigger emitted at for e.g. cancelled. If users want to completely disable this trigger then they can use existing action_sensor.enable parameter set to False.
  • This PR also includes a bug fix that action_sensor.enable parameter was not honored at all.

@nmaludy
Copy link
Member

nmaludy commented Aug 24, 2018

+100 !!!

I was thinking the other day it would be great if there were more triggers in the system for "internal" events like this!

LOG.debug('Action trigger is disabled, skipping trigger dispatch...')
return

target_statuses = cfg.CONF.action_sensor.emit_when
Copy link
Member

Choose a reason for hiding this comment

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

Would be a good idea to log a message under DEBUG if trigger is not emitted due to the status not being in ``emit_when list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. Thanks for the comments!

@@ -388,6 +388,10 @@ def register_opts(ignore_errors=False):
cfg.BoolOpt(
'enable', default=True,
help='Whether to enable or disable the ability to post a trigger on action.'),
cfg.ListOpt(
'emit_when', default=[],
Copy link
Member

Choose a reason for hiding this comment

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

For explicitness sake, you could perhaps default this option to LIVEACTION_COMPLETED_STATES.

This way you could also simple the code here a bit - https://github.com/StackStorm/st2/pull/4315/files#diff-70b51c2693ac263742fc28ad30ebc932R234.

Copy link
Contributor Author

@shusugmt shusugmt Sep 4, 2018

Choose a reason for hiding this comment

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

For explicitness sake, you could perhaps default this option to LIVEACTION_COMPLETED_STATES.

If we specify the list here explicitly, then we need to follow LIVEACTION_COMPLETED_STATES changes that may happen in the future. So I thought this way is better but I'm OK with either option. What do you think?

This way you could also simple the code here a bit

Anyways that test case still needs to be there because users might have chance to specify a null or a blank list.

Copy link
Member

Choose a reason for hiding this comment

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

That's true, but I don't think that should be a big deal because any change to that constant would also mean user would need to update and restart all the services so the change would be picked up.

Copy link
Member

Choose a reason for hiding this comment

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

I will merge this into master and open a small PR with changelog entry and this change here which will allow us to slightly simplify the if statement.

Copy link
Member

Choose a reason for hiding this comment

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

And another reason why I prefer to use a default value here is because it's more explicit.

If this option contain no default value here, user needs to dig through the code and documentation to figure out what a default value of None indicates.

@Kami
Copy link
Member

Kami commented Sep 3, 2018

Nice work, thank you 👍

I've added some comments, nothing major.

@Kami Kami self-assigned this Sep 3, 2018
@Kami Kami added this to the 2.9.0 milestone Sep 3, 2018
@@ -79,22 +78,18 @@ def process(self, execution_db):
extra = {'execution': execution_db}
LOG.debug('Processing action execution "%s".', execution_id, extra=extra)

if execution_db.status not in LIVEACTION_COMPLETED_STATES:
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, but I found previous code a bit easier to read / follow ("return early" vs "nested if", one level less of nesting).

Was there any particular reason why you changed it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is inevitable since:

  1. I thought the order of other function calls is important here and shouldn't be changed (to keep this: apply_post_run_policies -> _post_notify_triggers -> _post_generic_trigger)
  2. We always need to call _post_generic_trigger regardless of the status. So If we want to do a "early return" then I need to move that call before if execution_db.status not in LIVEACTION_COMPLETED_STATES: line but that will break the order (_post_generic_trigger will be called before _post_notify_triggers)

@shusugmt
Copy link
Contributor Author

shusugmt commented Sep 4, 2018

@Kami PR updated. Please take a look.

LOG.debug('Action trigger is disabled, skipping trigger dispatch...')
return

execution_id = str(execution_db.id)
extra = {'execution': execution_db}

target_statuses = cfg.CONF.action_sensor.emit_when
Copy link
Member

Choose a reason for hiding this comment

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

Small style thing - I would do target_statuses = cfg.CONF.action_sensor.emit_when or LIVEACTION_COMPLETED_STATES this way we could get rid of else clause.

Besides that, LGTM 👍

@Kami Kami merged commit 31da26b into StackStorm:master Sep 5, 2018
Kami added a commit that referenced this pull request Sep 5, 2018
@Kami Kami mentioned this pull request Sep 5, 2018
@Kami
Copy link
Member

Kami commented Sep 5, 2018

Merged, thanks!

Changelog and default value change in #4330.

@shusugmt shusugmt deleted the selectable-actiontrigger branch September 5, 2018 11:12
Kami added a commit that referenced this pull request Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants