Skip to content

kaihendry/slo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Service Level Objective (SLO) tutorial for Kubernetes 🐢

Goal is to show how to derive a Service Level Objective measure on a Kubernetes service "slo" using Prometheus metrics.

SLOs help teams create API performance goals and measure how well they are meeting those goals.

The three pillars of observability are logs, metrics, and traces. The aim of this code is to show how metrics are instumented, exported (kind: LoadBalancer), scraped (kind: PodMonitor) and queried (Prometheus Operator).

Quickstart

  1. brew install colima hey helm - install the tools
  2. Give colima a bit more memory than defaults: colima start --cpu 4 --memory 8
  3. Start Kubernetes cluster: colima kubernetes start
  4. Install the kube-prometheus-stack
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install tutorial prometheus-community/kube-prometheus-stack --set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false
  1. kubectl apply -f k8s/deploy.yaml to deploy the "slo" service
  2. Export prometheus service to localhost: kubectl port-forward service/tutorial-kube-prometheus-s-prometheus 9090:9090
  3. Expose slo level 4 load balancer to localhost: kubectl port-forward svc/slo-service 8080:8080
  4. hey http://localhost:8080/ - generate 200 requests to the service
  5. hey "http://localhost:8080/?sleep=500" - simulate 200 SLOW 🐢 responses frim the service

With a Application Performance Index aka SLO query in Prometheus:

sum(rate(request_duration_seconds_bucket{le="0.3"}[5m])) by (job)
/
sum(rate(request_duration_seconds_count[5m])) by (job)

Documentation on these queries

It should say 50% (0.5) of requests are under 300ms in the last 5 minutes. You might need to be patient for the metrics to appear, as the /metrics endpoints might not have been scraped by Prometheus yet.

image

Other resources

Acknowledgements

shad and SuperQ on the Libera IRC #prometheus channel for helping.