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

ST2api Log Fix So That Querying a Non-Existent Key in the Datastore Will Not Print Traceback #4981

Merged
merged 22 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Changed

Contributed by @punkrokk

* Added an enhancement where ST2api.log no longer reports the entire traceback when trying to get a datastore value
that does not exist. It now reports a simplified log for cleaner reading. Addresses and Fixes #4979. (improvement) #4981

Contributed by Justin Sostre (@saucetray)

Fixed
~~~~~
* Fixed a bug where `type` attribute was missing for netstat action in linux pack. Fixes #4946
Expand Down
6 changes: 6 additions & 0 deletions st2common/st2common/exceptions/keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

from __future__ import absolute_import
from st2common.exceptions import StackStormBaseException
from st2common.exceptions.db import StackStormDBObjectNotFoundError

__all__ = [
'CryptoKeyNotSetupException',
'DataStoreKeyNotFoundError',
'InvalidScopeException'
]

Expand All @@ -25,6 +27,10 @@ class CryptoKeyNotSetupException(StackStormBaseException):
pass


class DataStoreKeyNotFoundError(StackStormDBObjectNotFoundError):
saucetray marked this conversation as resolved.
Show resolved Hide resolved
pass


class InvalidScopeException(StackStormBaseException):
pass

Expand Down
4 changes: 2 additions & 2 deletions st2common/st2common/persistence/keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from st2common.constants.triggers import KEY_VALUE_PAIR_UPDATE_TRIGGER
from st2common.constants.triggers import KEY_VALUE_PAIR_VALUE_CHANGE_TRIGGER
from st2common.constants.triggers import KEY_VALUE_PAIR_DELETE_TRIGGER
from st2common.exceptions.db import StackStormDBObjectNotFoundError
from st2common.exceptions.keyvalue import DataStoreKeyNotFoundError
from st2common.models.api.keyvalue import KeyValuePairAPI
from st2common.models.db.keyvalue import keyvaluepair_access
from st2common.models.system.common import ResourceReference
Expand Down Expand Up @@ -112,7 +112,7 @@ def get_by_scope_and_name(cls, scope, name):

if not query_result:
msg = 'The key "%s" does not exist in the StackStorm datastore.'
raise StackStormDBObjectNotFoundError(msg % name)
raise DataStoreKeyNotFoundError(msg % name)

return query_result.first() if query_result else None

Expand Down
5 changes: 5 additions & 0 deletions st2common/st2common/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

from st2common.exceptions import rbac as rbac_exc
from st2common.exceptions import auth as auth_exc
from st2common.exceptions.keyvalue import DataStoreKeyNotFoundError
from st2common import log as logging
from st2common.persistence.auth import User
from st2common.rbac.backends import get_rbac_backend
Expand Down Expand Up @@ -513,6 +514,10 @@ def __init__(self, **entries):

try:
resp = func(**kw)
except DataStoreKeyNotFoundError as e:
LOG.warning('Failed to call controller function "%s" for operation "%s": %s' %
(func.__name__, endpoint['operationId'], six.text_type(e)))
raise e
except Exception as e:
LOG.exception('Failed to call controller function "%s" for operation "%s": %s' %
(func.__name__, endpoint['operationId'], six.text_type(e)))
Expand Down