Skip to content

Commit 1844a2c

Browse files
hmadisonpdimitra
andauthored
Allow customers to disable metrics collection (#336)
* 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. * adding a test case for the environmental variable for disabling the metrics collection Co-authored-by: dimitraparaskevopoulou <[email protected]>
1 parent 7325afb commit 1844a2c

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

instana/collector/helpers/runtime.py

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ def collect_metrics(self, with_snapshot=False):
5555
return [plugin_data]
5656

5757
def _collect_runtime_metrics(self, plugin_data, with_snapshot):
58+
if os.environ.get('INSTANA_DISABLE_METRICS_COLLECTION', False):
59+
return
60+
5861
""" Collect up and return the runtime metrics """
5962
try:
6063
rusage = resource.getrusage(resource.RUSAGE_SELF)

instana/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
# Module version file. Used by setup.py and snapshot reporting.
55

6-
VERSION = '1.35.2'
6+
VERSION = '1.35.3'

tests/platforms/test_host_collector.py

+38-12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def tearDown(self):
4040
os.environ.pop("INSTANA_ZONE")
4141
if "INSTANA_TAGS" in os.environ:
4242
os.environ.pop("INSTANA_TAGS")
43+
if "INSTANA_DISABLE_METRICS_COLLECTION" in os.environ:
44+
os.environ.pop("INSTANA_DISABLE_METRICS_COLLECTION")
4345

4446
set_agent(self.original_agent)
4547
set_tracer(self.original_tracer)
@@ -55,17 +57,17 @@ def test_prepare_payload_basics(self):
5557
self.create_agent_and_setup_tracer()
5658

5759
payload = self.agent.collector.prepare_payload()
58-
assert(payload)
59-
60-
assert(len(payload.keys()) == 3)
61-
assert('spans' in payload)
62-
assert(isinstance(payload['spans'], list))
63-
assert(len(payload['spans']) == 0)
64-
assert('metrics' in payload)
65-
assert(len(payload['metrics'].keys()) == 1)
66-
assert('plugins' in payload['metrics'])
67-
assert(isinstance(payload['metrics']['plugins'], list))
68-
assert(len(payload['metrics']['plugins']) == 1)
60+
assert (payload)
61+
62+
assert (len(payload.keys()) == 3)
63+
assert ('spans' in payload)
64+
assert (isinstance(payload['spans'], list))
65+
assert (len(payload['spans']) == 0)
66+
assert ('metrics' in payload)
67+
assert (len(payload['metrics'].keys()) == 1)
68+
assert ('plugins' in payload['metrics'])
69+
assert (isinstance(payload['metrics']['plugins'], list))
70+
assert (len(payload['metrics']['plugins']) == 1)
6971

7072
python_plugin = payload['metrics']['plugins'][0]
7173
assert python_plugin['name'] == 'com.instana.plugin.python'
@@ -113,7 +115,7 @@ def test_prepare_payload_basics(self):
113115
assert type(python_plugin['data']['metrics']['dummy_threads']) in [float, int]
114116
assert 'daemon_threads' in python_plugin['data']['metrics']
115117
assert type(python_plugin['data']['metrics']['daemon_threads']) in [float, int]
116-
118+
117119
assert 'gc' in python_plugin['data']['metrics']
118120
assert isinstance(python_plugin['data']['metrics']['gc'], dict)
119121
assert 'collect0' in python_plugin['data']['metrics']['gc']
@@ -128,3 +130,27 @@ def test_prepare_payload_basics(self):
128130
assert type(python_plugin['data']['metrics']['gc']['threshold1']) in [float, int]
129131
assert 'threshold2' in python_plugin['data']['metrics']['gc']
130132
assert type(python_plugin['data']['metrics']['gc']['threshold2']) in [float, int]
133+
134+
def test_prepare_payload_basics_disable_runtime_metrics(self):
135+
os.environ["INSTANA_DISABLE_METRICS_COLLECTION"] = "TRUE"
136+
self.create_agent_and_setup_tracer()
137+
138+
payload = self.agent.collector.prepare_payload()
139+
assert (payload)
140+
141+
assert (len(payload.keys()) == 3)
142+
assert ('spans' in payload)
143+
assert (isinstance(payload['spans'], list))
144+
assert (len(payload['spans']) == 0)
145+
assert ('metrics' in payload)
146+
assert (len(payload['metrics'].keys()) == 1)
147+
assert ('plugins' in payload['metrics'])
148+
assert (isinstance(payload['metrics']['plugins'], list))
149+
assert (len(payload['metrics']['plugins']) == 1)
150+
151+
python_plugin = payload['metrics']['plugins'][0]
152+
assert python_plugin['name'] == 'com.instana.plugin.python'
153+
assert python_plugin['entityId'] == str(os.getpid())
154+
assert 'data' in python_plugin
155+
assert 'snapshot' in python_plugin['data']
156+
assert 'metrics' not in python_plugin['data']

0 commit comments

Comments
 (0)