Share
Embed
2ヶ月かかるDBアップグレード検証を最大2週間に短縮した自作Go製CLIツール「Platinum」を紹介する / Introducing Go CLI tool "Platinum" for shortened DB upgrade validation
Money Forward Tech Day 2024 9.20 https://techday.moneyforward-dev.jp/2024/
"2ヶ月かかるDBアップグレード検証を最大2週間に短縮した自作Go製CLIツール「Platinum」を紹介する"
【概要】
Amazon Aurora v2のEOLが迫る中、私たちは複数のデータベース移行検証を実施する必要がありました。バージョンアップ後に問題がないかを検証するために、本番データベースを元に検証環境を構築するなど、様々なハードルが存在しました。このToilを解消するためにSREチームはGo製CLIを作成し、これら一連の検証期間を2週間程度に短縮することに成功しました。このセッションでは、SREによるSREのためのツール開発の重要性や、それがもたらした効果を知ることができます。
VTRyo
September 20, 2024
Transcript
62 slides
-
• Joined Money Forward in October 2021 • Responsible for
reliability of HR related products. • At SRE NEXT 2022, I presented "How to start SRE in a product team, all by yourself" https://speakerdeck.com/vtryo/how-to-start-sre-in- a-product-team-all-by-yourself • At the Developers boost 2023, received the best speaker award https://speakerdeck.com/vtryo/career-planning-starti ng-by-luckly VTRyo(リョウ / Rio) -
• 拙著「ITエンジニアのための偶然から始めるキャリアプ ラン」etc I am the author of “Career Planning
for IT Engineers Starting from serendipity”, etc • 🍜, 🍛, 🍺 I eat curry or ramen almost every day. Beer is my default. VTRyo(リョウ / Rio) -
マネーフォワード クラウドの人事労務領域やってます I’m working on the HR and Labor area
of the Money Forward Could series. Cloud Payroll Cloud Attendance Cloud personal management -
• データベースエンジンを変更するとき に実施している"pt-upgrade” • 繰り返されるヘビーな運用作業を解決 するために Platinum というCLIツー ルが生まれた •
自分たちのためにツールを作ってどう なったか 目次 Agenda • “pt-upgrade” performed when changing database engine. • A CLI tool called Platinum was created to solve repetitive and heavy operational tasks. • What happened when we created this tool for ourselves. -
• DBエンジンを変更するとき、高い可用 性を維持するためにやっていること • 何に2ヶ月かかったのか • 時短のアプローチ方法 • Platinumの機能例 今日の話でわかること
Takeaways from today's presentation • What we do to maintain high availability when changing DB engines • What took two months? • Approaches taken to shorten the time • Examples of Platinum’s features -
• AWS, Go, Terraformなどの使い方 • CLIの実装詳細 話さないこと Things I won’t
talk about today • How to use AWS, Go and Terraform • Details of the CLI implementation -
• パフォーマンスが劣化しない • クエリの互換性がある • 非推奨クエリや非推奨パラメータがな い → Percona社が開発している "pt-upgrade"を利用してチェック
DBエンジンを変更するとき確認していること What to check when changing a DB engine • No performance degradation • Query compatibility • No deprecated queries or parameters. → Use 'pt-upgrade' developed by Percona to perform the checks -
Percona Toolkit - pt-upgradeを採用 • 異なる2 version間で互換性をチェック するベンチマークツール • 2台のサーバでクエリを実行し、有意
差をレポートする • slow.log, general.log, binary, tcpdumpなどにも対応 互換性とクエリパフォーマンスチェックするために To check compatibility and query performance The Percona Toolkit - Adopt pt-upgrade. • A benchmarking tool to check compatibility between two different versions. • Run queries on two servers and report significant differences. • Supports slow.log, general.log, binary, tcpdump. -
Perconaのブログ The Percona’s blog about pt-upgrade. Arunjith Aravindan, Two Extremely
Useful Tools (pt-upgrade and checkForServerUpgrade) for MySQL Upgrade Testing,PERCONA, August 29, 2022, https://www.percona.com/blog/two-extremely-useful-tools-pt-upgrade-and-checkforserverupgrade-for-mysql-upgrade-testing/ -
検証概要 Verification summary general.logを2つのDBに流して レポートを生成する Send general.log to two DBs
and generates reports -
pt-upgradeのコマンド例 Example command for pt-upgrade filter 引数の例。本番環境では30個以上パイプしている Example of filter
argument. More than 30 are piped in production environment. -
• 社内制約を考慮した構成が必要だっ た • pt-upgrade実行準備の手間の多さ • pt-upgrade実行中の手間の多さ • 外部要因 なぜこんなに時間がかかったのか
Why did it take so long to verify this? • The configuration needed to take internal constraints into account. • Preparation for pt-upgrade execution required time and effort. • Running pt-upgrade required time and effort. • external factors. -
• 本番環境のデータはProductionの AWSアカウント上でしか扱えない • 本番環境に影響しない形で検証できる 環境を構築するためのトライアンドエ ラーに長時間使った • 検証の度にDBを消したり作ったりする だけでもTerraformで大幅変更が必
要だったりした その1, 社内制約を考慮した構成が必要だった No.1 The configuration needed to take internal constraints into account. • Production data can only be handled on the Production AWS account. • We spent a lot of time on trial and error to build an environment that could run the verification without affecting the production environment. • Just deleting and creating a DB for each verification required major changes in Terraform. -
• 本番DBでgeneral.logを出力する • 本番DBのSnapshotを取得する • 新旧のDBインスタンスを作成 • これらのDBにアクセスできるサーバと ネットワークの設定
(続く……) その2, pt-upgrade実行準備の手間 No.2, Preparation for pt-upgrade execution required time and effort. • Output general.log in the production DB. • Get a snapshot of the production DB. • Create old and new DB instances. • Configure server and network settings to access these DBs. (continued…) -
• general.logをpt-upgrade実行サー バにダウンロードする • 分割されたgeneral.logをひとつに結 合する • pt-upgrade実行用のオプションを選 定する その2,
pt-upgrade実行準備の手間 • Download general.log to pt-upgrade execution server. • Merge the split general.log into one file. • Select options for pt-upgrade execution. No.2, Preparation for pt-upgrade execution required time and effort. -
• pt-upgrade実行開始 • filterオプションが足りないと pt-upgradeがエラーで止まるので その都度オプションを追加する • 完了したかどうか逐一EC2インスタン スにログインして見に行く その3,
pt-upgrade実行中の手間 No.3, Running pt-upgrade required time and effort • Start pt-upgrade execution • If the filter option is missing, pt-upgrade will stop with an error, and options need to be added each time. • Log in to the EC2 instance to see if pt-upgrade is completed. -
• SnapshotはDBを停止して取得する 必要があったので夜間メンテナンス作 業が必須 -> general.logの開始地点と Snapshotの断面を揃えるため • メンテナンス実施調整 •
夜間ローテーション調整 その4, 外部要因 No.4, external factors. • Since the snapshot required stopping the database to be taken, nighttime maintenance work was necessary. -> To align the starting point of general.log with the cross-section of snapshot. • Coordination of maintenance implementation. • Setting up nighttime duty rotations. -
初回利用時は大変な作業だった Using pt-upgrade for the first time was a very
difficult task. -
Amazon Aurora MySQL 互換エディション バージョン 2 標準サポート終了 Amazon Aurora MySQL-Compatible
Edition version 2’s standard support ends -
せめて外部依存のない範囲は時短したい At the very least, we wanted to shorten the
time, where there are no external dependencies -
• SREチーム内に閉じている範囲 • 1. 検証環境構築 • 2. general.logのダウンロードや加工 • 3.
pt-upgradeコマンド(オプションや 接続情報なども含めて)の準備 こちらで制御できる範囲とは What is the scope we can control? • Scope closed within SRE team. • 1. Buildingthe verification environment • 2. Downloading and processing general.log • 3. Preparation of up-grade commands (including options and connection information) -
CLI - Platinumの誕生 CLI - Platinum was born pt-upgradeのPtから元素記号を連想し て命名
ロゴはChatGPTで生成 Named after the chemical symbol Pt in pt-upgrade. The logo was generated by Chat GPT. -
• 長くて多いpt-upgradeコマンド引数を config.ymlで管理する • general.logのダウンロード、結合、 フォーマットする • pt-upgradeの実行 • Slackへ完了通知
Platinumの主な機能 Platinum’s main features. • Manage long and numerous pt-upgrade command arguments in config.yml. • Download, merge and format general.log. • Execute pt-upgrade. • Notify completion to Slack. -
専用Terraform moduleを作成 Create dedicated Terraform module 必要なAWSリソース構築を module化したことで時間短縮に成 功 Successfully
reduced time by modularizing the required AWS resource setup -
自動構築するリソース Automatically build resources 本番アカウント内に隔離されたリソー スを毎回作る Create an isolated resource
in the production account each time. -
ポイントはpt-upgrade実行準備から実行開始までの見積もり変化 The key is the change in estimated time from
preparation to start of pt-upgrade execution. -
• go v1.21 • AWS SDK for Go v2 •
CLI tool: urfave/cli ◦ https://github.com/urfave/cli Platinum 基本情報 Platinum basic information -
Platinumの機能例 1 Platinum Features Example 1 ログの定期ダウンロード downloadCompleteLogFile へリクエストしている Periodic
log download. Requests to downloadCompleteLogFile. -
• AWS CLIで利用できる DownloadDBLogFilePortion ファイルサイズが1MBまで • CloudWatch logsがS3へ転送してダ ウンロード可能 •
REST endpoint downloadCompleteLogFile サイズに関係なくダウンロード可能 ログダウンロード方法はいくつか選択肢がある There are several options for downloading logs. • DownloadDBLogFilePortion available in AWS CLI. File size up to 1MB. • CloudWatch logs can be transferred to S3 for download. • REST endpoint downloadCompleteLogFile can be downloaded regardless of size -
• 一度に取得するログ行数を50行など に分割してループで取得する実験をし たがスロットリングエラー発生 • 仮に1行のサイズが1MBを超えた場 合は切り捨てられるはず • aws-sdk issue
"RDS log message was truncated by downloadDBLogFilePortion"参照 なぜDownloadDBLogFilePortionを使わないのか Why not use DownloadDBLogFilePortion? • We experimented splitting the number of log lines to be retrieved at a time to 50 lines and looping through them, but a throttling error occurred. • If the size of one line exceeds 1MB, it should be truncated. • Refer to aws-sdk issue “RDS log message was truncated by downloadDBLogFilePortion” -
• CloudWatch logsの最大イベントサ イズが256KB • 実際に1行がそのサイズを超えていた ため不完全なログになった なぜCloudWatch logsとS3を利用しないのか Why
not use CloudWatch logs and S3? • Maximum event size in CloudWatch logs is 256KB. • One line actually exceeded that size, resulting in incomplete logs. -
• REST endpoint downloadCompleteLogFile サイズに関係なくダウンロード可能 • 自力でGETリクエストを生成する必要 がある • https://docs.aws.amazon.com/ja_
jp/AmazonRDS/latest/AuroraUser Guide/DownloadCompleteDBLog File.html なぜdownloadCompleteLogFileを使うのか Why use downloadCompleteLogFile? • REST endpoint downloadCompleteLogFile can be download regardless of size. • Need to generate GET requests on my own. • https://docs.aws.amazon.com/A mazonRDS/latest/AuroraUserGui de/DownloadCompleteDBLogFile .html -
• 長い、多い、は非常に読みづらい • 何度もパラメータを変えて実行するこ ともある。 眼精疲労を許容しがたい • 最初はPlatinumの引数として渡そう としていたが、YAMLを読み込む方向 性に変更した
持たせるパラメータが複雑だったためこの形に The parameters to have were complex, so this is the form. • Long, many, is very hard to read. • Sometimes run with different parameters many times. Hard to tolerate eye strain. • At first we were trying to pass them as arguments to Platinum, but changed direction to read YAML. -
Platinumの機能例 3 Platinum Features Example 3 Slackへ完了通知 いつ終わったかわざわざ調べに行かずに済 む Notification
of completion to Slack. No need to go to check when it was finished -
AWS CLIの寄せ集めじゃだめなの? Couldn't we have used a collection of AWS
CLI commands in a shell? -
• Shell芸は避けたかった というか最初の一回目からAWS CLIで やっていた • Shellよりも保守性がある • 一連の作業をCLIにすれば他チーム に展開できるポテンシャルがあった
• SREチームの開発能力向上に繋がる ツール製作した理由とは Why did we create the tool? • We wanted to avoid using the shell trick. We had actually used AWS CLI since the first time • Higher maintainability compare do Shell • There was potential to deploy to other teams if a series of work was done using CLI • Improves the development capability of the SRE team -
• コードネームを決めると案外テンション 上がる。愛着ってすごい • "泥臭くてしんどい運用作業こそソフト ウェアでなんとかするのもSREだ"とい う初心を思い出す • 需要が自分たちにある開発はそれだ けで学びが大きい
• プログラミングを嫌がる人がいないの で全員イキイキしていた SREのSREによるSREのための開発 Development by SRE’s for SRE’s • Deciding on a code name was unexpectedly exciting. It feels great to feel the attachment! • Reminded us of the basics where “It is SRE’s job to to manage cumbersome and and tedious operations using software • Development where the demand is on us is a great learning experience in itself • None of us dislike programming, so everyone was very enthusiastic and full of energy -
• メンテナンスモードやリリースのための 日程調整は別途必要 • レポートの分析は人間が実施する • アプリケーションの修正が必要な場合 はその分の時間がかかる • とはいえその前段が短くなっただけで
も非常に喜ばしい 時短したのはあくまで検証までである The time was shortened only up to the verification • Separate scheduling for maintenance mode and release is required • Analysis of reports is performed by humans • If the application needs to be modified, it will take time to modify • However, we are extremely happy we have been able to shorten that first step!