From 2f39882badc2579afa9d2ac0766ae600562b0c8b Mon Sep 17 00:00:00 2001 From: Enzo Candotti Date: Thu, 28 Nov 2024 14:58:17 -0300 Subject: [PATCH] Enhance logging for dcaudit and dcorch To improve the logged information during dcmanager audit and avoid unnecessary logging in dcorch and audit, this commit adjusts log levels between DEBUG and INFO. Additionally, a specific rule is added for state.log in logrotate to retain larger files compared to the rest of the dcmanager logs. It was also seen that at the end of the dcorch audit process, the sync_request was being updated to 'requested' for the subcloud and endpoint being audited. This commit enhances this logic by updating this state just for the cases in which there are sync jobs to be run. Test Plan: PASS: Verify that during dcorch audit, if there are no sync jobs to be run, the sync_request field is not updated. PASS: Verify that during dcorch audit, if there are sync jobs, the sync_request field is updated to 'requested'. Also verify that in the next sync round, that subcloud/enpdoint is synched. PASS: Verify that state.log rotates when it reaches the configured size of 40MB. PASS: Verif that other dcmanager logs follow the previous rotation policy. Story: 2011106 Task: 51424 Change-Id: Icfa3eb9bd692e1e22f8940c904e7ef373260589d Signed-off-by: Enzo Candotti --- .../dcmanager/audit/patch_audit.py | 4 +++- .../dcmanager/audit/subcloud_audit_manager.py | 4 ++-- .../dcorch/engine/sync_services/identity.py | 2 +- .../dcorch/engine/sync_services/sysinv.py | 2 +- distributedcloud/dcorch/engine/sync_thread.py | 15 ++++++------- .../engine/sync_services/test_identity.py | 2 +- .../files/distcloud-logrotate.conf | 21 ++++++++++++++++++- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/distributedcloud/dcmanager/audit/patch_audit.py b/distributedcloud/dcmanager/audit/patch_audit.py index f0d6aaff8..3d110c12e 100644 --- a/distributedcloud/dcmanager/audit/patch_audit.py +++ b/distributedcloud/dcmanager/audit/patch_audit.py @@ -43,12 +43,14 @@ class PatchAudit(object): return PatchAuditData() def subcloud_patch_audit(self, keystone_client, subcloud): - LOG.info("Triggered patch audit for: %s." % subcloud.name) # NOTE(nicodemos): Patch audit not supported for 24.09 subcloud if subcloud.software_version == SW_VERSION: return consts.SYNC_STATUS_NOT_AVAILABLE + # Log this just for N-1 subclouds, before the has_usm_service external call + LOG.info("Triggered patch audit for: %s." % subcloud.name) + # NOTE(nicodemos): If the subcloud is on the 22.12 release with USM enabled, # skip the patch audit. if utils.has_usm_service(subcloud.region_name, keystone_client): diff --git a/distributedcloud/dcmanager/audit/subcloud_audit_manager.py b/distributedcloud/dcmanager/audit/subcloud_audit_manager.py index ce9a1b507..cf76e141f 100644 --- a/distributedcloud/dcmanager/audit/subcloud_audit_manager.py +++ b/distributedcloud/dcmanager/audit/subcloud_audit_manager.py @@ -608,7 +608,7 @@ class SubcloudAuditManager(manager.Manager): software_audit_data, use_cache, ) - LOG.debug( + LOG.info( "Sent subcloud audit request message for subclouds: %s" % subcloud_ids ) @@ -626,7 +626,7 @@ class SubcloudAuditManager(manager.Manager): software_audit_data, use_cache, ) - LOG.debug( + LOG.info( "Sent final subcloud audit request message for subclouds: %s" % subcloud_ids ) diff --git a/distributedcloud/dcorch/engine/sync_services/identity.py b/distributedcloud/dcorch/engine/sync_services/identity.py index 7be8d068c..fed065c92 100644 --- a/distributedcloud/dcorch/engine/sync_services/identity.py +++ b/distributedcloud/dcorch/engine/sync_services/identity.py @@ -115,7 +115,7 @@ class IdentitySyncThread(SyncThread): self.log_extra = { "instance": "{}/{}: ".format(self.region_name, self.endpoint_type) } - LOG.info("IdentitySyncThread initialized", extra=self.log_extra) + LOG.debug("IdentitySyncThread initialized", extra=self.log_extra) def initialize_sc_clients(self): super().initialize_sc_clients() diff --git a/distributedcloud/dcorch/engine/sync_services/sysinv.py b/distributedcloud/dcorch/engine/sync_services/sysinv.py index c0d8d38cb..418e55a9e 100644 --- a/distributedcloud/dcorch/engine/sync_services/sysinv.py +++ b/distributedcloud/dcorch/engine/sync_services/sysinv.py @@ -101,7 +101,7 @@ class SysinvSyncThread(SyncThread): self.sc_sysinv_client = None - LOG.info("SysinvSyncThread initialized", extra=self.log_extra) + LOG.debug("SysinvSyncThread initialized", extra=self.log_extra) def initialize_sc_clients(self): super().initialize_sc_clients() diff --git a/distributedcloud/dcorch/engine/sync_thread.py b/distributedcloud/dcorch/engine/sync_thread.py index c617d212f..867127f0e 100644 --- a/distributedcloud/dcorch/engine/sync_thread.py +++ b/distributedcloud/dcorch/engine/sync_thread.py @@ -769,17 +769,18 @@ class SyncThread(object): # shouldn't get here LOG.exception("Unexpected error!") - if not total_num_of_audit_jobs: + if total_num_of_audit_jobs == 0: # todo: if we had an "unable to sync this # subcloud/endpoint" alarm raised, then clear it pass + else: + db_api.subcloud_sync_update( + self.ctxt, + self.subcloud_name, + self.endpoint_type, + values={"sync_request": consts.SYNC_STATUS_REQUESTED}, + ) - db_api.subcloud_sync_update( - self.ctxt, - self.subcloud_name, - self.endpoint_type, - values={"sync_request": consts.SYNC_STATUS_REQUESTED}, - ) LOG.debug( "{}: done sync audit".format(threading.currentThread().getName()), extra=self.log_extra, diff --git a/distributedcloud/dcorch/tests/unit/engine/sync_services/test_identity.py b/distributedcloud/dcorch/tests/unit/engine/sync_services/test_identity.py index 1963d74c9..728153988 100644 --- a/distributedcloud/dcorch/tests/unit/engine/sync_services/test_identity.py +++ b/distributedcloud/dcorch/tests/unit/engine/sync_services/test_identity.py @@ -594,7 +594,7 @@ class TestIdentitySyncThreadProjectRoleAssignmentsPut( self._execute() - self._assert_log("info", "IdentitySyncThread initialized") + self._assert_log("debug", "IdentitySyncThread initialized") self.log.error.assert_not_called() diff --git a/distributedcloud/files/distcloud-logrotate.conf b/distributedcloud/files/distcloud-logrotate.conf index 12a9f0947..6c49c6acf 100644 --- a/distributedcloud/files/distcloud-logrotate.conf +++ b/distributedcloud/files/distcloud-logrotate.conf @@ -1,4 +1,23 @@ -/var/log/dcmanager/*.log +/var/log/dcmanager/state.log +{ + nodateext + size 40M + start 1 + rotate 20 + missingok + notifempty + compress + sharedscripts + postrotate + systemctl reload syslog-ng > /dev/null 2>&1 || true + endscript + +} + +/var/log/dcmanager/audit.log +/var/log/dcmanager/dcmanager-api.log +/var/log/dcmanager/dcmanager.log +/var/log/dcmanager/orchestrator.log { nodateext size 20M