From ab52366e75be36252046def631dc3c85f9800dfc Mon Sep 17 00:00:00 2001 From: Hunter Madison Date: Mon, 20 Sep 2021 07:42:34 -0400 Subject: [PATCH 1/3] Allow customers to disable metrics collection For certain hardened runtimes, collecting metrics can trigger slow paths in the security subsystems in place. By setting `INSTANA_DISABLE_METRICS_COLLECTION` to `TRUE`, a customer can now disable collecting these metrics and avoid the performance impact that the setup causes. --- instana/collector/helpers/runtime.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/instana/collector/helpers/runtime.py b/instana/collector/helpers/runtime.py index 95308b13..17ba8e93 100644 --- a/instana/collector/helpers/runtime.py +++ b/instana/collector/helpers/runtime.py @@ -55,6 +55,9 @@ def collect_metrics(self, with_snapshot=False): return [plugin_data] def _collect_runtime_metrics(self, plugin_data, with_snapshot): + if os.environ.get('INSTANA_DISABLE_METRICS_COLLECTION', False): + return False + """ Collect up and return the runtime metrics """ try: rusage = resource.getrusage(resource.RUSAGE_SELF) From 275cd421077220e3c87837166aacbf97a31a20ed Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Tue, 28 Sep 2021 05:53:08 +0200 Subject: [PATCH 2/3] adding a test case for the environmental variable for disabling the metrics collection --- instana/collector/helpers/runtime.py | 2 +- instana/version.py | 2 +- tests/platforms/test_host_collector.py | 50 +++++++++++++++++++------- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/instana/collector/helpers/runtime.py b/instana/collector/helpers/runtime.py index 17ba8e93..5d9dbf23 100644 --- a/instana/collector/helpers/runtime.py +++ b/instana/collector/helpers/runtime.py @@ -56,7 +56,7 @@ def collect_metrics(self, with_snapshot=False): def _collect_runtime_metrics(self, plugin_data, with_snapshot): if os.environ.get('INSTANA_DISABLE_METRICS_COLLECTION', False): - return False + return """ Collect up and return the runtime metrics """ try: diff --git a/instana/version.py b/instana/version.py index 9c10a8ef..2cd3e564 100644 --- a/instana/version.py +++ b/instana/version.py @@ -3,4 +3,4 @@ # Module version file. Used by setup.py and snapshot reporting. -VERSION = '1.35.2' +VERSION = '1.35.3' diff --git a/tests/platforms/test_host_collector.py b/tests/platforms/test_host_collector.py index 94699f66..639fcd4c 100644 --- a/tests/platforms/test_host_collector.py +++ b/tests/platforms/test_host_collector.py @@ -40,6 +40,8 @@ def tearDown(self): os.environ.pop("INSTANA_ZONE") if "INSTANA_TAGS" in os.environ: os.environ.pop("INSTANA_TAGS") + if "INSTANA_DISABLE_METRICS_COLLECTION" in os.environ: + os.environ.pop("INSTANA_DISABLE_METRICS_COLLECTION") set_agent(self.original_agent) set_tracer(self.original_tracer) @@ -55,17 +57,17 @@ def test_prepare_payload_basics(self): self.create_agent_and_setup_tracer() payload = self.agent.collector.prepare_payload() - assert(payload) - - assert(len(payload.keys()) == 3) - assert('spans' in payload) - assert(isinstance(payload['spans'], list)) - assert(len(payload['spans']) == 0) - assert('metrics' in payload) - assert(len(payload['metrics'].keys()) == 1) - assert('plugins' in payload['metrics']) - assert(isinstance(payload['metrics']['plugins'], list)) - assert(len(payload['metrics']['plugins']) == 1) + assert (payload) + + assert (len(payload.keys()) == 3) + assert ('spans' in payload) + assert (isinstance(payload['spans'], list)) + assert (len(payload['spans']) == 0) + assert ('metrics' in payload) + assert (len(payload['metrics'].keys()) == 1) + assert ('plugins' in payload['metrics']) + assert (isinstance(payload['metrics']['plugins'], list)) + assert (len(payload['metrics']['plugins']) == 1) python_plugin = payload['metrics']['plugins'][0] assert python_plugin['name'] == 'com.instana.plugin.python' @@ -113,7 +115,7 @@ def test_prepare_payload_basics(self): assert type(python_plugin['data']['metrics']['dummy_threads']) in [float, int] assert 'daemon_threads' in python_plugin['data']['metrics'] assert type(python_plugin['data']['metrics']['daemon_threads']) in [float, int] - + assert 'gc' in python_plugin['data']['metrics'] assert isinstance(python_plugin['data']['metrics']['gc'], dict) assert 'collect0' in python_plugin['data']['metrics']['gc'] @@ -128,3 +130,27 @@ def test_prepare_payload_basics(self): assert type(python_plugin['data']['metrics']['gc']['threshold1']) in [float, int] assert 'threshold2' in python_plugin['data']['metrics']['gc'] assert type(python_plugin['data']['metrics']['gc']['threshold2']) in [float, int] + + def test_prepare_payload_basics_disable_runtime_metrics(self): + os.environ["INSTANA_DISABLE_METRICS_COLLECTION"] = "disable" + self.create_agent_and_setup_tracer() + + payload = self.agent.collector.prepare_payload() + assert (payload) + + assert (len(payload.keys()) == 3) + assert ('spans' in payload) + assert (isinstance(payload['spans'], list)) + assert (len(payload['spans']) == 0) + assert ('metrics' in payload) + assert (len(payload['metrics'].keys()) == 1) + assert ('plugins' in payload['metrics']) + assert (isinstance(payload['metrics']['plugins'], list)) + assert (len(payload['metrics']['plugins']) == 1) + + python_plugin = payload['metrics']['plugins'][0] + assert python_plugin['name'] == 'com.instana.plugin.python' + assert python_plugin['entityId'] == str(os.getpid()) + assert 'data' in python_plugin + assert 'snapshot' in python_plugin['data'] + assert 'metrics' not in python_plugin['data'] From 4e22eddf3f1fbe46a59c1768a29480e0ed615630 Mon Sep 17 00:00:00 2001 From: dimitraparaskevopoulou Date: Tue, 28 Sep 2021 06:10:28 +0200 Subject: [PATCH 3/3] adding a test case for the environmental variable for disabling the metrics collection --- tests/platforms/test_host_collector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/platforms/test_host_collector.py b/tests/platforms/test_host_collector.py index 639fcd4c..c788695e 100644 --- a/tests/platforms/test_host_collector.py +++ b/tests/platforms/test_host_collector.py @@ -132,7 +132,7 @@ def test_prepare_payload_basics(self): assert type(python_plugin['data']['metrics']['gc']['threshold2']) in [float, int] def test_prepare_payload_basics_disable_runtime_metrics(self): - os.environ["INSTANA_DISABLE_METRICS_COLLECTION"] = "disable" + os.environ["INSTANA_DISABLE_METRICS_COLLECTION"] = "TRUE" self.create_agent_and_setup_tracer() payload = self.agent.collector.prepare_payload()