From 1c1af4128f125241b31ab74be62336bcb7d1b8aa Mon Sep 17 00:00:00 2001 From: saucetray Date: Tue, 30 Jun 2020 12:10:14 -0400 Subject: [PATCH 01/17] Fixed traceback on st2api.log when datastore value does not exist. --- st2common/st2common/persistence/keyvalue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/persistence/keyvalue.py b/st2common/st2common/persistence/keyvalue.py index e1108e39af..a7c1800d13 100644 --- a/st2common/st2common/persistence/keyvalue.py +++ b/st2common/st2common/persistence/keyvalue.py @@ -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) + LOG.error(msg % name) return query_result.first() if query_result else None From 7e561771df41bbf17a547ca5729c35aee982a931 Mon Sep 17 00:00:00 2001 From: saucetray Date: Tue, 30 Jun 2020 12:13:42 -0400 Subject: [PATCH 02/17] Added changes to CHANGELOG.rst --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 474ce77cc8..82334d3008 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,11 @@ Added Fixed ~~~~~ +* Fixed a bug where ST2api.log reports the entire traceback when trying to get a datastore value + that does not exist. Fixes #4979 + + Contributed by Justin Sostre (@saucetray) + * Fixed a bug where `type` attribute was missing for netstat action in linux pack. Fixes #4946 Reported by @scguoi and contributed by Sheshagiri (@sheshagiri) From 5ccffeef16ad73470a916630302542d6c9b0db88 Mon Sep 17 00:00:00 2001 From: saucetray Date: Wed, 1 Jul 2020 11:00:30 -0400 Subject: [PATCH 03/17] Added a specific catch for DB Object Not Found. --- st2common/st2common/persistence/keyvalue.py | 2 +- st2common/st2common/router.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/st2common/st2common/persistence/keyvalue.py b/st2common/st2common/persistence/keyvalue.py index a7c1800d13..e1108e39af 100644 --- a/st2common/st2common/persistence/keyvalue.py +++ b/st2common/st2common/persistence/keyvalue.py @@ -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.' - LOG.error(msg % name) + raise StackStormDBObjectNotFoundError(msg % name) return query_result.first() if query_result else None diff --git a/st2common/st2common/router.py b/st2common/st2common/router.py index 83b4c12362..6b003e9729 100644 --- a/st2common/st2common/router.py +++ b/st2common/st2common/router.py @@ -32,6 +32,7 @@ from st2common.exceptions import rbac as rbac_exc from st2common.exceptions import auth as auth_exc +from st2common.exceptions.db import StackStormDBObjectNotFoundError from st2common import log as logging from st2common.persistence.auth import User from st2common.rbac.backends import get_rbac_backend @@ -513,6 +514,9 @@ def __init__(self, **entries): try: resp = func(**kw) + except StackStormDBObjectNotFoundError as e: + LOG.error(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))) From 62fad9984c772a9d9269478c9742ced5c4d19bb8 Mon Sep 17 00:00:00 2001 From: saucetray Date: Wed, 1 Jul 2020 11:52:19 -0400 Subject: [PATCH 04/17] Returned the original message in the log. --- st2common/st2common/router.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/st2common/st2common/router.py b/st2common/st2common/router.py index 6b003e9729..260a55cb5e 100644 --- a/st2common/st2common/router.py +++ b/st2common/st2common/router.py @@ -515,7 +515,8 @@ def __init__(self, **entries): try: resp = func(**kw) except StackStormDBObjectNotFoundError as e: - LOG.error(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' % From cdabd02204ccc286d89629d87664330dc02f6e00 Mon Sep 17 00:00:00 2001 From: saucetray Date: Wed, 1 Jul 2020 11:53:20 -0400 Subject: [PATCH 05/17] Added the exception message to the log. --- st2common/st2common/router.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/st2common/st2common/router.py b/st2common/st2common/router.py index 260a55cb5e..c959a1ac9a 100644 --- a/st2common/st2common/router.py +++ b/st2common/st2common/router.py @@ -515,8 +515,8 @@ def __init__(self, **entries): try: resp = func(**kw) except StackStormDBObjectNotFoundError as e: - LOG.warning('Failed to call controller function "%s" for operation "%s": %s' % - (func.__name__, endpoint['operationId'], six.text_type(e)))) + LOG.warning('Failed to call controller function "%s" for operation "%s": %s, %s' % + (func.__name__, endpoint['operationId'], six.text_type(e), str(e))) raise e except Exception as e: LOG.exception('Failed to call controller function "%s" for operation "%s": %s' % From fbac366ff2b3f4be592204eb5a8730c3d0cccbec Mon Sep 17 00:00:00 2001 From: saucetray Date: Thu, 2 Jul 2020 12:26:45 -0400 Subject: [PATCH 06/17] Added new exception StackStormDBKeyNotFoundError. --- st2common/st2common/exceptions/db.py | 4 ++++ st2common/st2common/middleware/error_handling.py | 3 ++- st2common/st2common/persistence/keyvalue.py | 4 ++-- st2common/st2common/router.py | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/st2common/st2common/exceptions/db.py b/st2common/st2common/exceptions/db.py index 6b4b779796..381ad1a5ed 100644 --- a/st2common/st2common/exceptions/db.py +++ b/st2common/st2common/exceptions/db.py @@ -16,6 +16,10 @@ from st2common.exceptions import StackStormBaseException +class StackStormDBKeyNotFoundError(StackStormBaseException): + pass + + class StackStormDBObjectNotFoundError(StackStormBaseException): pass diff --git a/st2common/st2common/middleware/error_handling.py b/st2common/st2common/middleware/error_handling.py index 3b00c37865..cb73f8565a 100644 --- a/st2common/st2common/middleware/error_handling.py +++ b/st2common/st2common/middleware/error_handling.py @@ -62,7 +62,8 @@ def __call__(self, environ, start_response): if isinstance(e, exc.HTTPException): status_code = status message = six.text_type(e) - elif isinstance(e, db_exceptions.StackStormDBObjectNotFoundError): + elif isinstance(e, db_exceptions.StackStormDBObjectNotFoundError) or + isinstance(e, db_exceptions.StackStormDBKeyNotFoundError): status_code = exc.HTTPNotFound.code message = six.text_type(e) elif isinstance(e, db_exceptions.StackStormDBObjectConflictError): diff --git a/st2common/st2common/persistence/keyvalue.py b/st2common/st2common/persistence/keyvalue.py index e1108e39af..c8009d6f59 100644 --- a/st2common/st2common/persistence/keyvalue.py +++ b/st2common/st2common/persistence/keyvalue.py @@ -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.db import StackStormDBKeyNotFoundError from st2common.models.api.keyvalue import KeyValuePairAPI from st2common.models.db.keyvalue import keyvaluepair_access from st2common.models.system.common import ResourceReference @@ -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 StackStormDBKeyNotFoundError(msg % name) return query_result.first() if query_result else None diff --git a/st2common/st2common/router.py b/st2common/st2common/router.py index c959a1ac9a..20c06afd95 100644 --- a/st2common/st2common/router.py +++ b/st2common/st2common/router.py @@ -32,7 +32,7 @@ from st2common.exceptions import rbac as rbac_exc from st2common.exceptions import auth as auth_exc -from st2common.exceptions.db import StackStormDBObjectNotFoundError +from st2common.exceptions.db import StackStormDBKeyNotFoundError from st2common import log as logging from st2common.persistence.auth import User from st2common.rbac.backends import get_rbac_backend @@ -514,7 +514,7 @@ def __init__(self, **entries): try: resp = func(**kw) - except StackStormDBObjectNotFoundError as e: + except StackStormDBKeyNotFoundError as e: LOG.warning('Failed to call controller function "%s" for operation "%s": %s, %s' % (func.__name__, endpoint['operationId'], six.text_type(e), str(e))) raise e From 7bea2498a68f47d23cb9d3906e308ea3addea43b Mon Sep 17 00:00:00 2001 From: saucetray Date: Thu, 2 Jul 2020 12:44:37 -0400 Subject: [PATCH 07/17] Fixing syntax error on error_handling.py --- st2common/st2common/middleware/error_handling.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/st2common/st2common/middleware/error_handling.py b/st2common/st2common/middleware/error_handling.py index cb73f8565a..cafe5d5724 100644 --- a/st2common/st2common/middleware/error_handling.py +++ b/st2common/st2common/middleware/error_handling.py @@ -62,8 +62,7 @@ def __call__(self, environ, start_response): if isinstance(e, exc.HTTPException): status_code = status message = six.text_type(e) - elif isinstance(e, db_exceptions.StackStormDBObjectNotFoundError) or - isinstance(e, db_exceptions.StackStormDBKeyNotFoundError): + elif isinstance(e, db_exceptions.StackStormDBObjectNotFoundError) or isinstance(e, db_exceptions.StackStormDBKeyNotFoundError): status_code = exc.HTTPNotFound.code message = six.text_type(e) elif isinstance(e, db_exceptions.StackStormDBObjectConflictError): From eb3d234212e0c0376e8726d5329666507501eee5 Mon Sep 17 00:00:00 2001 From: saucetray Date: Wed, 29 Jul 2020 09:00:19 -0400 Subject: [PATCH 08/17] Added new exception to keyvalue.py --- st2common/st2common/exceptions/keyvalue.py | 5 +++++ st2common/st2common/router.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/st2common/st2common/exceptions/keyvalue.py b/st2common/st2common/exceptions/keyvalue.py index aef134c600..c2aafde07f 100644 --- a/st2common/st2common/exceptions/keyvalue.py +++ b/st2common/st2common/exceptions/keyvalue.py @@ -14,9 +14,11 @@ from __future__ import absolute_import from st2common.exceptions import StackStormBaseException +from st2common.exceptions.db import StackStormDBObjectNotFoundError __all__ = [ 'CryptoKeyNotSetupException', + 'DataStoreKeyNotFoundError', 'InvalidScopeException' ] @@ -25,6 +27,9 @@ class CryptoKeyNotSetupException(StackStormBaseException): pass +class DataStoreKeyNotFoundError(StackStormDBObjectNotFoundError): + pass + class InvalidScopeException(StackStormBaseException): pass diff --git a/st2common/st2common/router.py b/st2common/st2common/router.py index 20c06afd95..317007fe7e 100644 --- a/st2common/st2common/router.py +++ b/st2common/st2common/router.py @@ -32,7 +32,7 @@ from st2common.exceptions import rbac as rbac_exc from st2common.exceptions import auth as auth_exc -from st2common.exceptions.db import StackStormDBKeyNotFoundError +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 @@ -514,7 +514,7 @@ def __init__(self, **entries): try: resp = func(**kw) - except StackStormDBKeyNotFoundError as e: + except DataStoreKeyNotFoundError as e: LOG.warning('Failed to call controller function "%s" for operation "%s": %s, %s' % (func.__name__, endpoint['operationId'], six.text_type(e), str(e))) raise e From 750ea4182f8340181e2b13c375f7db165315f324 Mon Sep 17 00:00:00 2001 From: saucetray Date: Fri, 31 Jul 2020 08:35:04 -0400 Subject: [PATCH 09/17] Addressed unit test issues and extra code waste. --- st2common/st2common/exceptions/db.py | 4 ---- st2common/st2common/middleware/error_handling.py | 2 +- st2common/st2common/persistence/keyvalue.py | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/st2common/st2common/exceptions/db.py b/st2common/st2common/exceptions/db.py index 381ad1a5ed..6b4b779796 100644 --- a/st2common/st2common/exceptions/db.py +++ b/st2common/st2common/exceptions/db.py @@ -16,10 +16,6 @@ from st2common.exceptions import StackStormBaseException -class StackStormDBKeyNotFoundError(StackStormBaseException): - pass - - class StackStormDBObjectNotFoundError(StackStormBaseException): pass diff --git a/st2common/st2common/middleware/error_handling.py b/st2common/st2common/middleware/error_handling.py index cafe5d5724..c997515daf 100644 --- a/st2common/st2common/middleware/error_handling.py +++ b/st2common/st2common/middleware/error_handling.py @@ -62,7 +62,7 @@ def __call__(self, environ, start_response): if isinstance(e, exc.HTTPException): status_code = status message = six.text_type(e) - elif isinstance(e, db_exceptions.StackStormDBObjectNotFoundError) or isinstance(e, db_exceptions.StackStormDBKeyNotFoundError): + elif isinstance(e, db_exceptions.StackStormDBObjectNotFoundError) status_code = exc.HTTPNotFound.code message = six.text_type(e) elif isinstance(e, db_exceptions.StackStormDBObjectConflictError): diff --git a/st2common/st2common/persistence/keyvalue.py b/st2common/st2common/persistence/keyvalue.py index c8009d6f59..65619e7129 100644 --- a/st2common/st2common/persistence/keyvalue.py +++ b/st2common/st2common/persistence/keyvalue.py @@ -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 StackStormDBKeyNotFoundError +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 @@ -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 StackStormDBKeyNotFoundError(msg % name) + raise DataStoreKeyNotFoundError(msg % name) return query_result.first() if query_result else None From ef1ac22650d31dc7db4132c90e056a108c713bb4 Mon Sep 17 00:00:00 2001 From: saucetray Date: Fri, 31 Jul 2020 10:02:27 -0400 Subject: [PATCH 10/17] fixed colon for tests. --- st2common/st2common/middleware/error_handling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/middleware/error_handling.py b/st2common/st2common/middleware/error_handling.py index c997515daf..3b00c37865 100644 --- a/st2common/st2common/middleware/error_handling.py +++ b/st2common/st2common/middleware/error_handling.py @@ -62,7 +62,7 @@ def __call__(self, environ, start_response): if isinstance(e, exc.HTTPException): status_code = status message = six.text_type(e) - elif isinstance(e, db_exceptions.StackStormDBObjectNotFoundError) + elif isinstance(e, db_exceptions.StackStormDBObjectNotFoundError): status_code = exc.HTTPNotFound.code message = six.text_type(e) elif isinstance(e, db_exceptions.StackStormDBObjectConflictError): From 25e28dec04338d91725ac9852fd4be683d166563 Mon Sep 17 00:00:00 2001 From: saucetray Date: Fri, 31 Jul 2020 10:25:52 -0400 Subject: [PATCH 11/17] Addresses linting. --- st2common/st2common/exceptions/keyvalue.py | 1 + 1 file changed, 1 insertion(+) diff --git a/st2common/st2common/exceptions/keyvalue.py b/st2common/st2common/exceptions/keyvalue.py index c2aafde07f..185a5c606e 100644 --- a/st2common/st2common/exceptions/keyvalue.py +++ b/st2common/st2common/exceptions/keyvalue.py @@ -30,6 +30,7 @@ class CryptoKeyNotSetupException(StackStormBaseException): class DataStoreKeyNotFoundError(StackStormDBObjectNotFoundError): pass + class InvalidScopeException(StackStormBaseException): pass From 95a2dba066605e552f06a3ca7f746502d1d9d23f Mon Sep 17 00:00:00 2001 From: saucetray Date: Fri, 31 Jul 2020 10:52:03 -0400 Subject: [PATCH 12/17] Changed changelog. --- CHANGELOG.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 68d605da4e..4b46c55515 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -22,13 +22,13 @@ 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 + +Contributed by Justin Sostre (@saucetray) + Fixed ~~~~~ -* Fixed a bug where ST2api.log reports the entire traceback when trying to get a datastore value - that does not exist. Fixes #4979 - - Contributed by Justin Sostre (@saucetray) - * Fixed a bug where `type` attribute was missing for netstat action in linux pack. Fixes #4946 Reported by @scguoi and contributed by Sheshagiri (@sheshagiri) From ef2455ae96fe2b55c582f8829b8ff0cc075fc2bf Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 31 Jul 2020 12:52:29 -0400 Subject: [PATCH 13/17] Update CHANGELOG.rst Co-authored-by: Eugen C. --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4b46c55515..cccbab7898 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -23,7 +23,7 @@ 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 + that does not exist. It now reports a simplified log for cleaner reading. Addresses and Fixes #4979. (improvement) #4981 Contributed by Justin Sostre (@saucetray) From a11bf5def15f72f7a98f0ef0a98d072f105ecc76 Mon Sep 17 00:00:00 2001 From: saucetray Date: Wed, 5 Aug 2020 12:11:32 -0400 Subject: [PATCH 14/17] Removed extra line of log. --- st2common/st2common/router.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/router.py b/st2common/st2common/router.py index 317007fe7e..c86af6c636 100644 --- a/st2common/st2common/router.py +++ b/st2common/st2common/router.py @@ -516,7 +516,7 @@ def __init__(self, **entries): resp = func(**kw) except DataStoreKeyNotFoundError as e: LOG.warning('Failed to call controller function "%s" for operation "%s": %s, %s' % - (func.__name__, endpoint['operationId'], six.text_type(e), str(e))) + (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' % From 8c1d1bba82a19f2e7f92c1b6f0642a3df597ea98 Mon Sep 17 00:00:00 2001 From: saucetray Date: Thu, 6 Aug 2020 10:46:53 -0400 Subject: [PATCH 15/17] fix --- st2common/st2common/router.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/st2common/router.py b/st2common/st2common/router.py index c86af6c636..71afc2dc7c 100644 --- a/st2common/st2common/router.py +++ b/st2common/st2common/router.py @@ -515,7 +515,7 @@ def __init__(self, **entries): try: resp = func(**kw) except DataStoreKeyNotFoundError as e: - LOG.warning('Failed to call controller function "%s" for operation "%s": %s, %s' % + 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: From 61ef00c70b8ccef4b92d4fa697547dd96176b498 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 6 Aug 2020 19:29:44 -0400 Subject: [PATCH 16/17] Update CHANGELOG.rst --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 27d75b82eb..d798c5f406 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -28,7 +28,7 @@ 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 +that does not exist. It now reports a simplified log for cleaner reading. Addresses and Fixes #4979. (improvement) #4981 Contributed by Justin Sostre (@saucetray) From 38e05d5fce3691f1b22b2f9b7bd34fbb6ab387f9 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 10 Aug 2020 09:55:22 -0400 Subject: [PATCH 17/17] Update CHANGELOG.rst Co-authored-by: blag --- CHANGELOG.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d798c5f406..cdb2b5e4ef 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -28,9 +28,9 @@ 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 + that does not exist. It now reports a simplified log for cleaner reading. Addresses and Fixes #4979. (improvement) #4981 -Contributed by Justin Sostre (@saucetray) + Contributed by Justin Sostre (@saucetray) Fixed ~~~~~