Skip to content
This repository has been archived by the owner on Nov 10, 2021. It is now read-only.

Event Loop Utilization Metric exporter and K8S HPA

Notifications You must be signed in to change notification settings

nearform/fastify-elu-scaler

Repository files navigation

fastify-elu-scaler

This readonly repository contains sample code accompanying the published blog post Event Loop Utilization with HPA. For demonstration purposes only and not to be used in production.

Prerequisites

To deploy this example of an evelt loop utilizer you need already access to an up and running kubernetes cluster. This could be for example kinD or minikube for testing compose but any cluster is fine. Also needed is Helm 3 to be installed to deploy required tools into kubernetes like Prometheus and Grafana as well as CRDs of Keda

Do not forget to setup your kubeconfig environment variable correctly to point to the right cluster

export KUBECONFIG=${PATH_TO_YOUR_KUBECONFIG}

Prometheus/Grafana

Let's have Prometheus and Grafana to be installed to monitor and visualize our ELU metric

$ kubectl create -f manifests/setup
$ kubectl create -f manifests/

Keda

We want to use Keda to auto scale our Pod

$ kubectl create namespace keda
$ helm repo add kedacore https://kedacore.github.io/charts
$ helm repo update
$ helm upgrade -i keda -n keda --create-namespace kedacore/keda

Build

We provided an simple nodejs app including a Dockerfile to build an container image exposing a metric endpoint for ELU.

$ docker build -t elu:latest .

Make sure your Docker image is accessible from within your Kubernetes cluster.

Deploy

To deploy our application and scaler to Kubernetes we prepared some manifest files.

$ kubectl create namespace elu
$ kubectl apply -f manifests/

How it works

By default, we defined a threshold of 20 for up-/downscaleing in scaledObject.yaml which is related to the average over all percentiles of our ELU metric, factorized by 100.

triggers:
  - type: prometheus
    metadata:
      metricName: event_loop_utilization
      threshold: '20'
      serverAddress: "http://prometheus-k8s.monitoring:9090"
      query: 100*avg(event_loop_utilization{service="elu"})

After deployment is done, you open your Grafana via Proxy forwarding and watch your Pod and the ELU metric.

$ export POD=$(kubectl -n monitoring get pod -l app.kubernetes.io/component=grafana --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
$ kubectl -n monitoring port-forward $POD 3000:3000

You can now visit http://localhost:3000/explore and watch the pod ELU.

To trigger your auto scaler you can use apaches benchmark tool ab

$ kubectl run -it --rm --image=piegsaj/ab bench -- -c 20000 -n 100000 http://elu.elu:3000
$ kubectl -n elu get pods --watch

About

Event Loop Utilization Metric exporter and K8S HPA

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •