redashを0.12 -> 4.0.1のアップグレードした作業ログ
何
(あまりまともに運用されていない)redashがもともとredash-v0.12.0.b2449
で動いていたが Redash1.0.3で日本語を含むTreasureDataのクエリがエラーになるらしい
という報告をもらい対応を検討した結果、容易にアップグレードできそうだったので対応してみたところハマった
背景
http://blog.web.nifty.com/engineer/701
のように、古いredashではtd-clientのversionが古く日本語を含むクエリが動かないのでアップグレードしてほしい、という軽い相談を受けた。
前述のブログによれば td-client
が0.8.0以降で改修されているという記述があったので試してみたところ、 Error running query: job error: 328215861: error
という謎のエラーが発生し解決しなかった。
pip install td-client==0.8.0 pip list | grep td-client supervisorctl restart all
redashのupgradeについて調査をしてみたところ、 https://redash.io/help/open-source/admin-guide/how-to-upgrade にキレイにアップグレードの方法がまとまっていたので、数年前のredashを積極的に使う理由もないし簡単にできそうだったのでアップグレードをすることにした。 なおコンテナで動かす方向も検討したが、redashはそれまでほぼ誰も使っておらず今後の使用頻度にもあまり期待はできなさそうだったのでアップグレードを採用した。
何にハマったか
今回は0.12 -> latestのupgradeだったので前述のリンクの
How to upgrade (pre v1.0.0 versions)
に該当し、記述通りの対応を行った。
cd /opt/redash sudo cp -r redash-v0.12.0.b2449 redash-v0.12.0.b2449-backup cd /opt/redash/current wget https://raw.githubusercontent.com/getredash/redash/master/bin/upgrade chmod +x upgrade vim .env # REDASH_STATIC_ASSETS_PATHを消す sudo ./upgrade
実行したところ、
Downloading release tarball... Unpacking to: redash.4.0.1.b4038... Changing ownership to redash... Linking .env file... Installing new Python packages (if needed)... Running migrations (if needed)...
とログが流れ、最後のmigrationが時間がかかっているようだったのでバックグランド実行に切り替え退社(20:30)し、優雅にジムに行き2km泳ぎ、気分良く帰宅し「よーしmigration終わったやろ」と言って psql して SELECT * FROM pg_stat_activity;
した(1:30)ところ、 idle in transaction
で数時間止まっているクエリを発見した。
migrationが終わっていない....
ひとまずmigrationが問題であることがわかったのでmigrationを単体で実行してみる。
[ec2-user@ip-xxx-xxx-xxx-xxx redash.4.0.1.b4038]$ pwd /opt/redash/redash.4.0.1.b4038 bin/run ./manage.py db upgrade
しかし、 Update widget’s position data based on dashboard layout.
Updating dashboards position data:
でstuckして十数分待ってもmigrationが終わらない。
どうしたものかと思いぐぐったところ、全く同じ現象でハマッた人がおり、 0.12 -> 4.0.1の前に 3.0を経由したら動いた とのことだった。 んなアホな
物は試しと3.0へのupgradeを試みる。 アップグレード対象のversionはどうやらAPIから取得しているようだった。
def get_release(channel): if channel == 'ci': return get_latest_release_from_ci() response = requests.get('https://version.redash.io/api/releases?channel={}'.format(channel)) release = response.json()[0] filename = release['download_url'].split('/')[-1] release = Release(release['version'], release['download_url'], filename, release['description']) return release
APIのレスポンスを見ると、
[{"id":28,"version":"4.0.1","channel":"stable","download_url":"https://s3.amazonaws.com/redash-releases/redash.4.0.1.b4038.tar.gz","backward_compatible":false,"released_at":"2018-05-02T00:00:00.000Z","description":"* Before doing an upgrade, please make sure you have a backup.\n* If you have any issues, please refer to the troubleshooting section in the upgrade guide:\n https://redash.io/help/open-source/admin-guide/how-to-upgrade\n* If the upgrade guide doesn't help, you can ask for help on the forum (https://discuss.redash.io). \n\nFull CHANGELOG for this release: https://github.com/getredash/redash/blob/master/CHANGELOG.md","docker_image":"redash/redash:4.0.1.b4038"},{"id":27,"version":"4.0.0","channel":"stable","download_url":"https://s3.amazonaws.com/redash-releases/redash.4.0.0.b3948.tar.gz","backward_compatible":false,"released_at":"2018-04-16T00:00:00.000Z","description":"* Before doing an upgrade, please make sure you have a backup.\n* If you have any issues, please refer to the troubleshooting section in the upgrade guide:\n https://redash.io/help/open-source/admin-guide/how-to-upgrade\n* If the upgrade guide doesn't help, you can ask for help on the forum (https://discuss.redash.io). \n\nFull CHANGELOG for this release: https://github.com/getredash/redash/blob/master/CHANGELOG.md","docker_image":"redash/redash:4.0.0.b3948"},{"id":23,"version":"3.0.0","channel":"stable","download_url":"https://s3.amazonaws.com/redash-releases/redash.3.0.0.b3134.tar.gz","backward_compatible":true,"released_at":"2017-11-13T00:00:00.000Z","description":"* Before doing an upgrade, please make sure you have a backup.\n* If you have any issues, please refer to the troubleshooting section in the upgrade guide:\n https://redash.io/help-onpremise/maintenance/how-to-upgrade-redash.html\n* If the upgrade guide doesn't help, you can ask for help on the forum (https://discuss.redash.io). \n\nFull CHANGELOG for this release: https://github.com/getredash/redash/blob/master/CHANGELOG.md","docker_image":"redash/redash:3.0.0.b3134"},{"id":22,"version":"2.0.1","channel":"stable","download_url":"https://s3.amazonaws.com/redash-releases/redash.2.0.1.b3080.tar.gz","backward_compatible":true,"released_at":"2017-10-22T00:00:00.000Z","description":"* Before doing an upgrade, please make sure you have a backup.\n* If you have any issues, please refer to the troubleshooting section in the upgrade guide:\n https://redash.io/help-onpremise/maintenance/how-to-upgrade-redash.html\n* If the upgrade guide doesn't help, you can ask for help on the forum (https://discuss.redash.io). \n\nFull CHANGELOG for this release:\nhttps://github.com/getredash/redash/blob/master/CHANGELOG.md#v201---2017-10-22","docker_image":null},{"id":21,"version":"2.0.0","channel":"stable","download_url":"https://s3.amazonaws.com/redash-releases/redash.2.0.0.b2990.tar.gz","backward_compatible":true,"released_at":"2017-08-08T00:00:00.000Z","description":"* Before doing an upgrade, please make sure you have a backup.\n* If you have any issues, please refer to the troubleshooting section in the upgrade guide:\n https://redash.io/help-onpremise/maintenance/how-to-upgrade-redash.html\n* If the upgrade guide doesn't help, you can ask for help on the forum (https://discuss.redash.io). \n\nFull CHANGELOG for this release: https://github.com/getredash/redash/blob/master/CHANGELOG.md#v200---2017-08-08","docker_image":null}]
のようになっておりchannel: stableの3つめのレスポンスを使えばよさそうということがわかったので、
- release = response.json()[0] + release = response.json()[2]
とし
sudo ./upgrade --channel stable
を実行したところ、速攻3.0へのupgradeが終わってしまった。なんでやねん...と思いつつもう一度upgradeを実行したところ素直に4.0.1にあがった。 なんでやねん
所感
- ゴリ押し感半端ない
- 素直にcontainerで動かせばこんな苦労はないので、僕のような悪い大人にはならないようにしましょう
補足
redash4.0にあげたことによりクエリ失敗時のエラーログに詳細の理由が出るようになった結果、 今回のクエリは
Error running query: job error: 328361382: error: Query 20180814_173306_79597_yerrm failed: line 15:12: Table td-presto.xxx.xxx_orders does not exist
というように失敗していたので別の理由もあったことがわかり結果的にはredashあげてよかったですね。