Google Cloud Platform – Designing an Issues Notification System using Cloud Run
Problem Statement: Consider your run a Software company. And you have a huge client list who frequently use your software. You host your software on Github so that its users can send information regarding bugs in them. You being a lead developer in the team, how will you design a system that notifies the development team on Slack whenever an issue is submitted by a user on GitHub?
GitHub is one of the many services that provide event-driven Webhooks. This means is that if someone files an issue, Github will send a request to a URL specified by the developer. To ensure that if someone files an issue in GitHub, the developer team is notified and the issue isn’t lost in their inbox.
We can use Cloud Run to host the new Webhook target. This means developers won’t have to worry about servers, and they can use the language and framework that they are comfortable with.
The first thing you have to worry about is authorization. It would look somewhat like below:
A Webhook target is a public URL, and anyone with the URL could send anything to it. To ensure you are only processing valid requests, you can make use of a shared secret. You will need to create a secret key and put one copy in the GitHub configuration and store a copy securely with the Cloud Secret Manager. These secrets would look something like below depending upon your need:
$ SECRET = "$(python3 -c 'import secrets print(secrets.token_hex(20))')" $ echo - $SECRET | gloud beta secrets create github-secret --replication-policy = automatic --data-file=-
Every request from GitHub is signed, so you can use the secret to validate the signature and only process the valid requests. A generics signature verification function is given below, it may change depending upon your verification requirements:
Now development team will be able to securely receive events from GitHub, and a developer can use these events to send messages to Slack using the Slack API. A developer at this will write a function to send a message to the team’s Slack channel every time a valid request from GitHub is received. A sample function would look like below:
Your team will never miss another issue. To measure how long it takes the team to close an issue. You can add one more function to the Webhook to stream any issue events to BigQuery so it can easily create metrics around the team’s issue performance. The full Webhook target is now creating notifications, triggering an action, and streaming data into BigQuery.