Untitled

 avatar
unknown
plain_text
a year ago
3.4 kB
11
Indexable
I have this existing code in get-engine-commit.sh

engine_public_version="$(/rdsdbbin/oscar/bin/mysql -u rdsbmsperf -p auroraperf -e "SELECT aurora_version();" -prdsbmsperf | grep -P '[\d.]+')"
MySQL_grep=$(echo $(strings /rdsdbbin/oscar/bin/mysqld | grep 'git-head' -m1))
engine_internal_version=$(echo $MySQL_grep | grep -P 'OscarMysql[\d]+-[\d.]+' -o | grep -P '[\d.]+')
engine_build_time=$(echo $MySQL_grep | grep -P '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}UTC' -o)
engine_git_commit=$(echo $MySQL_grep | grep -P '[\w\d]{40}' -o -m1)

echo "engine_public_version: $engine_public_version engine_internal_version: $engine_internal_version engine_build_time: $engine_build_time engine_git_commit: $engine_git_commit"

which is being used here
 def collect_ams_engine_version_logs(self, instance_id, workflow_path):
        """
        Gather ams engine versions
        """
        credentials = self.get_pas_credentials(PAS_ADMIN_OPS_ROLE)
        cmds = self.get_rds_s3_file_transfer_template(
            credentials["AccessKeyId"], credentials["SecretAccessKey"]
        )
        cmds.append(
            "aws s3 cp " + f"{self.base_s3_location}/aurora-db-logs/get-engine-commit.sh /tmp "
        )
        cmds.append("sudo chmod +x /tmp/get-engine-commit.sh")
        cmds.append("sudo bash /tmp/get-engine-commit.sh > /tmp/engine_commit_id.log 2>&1")
        cmds.append(
            "aws s3 cp /tmp/engine_commit_id.log "
            + f"{get_pas_logs_s3_dir_for_instance(workflow_path, instance_id[0].strip())}"
        )
        self.__ssm_client.run_cmd(
            instance_id[1],
            cmds,
        )

Instead of going into f"{self.base_s3_location}/aurora-db-logs/get-engine-commit.sh and execurting commands from there I want to make the ams_engine_logs function somethig like this
def configure_cw_streaming(self, instance_id, workflow_id, log_group):
        credentials = self.get_pas_credentials(PAS_ADMIN_OPS_ROLE)
        cmds = self.get_rds_s3_file_transfer_template(
            credentials["AccessKeyId"], credentials["SecretAccessKey"]
        )

        cmds.append("export logfile=/tmp/ec2_logs_to_cw.log")
        cmds.append("sudo date >> $logfile 2>&1")
        cmds.append("sudo chmod -R 777 /tmp/ec2_logs_to_cw.log")
        cmds.append('sudo echo "Copy configure_cwagent_on_ec2.sh to /tmp" >> $logfile 2>&1')
        cmds.append(
            "aws s3 cp "
            + f"{self.base_s3_location}/aurora-db-logs/configure_cwagent_on_ec2.sh /tmp "
            + ">> $logfile 2>&1"
        )
        cmds.append("sudo chmod +x /tmp/configure_cwagent_on_ec2.sh >> $logfile 2>&1")
        cmds.append("echo y | sudo yum install jq >> $logfile 2>&1")
        cmds.append(
            f"sudo AWS_ACCESS_KEY_ID={credentials['AccessKeyId']} "
            + f"AWS_SECRET_ACCESS_KEY={credentials['SecretAccessKey']} "
            + "bash /tmp/configure_cwagent_on_ec2.sh "
            + f"-l {log_group} -t {workflow_id} -i {instance_id} "
            + ">> $logfile 2>&1"
        )
        cmds.append("sleep 2")
        self.__ssm_client.run_cmd(instance_id=instance_id, cmds=cmds)

So it doesnt have to go to get-engine-commit.sh file and the output of engine_commit_id.log should look like
engine_public_version: 3.999.95 engine_internal_version: OscarMysql80-1.0.48646.0 engine_build_time: 2024-01-16T20:27:20UTC engine_git_commit: f8a5f72003e47967f5c2072c1087f3d901fc0c11
Editor is loading...
Leave a Comment