YURI GRINSHTEYN: We've seen how to create service level
objectives for services running on GKE.
But what if your services aren't?
Today, I'm going to show you how to create custom services
and define SLOs to measure their reliability.
This is The Stack Doctor.
[MUSIC PLAYING]
As we covered in our earlier episode,
services running on GKE are automatically
discovered by SLO monitoring, if you were
using the Istio service mesh.
If you're not, you can easily select GKE entities
and create services against them.
If your services aren't on GKE, you
need to define them as custom services.
As you can see, you're not limited
to just the out-of-the box service types and service
monitoring.
You can create custom services.
You have two options.
You can use the API directly, or you can use an automation tool
like Terraform.
Once the service is created, you can then
use the UI to create SLOs against it.
Let's take a look at the API method first.
To invoke the API, make a POST request of the services
endpoint within your project, specifying the service
ID as a parameter.
The body of the request should contain the name
you'd like to see in the UI.
And there you are.
Now that the service has been created,
you can use the UI to create an SLO against it.
Note that you have to specify "other" as the metric
for your SLI.
This is a custom service, and there
is no automatic measure of performance or availability
for it.
As such, you need to have a good SLI for the service.
For a start, you might be able to use a metric admitted
by the Google Cloud load balancer, such as request
count.
Otherwise, you want to instrument
your service to admit SLIs.
For an example, take a look at our earlier episode
by using OpenTelemetry to do just that.
As you can see, creating a custom service
using an API call is pretty straightforward.
From there, you could use the API or the UI
to define your SLO.
But what if you want to automate this process?
This is where Terraform comes in.
You may remember that we covered using Terraform to create
monitoring configurations like uptime checks,
dashboards, and the learning policies
in the previous episode.
If not, no worries.
We'll link to that episode below.
To quickly bring you up to speed,
Terraform is an open source tool that
allows us to define infrastructure and monitoring
configurations as code.
That includes defining services and SLOs.
Here's how you can define a service and an SLO against it
in Terraform.
Let's walk through the code together so that it's clear.
First, define the basics.
Specify Google Cloud as the provider,
and define your service.
For the service, you just need to provide a service
ID that's unique to your project and a display name.
Next, define the SLO.
Specify an ID for it and a display name.
Next, specify whether you want to use a request-based
or a windows-based SLI.
Then, specify the metric you want to use as your SLI.
And finally, determine how you'd like the SLI to be evaluated.
Note that I'm just using a single metric in this example.
For a request-based SLO, you might have separate metrics
that you want to use to represent
total requests and good requests or perhaps the same metrics
with different filters applied.
Both of those are absolutely supported
by SLO monitoring to allow you to calculate a ratio.
The final step is to define your target or goal, expressed
as a fraction that should be less than 1,
and your compliance period as either a rolling or a calendar
window.
Once your definition is done, run the "terraform plan"
command to validate your configuration
and make sure that the two resources will be created--
your service and your SLO.
Finally, run "terraform apply" to actually create
the resources.
Confirm that you want to do this at the prompt,
and verify that the two resources you wanted got
created.
Return to the console, and verify
that your service was created and that it
has an SLO defined against it.
In the services detail screen, make sure
that your service is currently compliant with your SLO,
if that's what you expect.
Thanks for joining me today.
We learned how to define custom services using the API
and Terraform and how to automate setting up
SLOs against our services.
Now you are ready to start defining your own services
and setting SLOs against them.
Thanks for watching, and come back soon for more.
This is The Stack Doctor.
Stay healthy out there.
[MUSIC PLAYING]