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

[WIP] [Issue#4939] Changes to support new purge task executions and purge workflows #4924

Closed
wants to merge 9 commits into from

Conversation

srimandaleeka01
Copy link
Contributor

@srimandaleeka01 srimandaleeka01 commented Apr 27, 2020

Closes #4939

@pull-request-size pull-request-size bot added the size/S PR that changes 10-29 lines. Very easy to review. label Apr 27, 2020
@CLAassistant
Copy link

CLAassistant commented Apr 27, 2020

CLA assistant check
All committers have signed the CLA.

@pull-request-size pull-request-size bot added size/XL PR that changes 500-999 lines. Consider splitting work into several ones that easier to review. and removed size/S PR that changes 10-29 lines. Very easy to review. labels Apr 28, 2020
@srimandaleeka01 srimandaleeka01 changed the title changes to support new purge task executions and st2 purge workflow [WIP] Changes to support new purge task executions and st2 purge workflow Apr 28, 2020
@srimandaleeka01 srimandaleeka01 changed the title [WIP] Changes to support new purge task executions and st2 purge workflow [WIP] [Issue#4939] Changes to support new purge task executions and st2 purge workflow May 6, 2020
@nmaludy nmaludy requested a review from m4dcoder May 26, 2020 14:58
Copy link
Member

@nmaludy nmaludy left a comment

Choose a reason for hiding this comment

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

@srimandaleeka01 I think overall these changes are great to see.

What i think would be a better approach though is to integrate the workflow and task purging into the already existing purge executions script. This way things like the st2garbagecollector process will be automatically updated.

Should be just moving some code around.

Does that sound good?

@nmaludy nmaludy linked an issue May 26, 2020 that may be closed by this pull request
@stale
Copy link

stale bot commented Aug 27, 2020

Thanks for contributing to this issue. As it has been 90 days since the last activity, we are automatically marking is as stale. If this issue is not relevant or applicable anymore (problem has been fixed in a new version or similar), please close the issue or let us know so we can close it. On the contrary, if the issue is still relevant, there is nothing you need to do, but if you have any additional details or context which would help us when working on this issue, please include it as a comment to this issue.

@stale stale bot added the stale label Aug 27, 2020
@stale stale bot removed the stale label Feb 24, 2021
======================================================================
1) ERROR: test_run (test_action_unload.UnloadActionTestCase)
----------------------------------------------------------------------
   Traceback (most recent call last):
    tests/test_action_unload.py line 100 in test_run
      action.run(packs=[pack])
    actions/pack_mgmt/unload.py line 68 in run
      self._unregister_rules(pack=pack)
    actions/pack_mgmt/unload.py line 99 in _unregister_rules
      cleanup_trigger_db_for_rule(rule_db=rule_db)
    /home/runner/work/st2/st2/st2common/st2common/services/triggers.py line 332 in cleanup_trigger_db_for_rule
      Trigger.delete_if_unreferenced(existing_trigger_db)
    /home/runner/work/st2/st2/st2common/st2common/persistence/trigger.py line 61 in delete_if_unreferenced
      cls._get_impl().delete_by_query(**delete_query)
    /home/runner/work/st2/st2/st2common/st2common/models/db/__init__.py line 479 in delete_by_query
      super(self)
   TypeError: super() argument 1 must be type, not MongoDBAccess
@srimandaleeka01
Copy link
Contributor Author

srimandaleeka01 commented Feb 24, 2021

@srimandaleeka01 I think overall these changes are great to see.

What i think would be a better approach though is to integrate the workflow and task purging into the already existing purge executions script. This way things like the st2garbagecollector process will be automatically updated.

Should be just moving some code around.

Does that sound good?

Thanks for the pointer @nmaludy . Sorry have been out of loop on this project. I made the changes to call purge workflow and task executions in the garbagecollector . Please take a look : 36c7fdf

With the above change I also added 2 new attributes _workflow_execution_ttl _task_execution_ttl this is causing the unit tests to fail . How can I fix the unit test ? Couldn't figure out yet where the st2.conf file is being patched or where the fixture is

Thanks again!

----------------------------------------------------------------------
   Traceback (most recent call last):
    /opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/mock/mock.py line 1305 in patched
      return func(*args, **keywargs)
    st2actions/tests/unit/test_workflow_engine.py line 226 in test_process_error_handling_has_error
      gc = garbage_collector.GarbageCollectorService()
    st2reactor/st2reactor/garbage_collector/base.py line 72 in __init__
      self._workflow_execution_ttl = cfg.CONF.garbagecollector.workflow_execution_ttl
    /opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/oslo_config/cfg.py line 2547 in __getattr__
      return self._conf._get(name, self._group)
    /opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/oslo_config/cfg.py line 2264 in _get
      value = self._do_get(name, group, namespace)
    /opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/oslo_config/cfg.py line 2282 in _do_get
      info = self._get_opt_info(name, group)
    /opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/oslo_config/cfg.py line 2415 in _get_opt_info
      raise NoSuchOptError(opt_name, group)
   NoSuchOptError: no such option in group garbagecollector: workflow_execution_ttl```

and an additional Lint failure as well 

```echo "# Sample config which contains all the available options which the corresponding descriptions" > conf/st2.conf.sample;
echo "# Note: This file is automatically generated using tools/config_gen.py - DO NOT UPDATE MANUALLY" >> conf/st2.conf.sample
echo "" >> conf/st2.conf.sample
. virtualenv/bin/activate; python ./tools/config_gen.py >> conf/st2.conf.sample;
make[1]: Leaving directory '/home/runner/work/st2/st2'
diff conf/st2.conf.sample /tmp/st2.conf.sample.upstream || (echo "conf/st2.conf.sample hasn't been re-generated and committed. Please run \"make configgen\" and include and commit the generated file." && exit 1)
167a168,172
> # Workflow execution output objects (ones generated by action output streaming) older than this value (days) will be automatically deleted.
> workflow_execution_ttl = 7
> # Task execution output objects (ones generated by action output streaming) older than this value (days) will be automatically deleted.
> task_execution_ttl = 7
> ```





 

@srimandaleeka01 srimandaleeka01 changed the title [WIP] [Issue#4939] Changes to support new purge task executions and st2 purge workflow [WIP] [Issue#4939] Changes to support new purge task executions and purge workflows Feb 24, 2021
@cognifloyd
Copy link
Member

We just reformatted the code with black. So, would you merge master into your branch (resolve any conflicts & reformat with black)? This should help resolve any linting errors. Thanks!

@stale
Copy link

stale bot commented Jun 9, 2021

Thanks for contributing to this issue. As it has been 90 days since the last activity, we are automatically marking is as stale. If this issue is not relevant or applicable anymore (problem has been fixed in a new version or similar), please close the issue or let us know so we can close it. On the contrary, if the issue is still relevant, there is nothing you need to do, but if you have any additional details or context which would help us when working on this issue, please include it as a comment to this issue.

@stale stale bot added the stale label Jun 9, 2021
@stale stale bot removed the stale label Jul 29, 2021
@cognifloyd
Copy link
Member

@srimandaleeka01 I'd really like to see this in v3.6.0 if possible. Do you have bandwidth to bring this up-to-date with master?

Both unit and lint failures are due to missing config options. You can add those here:

ttl_opts = [
cfg.IntOpt(
"action_executions_ttl",
default=None,
help="Action executions and related objects (live actions, action output "
"objects) older than this value (days) will be automatically deleted.",
),
cfg.IntOpt(
"action_executions_output_ttl",
default=7,
help="Action execution output objects (ones generated by action output "
"streaming) older than this value (days) will be automatically deleted.",
),
cfg.IntOpt(
"trigger_instances_ttl",
default=None,
help="Trigger instances older than this value (days) will be automatically deleted.",
),
]

Sorry for the duplicate message. I was logged into the wrong github account. I just deleted the other message.

@cognifloyd
Copy link
Member

Also, could you edit your PR description to include Closes: #4939? Thanks!

@cognifloyd
Copy link
Member

@srimandaleeka01 Would you be willing to allow maintainers to edit your PR? If so, I can quickly merge in master and adjust the config options for you.

@arm4b arm4b modified the milestones: 3.6.0, 3.7.0 Oct 5, 2021
@arm4b arm4b added this to In progress in StackStorm v3.7.0 via automation Oct 5, 2021
@arm4b arm4b removed this from In progress in StackStorm v3.7.0 Jan 6, 2022
@arm4b arm4b removed this from the 3.7.0 milestone Jan 6, 2022
@amanda11 amanda11 added this to the 3.7.0 milestone Jan 6, 2022
@amanda11 amanda11 added this to In progress in StackStorm v3.7.0 via automation Jan 6, 2022
the criteria defined in the config.
"""
utc_now = get_datetime_utc_now()
timestamp = (utc_now - datetime.timedelta(days=self._action_executions_ttl))
Copy link
Contributor

Choose a reason for hiding this comment

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

Think this should be _workflow_execution_ttl instead of actions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @amanda11 I will make this change.

the criteria defined in the config.
"""
utc_now = get_datetime_utc_now()
timestamp = (utc_now - datetime.timedelta(days=self._action_executions_ttl))
Copy link
Contributor

Choose a reason for hiding this comment

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

Think this should be _task_execution_ttl instead of actions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Think this should be _task_execution_ttl instead of actions

Thank you @amanda11 will make this change.

@srimandaleeka01
Copy link
Contributor Author

srimandaleeka01 commented Jan 10, 2022

@srimandaleeka01 Would you be willing to allow maintainers to edit your PR? If so, I can quickly merge in master and adjust the config options for you.

@cognifloyd Please go ahead and the maintainers can edit the PR for getting it merged. Thank you!

@amanda11
Copy link
Contributor

@cognifloyd I can update the PR, as I have taken this code made some slight changes and got it installed on a ST2 system. So happy to do update to master and merge those changes in.

@amanda11
Copy link
Contributor

@srimandaleeka01 Could you check if maintainers have access to this PR request, as I'm getting 403 error trying to push.

Please see: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork for info on how to allow maintainers to edit a PR that has been created from a fork.

@srimandaleeka01
Copy link
Contributor Author

srimandaleeka01 commented Jan 21, 2022

@srimandaleeka01 Could you check if maintainers have access to this PR request, as I'm getting 403 error trying to push.

Please see: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork for info on how to allow maintainers to edit a PR that has been created from a fork.

I was following the article above to allow mainters to edit the PR, however I don't see that option.
It's likely that the PR has been created from a Plexxi:st2 ( a fork from master:st2) which is more restrictive ( intentionally ) .

Are there any specific changes apart from the comments you have posted for the PR ? If so please post the diff for the corresponding file , I can manually apply.

Copy link
Contributor

@amanda11 amanda11 left a comment

Choose a reason for hiding this comment

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

Thanks so much for this PR. It will be really great to get this into the next release of StackStorm.

Just some minor other comments I found, in addition to fix the CircleCI then:

  1. Need to run black on the files changed, so that it doesn't break the lint checks
  2. Need to add the change to st2reactor/st2reactor/garbage_collector/config.py as mentioned earlier in review comments to prevent the UT failure to add the new config options.

Can you also update CHANGELOG.rst - to update the "Added" section to include details of this PR?

If need any assistance or want us to help with doing any of the amendments then just please let us know (we'd need the fork updated with permissions for maintainers to edit as I think at moment it's blocked). But if you are happy to do the changes there would be no need.

logger.exception('Deletion of execution models failed for query with filters: %s.',
exec_filters)
else:
logger.info('Deleted %s action execution objects' % deleted_count)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably best to change logger to workflow execution objects not "action execution objects", and other references to action in this method.

logger.exception('Deletion of execution models failed for query with filters: %s.',
exec_filters)
else:
logger.info('Deleted %s action execution objects' % deleted_count)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably best to change logger to task execution objects not "action execution objects", and other references to actiosn or action executions in this method.

@@ -0,0 +1,88 @@
# Copyright 2019 Extreme Networks, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copyright is now StackStorm Authors, and year file first introduced, e.g. could you change to:

Copyright 2021, The StackStorm Authors.

@@ -0,0 +1,88 @@
# Copyright 2019 Extreme Networks, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copyright 2021, The StackStorm Authors.

@@ -0,0 +1,160 @@
# Copyright 2020 Extreme Networks, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copyright 2021, The StackStorm Authors.

@@ -0,0 +1,72 @@
# Copyright 2019 Extreme Networks, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copyright 2021, The StackStorm Authors.

@@ -0,0 +1,72 @@
# Copyright 2019 Extreme Networks, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copyright 2021, The StackStorm Authors.

from datetime import timedelta

from st2common import log as logging
from st2common.constants.triggers import TRIGGER_INSTANCE_PROCESSED
Copy link
Contributor

Choose a reason for hiding this comment

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

The import of TRIGGER_INSTANCE_PROCESSED isn't used, so it breaks the CI checks.

from datetime import timedelta

from st2common import log as logging
from st2common.constants.triggers import TRIGGER_INSTANCE_PROCESSED
Copy link
Contributor

Choose a reason for hiding this comment

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

As TRIGGER_INSTANCE_PROCESSED is unused it will break the CI checks, so can you remove this import.

filters['status'] = {'$in': DONE_STATES}

exec_filters = copy.copy(filters)
# TODO: Are these parameters valid.
Copy link
Contributor

Choose a reason for hiding this comment

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

At the moment the action_ref passed in from the standalone tool, doesn't take affect - as its not used in this class. I don't believe action_ref is valid for WorkflowExecution or TaskExecution, so I would remove the commented out lines and also the action_ref in the cmd/purge_....py classes.

@amanda11
Copy link
Contributor

@srimandaleeka01 Could you check if maintainers have access to this PR request, as I'm getting 403 error trying to push.
Please see: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork for info on how to allow maintainers to edit a PR that has been created from a fork.

I was following the article above to allow mainters to edit the PR, however I don't see that option. It's likely that the PR has been created from a Plexxi:st2 ( a fork from master:st2) which is more restrictive ( intentionally ) .

Are there any specific changes apart from the comments you have posted for the PR ? If so please post the diff for the corresponding file , I can manually apply.

Hi - I've listed in that last review I think all the changes that I was going to make - just a few minor things like copyright, black formatting etc, and then I had a look at the TODO you had left around action_ref, and checked the collection contents - so think safest to remove the action_ref that was in the TODO whether it was relevant or not.
There is also a merge conflict with master - but the instructions to fix that are provided by GIT where it says there are conflicts (it's just that in setup.py on master it has a new binary in its list, so just a small conflict on that to change).

@amanda11
Copy link
Contributor

amanda11 commented Mar 4, 2022

@srimandaleeka01 Are you ok to sign the CLA Contribution Agreement? At the moment it is blocking the PR as the contribution agreement isn't signed.
We really appreciate this fix, and we'd like to get it into the 3.7.0 release, which is targetted for end of March.

Do you have time to address the review comments this month, as we'd like to get this into the 3.7.0 PR. Alternatively, if the contribution agreement is signed, then we could fork off this repo and then merge a PR that way - and ask one of the TSC to make the review comments? Whichever you prefer.

Thanks once again for the contribution.

amanda11 added a commit that referenced this pull request Apr 1, 2022
StackStorm v3.7.0 automation moved this from In progress to Done Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database feature service: workflow engine size/XL PR that changes 500-999 lines. Consider splitting work into several ones that easier to review. status:needs changes workflows: orquesta
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Support purge operations for st2 Workflows and TaskExecution
6 participants