Reputation: 121
I have an Angular web app (with a backend in Java SpringBoot). Need to build a health check (monitoring) service, which tests that all its services are up and running and shows the status. Let's say it's a sales app, which has services CompanyService, and AccountService with functions like getCompanies(), getAccount(id), updateXXX(), etc. There is something like that on server side (healthz/readyz in Kubernetes). Is it possible to build that service as a unit test, which calls several other unit tests (testing its individual services) using Jasmine/Karma? How can we integrate that in the application, so the user clicks a button, it runs and returns/displays the result in the app? If not, what approach would you suggest? And on stage 2 maybe make it run automatically every minute or so.
Please advise, Oleg.
Upvotes: 0
Views: 3129
Reputation: 4384
There is a difference between Unit tests and a health check/monitoring. As mentioned in the comments, unit tests and integration tests happen before the app is released. You don't want to constantly check the functionality in a live production app, this needs to be done in the build pipeline before deployment.
Health checking, to monitor if your app is still running, is something that does need to be done in production. In case of an Angular app, the health check can simply consist of an external service that calls your app, to see if the HTTP response code returns '200 OK'.
An Angular app is actually static code, Javascript, HTML and CSS, so if the webserver does it's job, the app will run, because everything happens in the browser. So checking if your webserver is still serving up your static page(s) is enough.
To check your backend API(s), a standard way of doing so, is to have a /health
endpoint that does some backend checks (like check to see if your database can be queried, or if all other backend dependencies are up and running) and returning a status. Many monitoring tools will have the option to test these /health endpoints and alert if something is wrong.
Upvotes: 0