In a previous post to our blog, we talked about how we make sure our players are working as expected just before its release with a series of end-to-end(e2e) tests, which run on supported distributions. This has helped us to identify the introduction of issues during the development of new features or bug fixes. For this reason, most of the time we implement e2e for every piece of software in our entire digital signage platform. Although it catches most of the issues, there might be times where an issue is not caught, and for that reason we also have monitoring systems;, it’s this monitoring system that we will be talking about in this post. We will show a way to trigger HTML Cloud Functions.
We built this monitoring system for one of the backend services we have for our player to be able to communicate with app.risevision.com. You can see it in use when you request a screenshot of the player or when you check the online/offline status. As it is essential to our platform to inform users about the player status, this service has to be monitored so we can be alerted if something stops working, thus, we can act immediately to avoid impacting our end users.
We have chosen to use Google Cloud Functions and Stackdriver health check as trigger for our monitoring system. Our monitoring system is a set of e2e tests that runs continually every few minutes to make sure that the service is live and responding correctly based on defined use cases. e looked at the tools we could use knowing that we are already a big consumer of the Google Cloud Platform to accomplish this. With that in mind, there are two options: use a stand alone VM or the new Cloud Function. Cloud Functions first came to mind because the monitoring system is a NodeJs app. After researching a little bit more we decided to go with Cloud Function because of the following:
- NodeJs platform
- Simple to setup
- No need to maintain a VM instance
- Cost on demand
- Easy to deploy and to do CD(Continuous Delivery)
Once we decided to use Cloud Functions we found a problem; there is no way to create a scheduled cloud function as we need in our case. After some research on the internet, we saw others resorting to using an app engine cron job to trigger it, but that would be cumbersome. We then remembered that stackdriver health checks is designed to call any endpoint accessible on the internet. So why not use it to call a HTTP Cloud Function. That was it, we had found a cheap and easy way to trigger cloud functions on a scheduled basis.
A key feature of monitoring system is the alerts, right? So we needed to have a way to alert us when a failure happens which means an use case of the e2e test has failed. As we use HipChat daily to communicate with everyone in the company, that was an easy choice as HipChat API is pretty straightforward and there is a node library out there to help with it (node-hipchat).
Due to the fact that Cloud Function Google’s documentation is pretty good we will not cover how to build Cloud Functions in this article. We will though show how you can create a scheduled trigger using StackDriver Health Check for your Cloud Function.
First, you need to enable Stackdriver to your Google Cloud Project--ideally the same that you are hosting your Cloud Function. Once you have Stackdriver setup you can open it and find the option called Uptime Checks.
Then, you can add a check to ping your HTTP Cloud Function within an interval that can vary from 1 minute to 15 minutes.
After entering all the details, you can then test it to make sure it is working. Saving it will start the check which will run on a schedule as a cron job would do.
Rise Vision is a big fan of open source; most of our projects are public on GitHub. Thus, this monitoring systems we built, and any enhancements we add, can be found here.
I hope you have enjoyed the read. Please feel free to ask any question, and we will try to get to them as soon as we can.
Please sign in to leave a comment.