DEV Community

Cover image for Monitoring gRPC Uptime
Eric Hacke
Eric Hacke

Posted on • Originally published at asserted.io

Monitoring gRPC Uptime

Uptime monitoring for gRPC can't be done with traditional HTTP checks. With Asserted you can write sophisticated external health checks using the gRPC client and Mocha.

Example on GitHub

gRPC is an open source, high performance RPC framework that uses protocol buffers to efficiently serialize structured data between servers and clients in dozens of languages.

The specialized interchange format that makes it highly performant is also means that a gRPC server usually requires a specialized client to communicate, regular HTTP libraries won't work. As a result, Asserted is uniquely suited to providing the custom environment needed to externally monitor gRPC uptime and stability.

The example code used in this walk-through is heavily based on the Node example provided here.

Example Server

The proto definitions that this server will use are shown below, and are taken directly from the official gRPC Node example mentioned above.

The gRPC server that the example tests will run against is described in this file. It's too large to show here in it's entirety, but I'll summarize the major elements.

The server exposes four RPCs:

  • a simple RPC for getting a single object
  • a server-side streaming RPC to retrieve a list
  • a client-side streaming RPC to record a series of events
  • and a bi-directional RPC to provide a simple chat function

Routine Configuration

The routine.json makes use of custom dependencies. Custom dependencies are available on paid plans, and here we're using that option to include the Socket.IO client library in our tests.

Routine package.json

The package.json for the routine (inside the .asserted directory) is slightly different than the default in this case because of the custom dependencies. In this case we're adding a few convenience libraries as well as @grpc/proto-loader, google-protobuf, and grpc.

Continuous Integration Tests

To start off, we create a gRPC client based on the same proto as the server.

Then we use that client to perform tests against each of the four RPCs we defined earlier.

The simple RPC just retrieves a single object and asserts that it matches what is expected.

From the client side, the list RPC (streaming on the server-side) looks fairly similar to the simple RPC above.

The client-side streaming RPC sends a number of points to the server, and asserts the result.

And finally the bidirectional RPC sends a series of notes to the server which responds once the call is ended.

Next Steps

While the example shown here can be cloned and run locally without an account, you'll need to do a few extra steps if you want to create your own Asserted routine to integration test your API in production.

  1. Create an Asserted account. It's free and easy.
  2. Complete the 2 minute onboarding to ensure that your environment is ready. You can also reference the docs here.
  3. Start writing and running tests in prod!

Top comments (0)