By Paul Scanlon

What Is the CockroachDB Cloud API?

Project Overview

My first task after joining Cockroach Labs was to design and build something that demonstrates the capabilities of the new CockroachDB Cloud API. I read the docs, tested out some endpoints and my mind went immediately to, ā€œDashboardā€.

The snag however is, CockroachDB already has the Cockroach Cloud Console which can be used to create new Clusters and perform a number of operational tasks. So, I needed an angle.

Problem

Like most, if not all Cloud UI interfaces they cater for customerā€™s most common needs and often require user authentication. User authentication typically comes in the form of ā€œpaid for seatsā€ which means thereā€™s usually only a few folks who can access what might actually be some super helpful information.

Solution

The solution to this is of course, make this information publicly available, and without authorization. By using the CockroachDB Cloud API you can authorize the application, rather than the user, and choose which information to surface publicly. Creating an app that lives on a live URL means anyone with the link can see whatā€™s going on with your database infrastructure, (without first needing to navigate the painful internal processes of requesting access).

Insight

When thinking about database infrastructure itā€™s fair to assume only the super technical would ever need to know the details but, when you introduce FinOps (folks in charge of spend budgets etc) it becomes crystal clear that the cost of infrastructure would absolutely be something that decision makers would want to be aware of!

The Idea

Using Next.js I securely make server-side requests to the CockroachDB Cloud API, retrieve the required information then, display it in user friendly way. I also mutate one of the endpoints and add up the total spend for each cluster to provide a quick way for FinOps to determine monthly costs.

Dashboard

ā€¦ but wait thereā€™s more.

Using NextAuth I created what Iā€™m calling conditional authorization. NextAuth is free (Open Source) and can be hooked up via GitHubā€™s oAuth apps (also free) and can be used to determine levels of access based on a users email address.

Admin Access

In this demo app I gave myself and Rob the role of Admin. With Admin access to the app we can perform operational updates to the infrastructure right there in the same UI. An Admin user could be given control to increase or decrease spend limits or, the ability to create or delete databases.

Admin Access

User Access

A non Admin user isnā€™t permitted the same level of access but can still see all this information, they just canā€™t change it.

User Access

Video Walk through

Hereā€™s a short video by my colleague Rob Reid that explains a little more about how this works.

Blog

Or, if youā€™d prefer, hereā€™s a full write up about the project: What is the CockroachDB Cloud API and why should you use It?

Further Reading