From 9a32bb0b8e3a3eae9e16d8dd953df0f21cef8baa Mon Sep 17 00:00:00 2001 From: Heron Vieira Date: Wed, 29 Nov 2023 11:38:14 -0300 Subject: [PATCH] Improve logging on k8s-coredump and allow case-sensitive path for k8s-coredump Improving logging by adding timestamp and show error in case we have a KeyError while trying to verify configurations set by pod annotations. Also allowing case-sensitive paths to be configured as the path to save the coredumps. PENDING: AIO-SX install and bootstrap. PENDING: On a AIO-SX test if k8s-coredump is executed successfully. PENDING: On a AIO-DX test if k8s-coredump is executed successfully. PENDING: On a Standard test if k8s-coredump is executed successfully. PENDING: On a Standard test if k8s-coredump is executed successfully using a PVC setup. Change-Id: I942253468a596b7d68d6a3733b24062cfb4661f7 Signed-off-by: Heron Vieira --- .../k8s-coredump/k8s_coredump/common/constants.py | 3 ++- .../k8s-coredump/k8s_coredump/config_functions.py | 15 ++++++++++++--- .../k8s-coredump/k8s_coredump/coredump.py | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/utilities/k8s-coredump/k8s-coredump/k8s_coredump/common/constants.py b/utilities/k8s-coredump/k8s-coredump/k8s_coredump/common/constants.py index 9dffb704..896150d1 100644 --- a/utilities/k8s-coredump/k8s-coredump/k8s_coredump/common/constants.py +++ b/utilities/k8s-coredump/k8s-coredump/k8s_coredump/common/constants.py @@ -14,5 +14,6 @@ LOCALHOST_URL = "https://localhost:10250/pods" SYSTEMD_COREDUMP = "/usr/lib/systemd/systemd-coredump" -logging.basicConfig(filename=K8S_COREDUMP_LOG, level=logging.DEBUG) +logging.basicConfig(filename=K8S_COREDUMP_LOG, level=logging.DEBUG, format='%(asctime)s %(message)s', + datefmt='%m/%d/%Y %I:%M:%S %p') LOG = logging.getLogger("k8s-coredump") diff --git a/utilities/k8s-coredump/k8s-coredump/k8s_coredump/config_functions.py b/utilities/k8s-coredump/k8s-coredump/k8s_coredump/config_functions.py index 69b49a4c..a518d940 100644 --- a/utilities/k8s-coredump/k8s-coredump/k8s_coredump/config_functions.py +++ b/utilities/k8s-coredump/k8s-coredump/k8s_coredump/config_functions.py @@ -66,9 +66,12 @@ def parse_core_pattern(string_core_pattern, **kwargs): str String with all the information replaced accordingly """ - string_core_pattern = string_core_pattern.lower() + LOG.info(f'Full path passed to parse_core_pattern: {string_core_pattern}') + splited_path = string_core_pattern.split("/") + string_core_pattern = splited_path[splited_path.__len__()-1] + LOG.info(f'Parsing core pattern: {string_core_pattern}') - processed_string = string_core_pattern + processed_string = string_core_pattern.lower() processed_string = processed_string.replace('%p', kwargs['pid']) processed_string = processed_string.replace('%u', kwargs['uid']) processed_string = processed_string.replace('%g', kwargs['gid']) @@ -77,7 +80,12 @@ def parse_core_pattern(string_core_pattern, **kwargs): processed_string = processed_string.replace('%h', kwargs['hostname']) processed_string = processed_string.replace('%e', kwargs['comm2']) LOG.info(f'Core pattern parsed to {processed_string}') - return processed_string + + splited_path[splited_path.__len__()-1] = processed_string + full_path_processed = "/".join(splited_path) + LOG.info(f'Full path parsed by parse_core_pattern: {full_path_processed}') + + return full_path_processed def parse_size_config(string_config): @@ -108,6 +116,7 @@ def parse_size_config(string_config): f'(Multiplier of bytes: {size_properties["multiplier"]})') return float(value), size_properties + LOG.info(f'Unable to parse size configuration from: {string_config}') return None diff --git a/utilities/k8s-coredump/k8s-coredump/k8s_coredump/coredump.py b/utilities/k8s-coredump/k8s-coredump/k8s_coredump/coredump.py index ffcaebeb..308451d3 100644 --- a/utilities/k8s-coredump/k8s-coredump/k8s_coredump/coredump.py +++ b/utilities/k8s-coredump/k8s-coredump/k8s_coredump/coredump.py @@ -127,8 +127,8 @@ def CoreDumpHandler(**kwargs): except ValueError as e: LOG.error("Pod defined an invalid core dump annotation: %s" % e) sys.exit(-1) - except KeyError: - LOG.debug("Pod does have annotations defined") + except KeyError as e: + LOG.debug("Pod does have annotations defined but some configuration is missing: %s" % e) pass # not handled by pod, redirect to systemd coredump handler