From 86ad1c390ab1a3918f08d874797edc3c516d7938 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Thu, 24 Jan 2019 19:07:10 +0100 Subject: [PATCH 1/3] Update code so we don't submit metrics for any "get one" API endpoints since this can potentially result in too many unique metrics. --- st2common/st2common/middleware/instrumentation.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/st2common/st2common/middleware/instrumentation.py b/st2common/st2common/middleware/instrumentation.py index ea03b72df1..0523ceb3eb 100644 --- a/st2common/st2common/middleware/instrumentation.py +++ b/st2common/st2common/middleware/instrumentation.py @@ -55,7 +55,15 @@ def __call__(self, environ, start_response): # other endpoints because this would result in a lot of unique metrics which is an # anti-pattern and causes unnecessary load on the metrics server. submit_metrics = endpoint.get('x-submit-metrics', True) - if not submit_metrics: + operation_id = endpoint.get('operationId', None) + is_get_one_endpoint = (operation_id.endswith('.get') or operation_id.endswith('.get_one')) + + if is_get_one_endpoint: + # NOTE: We don't submit metrics for any get one API endpoint since this would result + # in potentially too many unique metrics + submit_metrics = False + + if not submit_metrics or (): LOG.debug('Not submitting request metrics for path: %s' % (request.path)) return self.app(environ, start_response) From 8a954dfe1cb5cb572b8f4e9bddbdf1d471e393f4 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Thu, 24 Jan 2019 19:39:51 +0100 Subject: [PATCH 2/3] Make the if check more robust. --- st2common/st2common/middleware/instrumentation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/st2common/st2common/middleware/instrumentation.py b/st2common/st2common/middleware/instrumentation.py index 0523ceb3eb..3906d7c13d 100644 --- a/st2common/st2common/middleware/instrumentation.py +++ b/st2common/st2common/middleware/instrumentation.py @@ -56,14 +56,15 @@ def __call__(self, environ, start_response): # anti-pattern and causes unnecessary load on the metrics server. submit_metrics = endpoint.get('x-submit-metrics', True) operation_id = endpoint.get('operationId', None) - is_get_one_endpoint = (operation_id.endswith('.get') or operation_id.endswith('.get_one')) + is_get_one_endpoint = bool(operation_id) and (operation_id.endswith('.get') or + operation_id.endswith('.get_one')) if is_get_one_endpoint: # NOTE: We don't submit metrics for any get one API endpoint since this would result # in potentially too many unique metrics submit_metrics = False - if not submit_metrics or (): + if not submit_metrics: LOG.debug('Not submitting request metrics for path: %s' % (request.path)) return self.app(environ, start_response) From cc12871c20c087cd8bdb92c9c7a65ac6a18b49e8 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Thu, 24 Jan 2019 19:46:23 +0100 Subject: [PATCH 3/3] Fix assert in get_sandbox_python_path. Make sure it also works correctly when sys.prefix is relative (e.g. when calling ./tools/launchdev.sh script outside of tools directory or similar). --- st2common/st2common/util/sandboxing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/st2common/st2common/util/sandboxing.py b/st2common/st2common/util/sandboxing.py index d5ceb109a6..321d4f0250 100644 --- a/st2common/st2common/util/sandboxing.py +++ b/st2common/st2common/util/sandboxing.py @@ -117,7 +117,10 @@ def get_sandbox_python_path(inherit_from_parent=True, inherit_parent_virtualenv= if inherit_parent_virtualenv and hasattr(sys, 'real_prefix'): # We are running inside virtualenv site_packages_dir = get_python_lib() - assert sys.prefix in site_packages_dir + + sys_prefix = os.path.abspath(sys.prefix) + assert sys_prefix in site_packages_dir + sandbox_python_path.append(site_packages_dir) sandbox_python_path = ':'.join(sandbox_python_path)