From: Yaarit Hatuka Date: Sat, 9 Apr 2022 00:33:04 +0000 (-0400) Subject: mgr/telemetry: add anonymize_entity_name function X-Git-Tag: v18.0.0~1078^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e89d821ee6256b18f94d520baeb07012de80b731;p=ceph.git mgr/telemetry: add anonymize_entity_name function The ability to anonymize entity names should have its own function to prevent duplicate code. Will clean up in a separate commit. Signed-off-by: Yaarit Hatuka --- diff --git a/src/pybind/mgr/telemetry/module.py b/src/pybind/mgr/telemetry/module.py index a96e6155a0a41..3b49bd6093cec 100644 --- a/src/pybind/mgr/telemetry/module.py +++ b/src/pybind/mgr/telemetry/module.py @@ -28,6 +28,7 @@ ALL_CHANNELS = ['basic', 'ident', 'crash', 'device', 'perf'] LICENSE = 'sharing-1-0' LICENSE_NAME = 'Community Data License Agreement - Sharing - Version 1.0' LICENSE_URL = 'https://cdla.io/sharing-1-0/' +NO_SALT_CNT = 0 # Latest revision of the telemetry report. Bump this each time we make # *any* change. @@ -407,6 +408,28 @@ class Module(MgrModule): 'active_changed': sorted(list(active)), } + def anonymize_entity_name(self, entity_name:str) -> str: + if '.' not in entity_name: + self.log.debug(f"Cannot split entity name ({entity_name}), no '.' is found") + return entity_name + + (etype, eid) = entity_name.split('.', 1) + m = hashlib.sha1() + salt = '' + if self.salt is not None: + salt = self.salt + # avoid asserting that salt exists + if not self.salt: + # do not set self.salt to a temp value + salt = f"no_salt_found_{NO_SALT_CNT}" + NO_SALT_CNT += 1 + self.log.debug(f"No salt found, created a temp one: {salt}") + m.update(salt.encode('utf-8')) + m.update(eid.encode('utf-8')) + m.update(salt.encode('utf-8')) + + return etype + '.' + m.hexdigest() + def get_heap_stats(self) -> Dict[str, dict]: # Initialize result dict result: Dict[str, dict] = defaultdict(lambda: defaultdict(int))