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.
ā¦ 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.
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.
Video Walk through
Hereās a short video by my colleague Rob Reid that explains a little more about how this works.
.@PaulieScanlon wanted to go above and beyond what the CockroachDB Cloud Console could do. So he used the Cloud API to build a demo dashboard using @nextjs and @nextauthjs.
— CockroachDB (@CockroachDB) April 6, 2023
š Preview: https://t.co/ikGpKoTFlx
š» Blog: https://t.co/w3XudLVVIl
āļø GitHub: https://t.co/8EnQFFzyg3 pic.twitter.com/xRyPe9w4LH
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?