Skip to content

Commit

Permalink
Fixes #1669: restore router memory statistics (#1671)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgiusti authored Nov 19, 2024
1 parent 2dfa2a4 commit 77ecd45
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
12 changes: 8 additions & 4 deletions tests/system_tests_skmanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,16 +625,20 @@ def test_check_memory_usage(self):
query_command = f'QUERY --type={ROUTER_METRICS_TYPE}'
output = json.loads(self.run_skmanage(query_command))
self.assertEqual(len(output), 1)
mem = output[0].get('memoryUsage')
vmsize = output[0].get('memoryUsage')
rss = output[0].get('residentMemoryUsage')

if sys.platform.lower().startswith('linux'):
# @TODO(kgiusti) - linux only for now
self.assertIsNotNone(mem)
self.assertGreaterEqual(mem, 0)
self.assertIsNotNone(vmsize)
self.assertIsNotNone(rss)
self.assertGreaterEqual(vmsize, 0)
self.assertGreaterEqual(rss, 0)
else:
# @TODO(kgiusti) - update test to handle other platforms as support
# is added
self.assertIsNone(mem)
self.assertIsNone(vmsize)
self.assertIsNone(rss)

def test_ssl_connection(self):
"""Verify skmanage can securely connect via SSL"""
Expand Down
14 changes: 13 additions & 1 deletion tests/system_tests_skstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import os
import re
import sys
import unittest
from subprocess import PIPE
from proton import Url, SSLDomain, SSLUnavailable, SASL
Expand Down Expand Up @@ -86,6 +87,12 @@ def test_general(self):
out, flags=re.DOTALL) is not None, out)
self.assertTrue(re.match(r"(.*)\bMode\b[ \t]+\bstandalone\b(.*)",
out, flags=re.DOTALL) is not None, out)
if sys.platform.lower().startswith('linux'):
# process memory metrics currently only supported on linux
self.assertTrue(re.match(r"(.*)\bVmSize\b[ \t]+\b[0-9]+\b(.*)",
out, flags=re.DOTALL) is not None, out)
self.assertTrue(re.match(r"(.*)\bRSS\b[ \t]+\b[0-9]+\b(.*)",
out, flags=re.DOTALL) is not None, out)

self.assertEqual(out.count("QDR.A"), 2)

Expand Down Expand Up @@ -248,7 +255,12 @@ def test_memory(self):
self.assertIn("QDR.A", out)
self.assertIn("UTC", out)
regexp = r'qdr_address_t\s+[0-9]+'
assert re.search(regexp, out, re.I), "Can't find '%s' in '%s'" % (regexp, out)
self.assertIsNotNone(re.search(regexp, out, re.I),
"Can't find '%s' in '%s'" % (regexp, out))
if sys.platform.lower().startswith('linux'):
# process memory metrics currently only supported on linux
m_regexp = r"(.*)\bVmSize\b[ \t]+\bRSS\b[ \t]+\bPooled\b(.*)"
self.assertIsNotNone(re.match(m_regexp, out, flags=re.DOTALL), out)

def test_memory_csv(self):
out = self.run_skstat(['--memory', '--csv'])
Expand Down
11 changes: 6 additions & 5 deletions tools/skstat.in
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ class BusManager:
pass

try:
if router.memoryUsage is not None:
if router_metrics.memoryUsage is not None:
rows.append(('VmSize', NumKMG(router_metrics.memoryUsage,
base=1024)))
except Exception:
pass
try:
if router.residentMemoryUsage is not None:
if router_metrics.residentMemoryUsage is not None:
rows.append(('RSS', NumKMG(router_metrics.residentMemoryUsage,
base=1024)))
except Exception:
Expand Down Expand Up @@ -744,13 +744,14 @@ class BusManager:

# attempt to get the qdrouterd process memory usage
# this may not be present on all platforms
router = self.query('io.skupper.router.router')[0]
router_metrics = self.query('io.skupper.router.routerMetrics')[0]

try:
vm_size = router.memoryUsage
vm_size = router_metrics.memoryUsage
except AttributeError:
vm_size = None
try:
rss_size = router.residentMemoryUsage
rss_size = router_metrics.residentMemoryUsage
except AttributeError:
rss_size = None

Expand Down

0 comments on commit 77ecd45

Please sign in to comment.