Skip to content

Commit

Permalink
Allow customers to disable metrics collection (#336)
Browse files Browse the repository at this point in the history
* 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 <dimitra.paraskevopoulou@instana.com>
  • Loading branch information
hmadison and pdimitra authored Sep 28, 2021
1 parent 7325afb commit 1844a2c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
3 changes: 3 additions & 0 deletions instana/collector/helpers/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

""" Collect up and return the runtime metrics """
try:
rusage = resource.getrusage(resource.RUSAGE_SELF)
Expand Down
2 changes: 1 addition & 1 deletion instana/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

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

VERSION = '1.35.2'
VERSION = '1.35.3'
50 changes: 38 additions & 12 deletions tests/platforms/test_host_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'
Expand Down Expand Up @@ -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']
Expand All @@ -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"] = "TRUE"
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']

0 comments on commit 1844a2c

Please sign in to comment.