Somewhat on-topic, instead of re-inventing the wheel on this one, I've recently been using Flagger (https://flagger.app/) and have been exceptionally happy with it. Automated rollback on error rates, metrics or integration tests. It's so nice to finally be able to stop writing this code at every company I work for!