Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.9 kB
3
Indexable
Never
class RDSHostLogCollection(__BaseLogCollection):
    # Define constants for paths and filenames
    GATHER_DB_LOGS_SH_PATH = "/tmp/test-gather-aurora-db-logs.sh"
    AURORA_DIAGNOSTIC_LOG_PATH = "/rdsdbdata/tmp/aurora-perf-analysis-rdsdbdiagnostic.tar.gz"

    def __init__(self, instance_id, workflow_path, test_start_timestamp, **kwargs):
        super().__init__(**kwargs)
        self.instance_id = instance_id
        self.workflow_path = workflow_path
        self.test_start_timestamp = test_start_timestamp
        self.__ssm_client = get_ssm_client(region=region, rds_domain=domain)

    def collect_db_logs(self):
        """
        Gather rds db diagnostics logs
        """
        credentials = self.get_pas_credentials(PAS_ADMIN_OPS_ROLE)
        cmds = self.get_rds_s3_file_transfer_template(
            credentials["AccessKeyId"], credentials["SecretAccessKey"]
        )

        # Use variables instead of hardcoding paths and filenames
        cmds.append(f"aws s3 cp {self.base_s3_location}/aurora-db-logs/test-gather-aurora-db-logs.sh {self.GATHER_DB_LOGS_SH_PATH}")
        cmds.append(f"sudo chmod +x {self.GATHER_DB_LOGS_SH_PATH}")

        if self.test_start_timestamp:
            formatted_timestamp = self.test_start_timestamp.strftime("%Y-%m-%d %H:%M:%S")
        cmds.append(
            f"sudo bash {self.GATHER_DB_LOGS_SH_PATH} -t '{formatted_timestamp}' -z aurora-perf-analysis-rdsdbdiagnostic "
            "-x /rdsdbdata/tmp/seed -x /rdsdbdata/db/pg_stat_tmp -x /rdsdbdata/tmp_lctn_on -x /rdsdbdata/tmp/mysql/mysql.ibd "
            f"-x /rdsdbdata/tmp/pas /rdsdbdata"
        )
        cmds.append(
            f"aws s3 cp {self.AURORA_DIAGNOSTIC_LOG_PATH} "
            + f"{get_pas_logs_s3_dir_for_instance(self.workflow_path, self.instance_id[0].strip())}"
        )
        self.__ssm_client.run_cmd(
            self.instance_id[1],
            cmds,
        )
Leave a Comment