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

Let querier plugin decide to delete state object on error #3182

Merged
merged 4 commits into from Feb 7, 2017

Conversation

m4dcoder
Copy link
Contributor

@m4dcoder m4dcoder commented Feb 3, 2017

Add option in querier plugin to specify whether state object should be deleted if an error occur during query. This allows querier to recover in case of unexpected environment related exceptions. Mistral querier is refactored to delete state object on workflow completion or when the workflow or task references no longer exists.

@codecov-io
Copy link

codecov-io commented Feb 3, 2017

Codecov Report

Merging #3182 into master will increase coverage by <.01%.

@@            Coverage Diff             @@
##           master    #3182      +/-   ##
==========================================
+ Coverage   77.56%   77.56%   +<.01%     
==========================================
  Files         432      433       +1     
  Lines       22318    22323       +5     
==========================================
+ Hits        17309    17313       +4     
- Misses       5009     5010       +1
Impacted Files Coverage Δ
st2common/st2common/exceptions/resultstracker.py 100% <100%> (ø)
st2common/st2common/query/base.py 84.21% <70%> (+11.69%)
st2api/st2api/controllers/v1/triggers.py 70.94% <ø> (-6.4%)
st2exporter/st2exporter/worker.py 58.82% <ø> (-4.71%)
st2common/st2common/bootstrap/rulesregistrar.py 75.22% <ø> (-3.54%)
st2common/st2common/rbac/decorators.py 84.38% <ø> (-3.13%)
st2common/st2common/triggers.py 74.42% <ø> (-2.33%)
st2common/st2common/transport/consumers.py 87.37% <ø> (-2.11%)
st2common/st2common/rbac/utils.py 92.25% <ø> (-1.41%)
st2common/st2common/services/action.py 94.17% <ø> (-0.97%)
... and 11 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 bba27a9...6630a08. Read the comment docs.

@Kami
Copy link
Member

Kami commented Feb 6, 2017

From high level - LGTM.

Looking at the code, it doesn't seem to be a way for user / operator to enable this option for Mistral since it's disabled by default. Or am I missing something?

Edit: Ignore last part of my comment. It seems like this option is in addition to deleting on completion, etc. - https://github.com/StackStorm/st2/pull/3182/files#diff-5d34721fd4bff559a18008d8c41031ccR121

execution = self._client.executions.get(exec_id)
except mistralclient_base.APIException as mistral_exc:
if 'not found' in mistral_exc.message:
raise exceptions.ReferenceNotFoundError(mistral_exc.message)
Copy link
Member

Choose a reason for hiding this comment

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

👍

for task in self._client.tasks.list(workflow_execution_id=exec_id)
]
try:
wf_tasks = [
Copy link
Member

Choose a reason for hiding this comment

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

I would personally prefer to make this a regular for loop, because list comprehensions are usually only intended to be used for simple transformations and in cases like that when you have exception handling, etc. regular for loop is more clear and obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure can change to a for loop

if 'not found' in mistral_exc.message:
raise exceptions.ReferenceNotFoundError(mistral_exc.message)
raise mistral_exc
except Exception:
Copy link
Member

Choose a reason for hiding this comment

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

This is redundant since we are not doing any handling of the exception here so it can be removed.

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 it still raise any general exception if I remove it?

if 'not found' in mistral_exc.message:
raise exceptions.ReferenceNotFoundError(mistral_exc.message)
raise mistral_exc
except Exception:
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

tracker.shutdown()

# Ensure state objects are deleted
self.assertRaises(
Copy link
Member

Choose a reason for hiding this comment

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

Should we also verify somewhere at the top that this object actually exists in the database in the first place?

@m4dcoder
Copy link
Contributor Author

m4dcoder commented Feb 6, 2017

It's not an option for the user/operator. It's a querier plugin level option.

Add option in querier plugin to specify whether state object should be deleted if an error occur during query. This allows querier to recover in case of unexpected environment related exceptions. Mistral querier is refactored to delete state object on workflow completion or when the workflow or task references no longer exists.
Refactor mistral querier get tasks function to use a for loop instead of a list comprehension.
Add checks in the querier unit tests to ensure state objects are in the database before tests start.
@m4dcoder
Copy link
Contributor Author

m4dcoder commented Feb 6, 2017

@Kami concerns/comments addressed.

Copy link
Member

@Kami Kami left a comment

Choose a reason for hiding this comment

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

LGTM

@m4dcoder m4dcoder merged commit 200efeb into master Feb 7, 2017
@m4dcoder m4dcoder deleted the robust-mistral-querier branch February 7, 2017 20:48
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.

None yet

3 participants