Most of the time it is handy to find all the log messages created as a result of a user action, service request or message. To achieve this it is best practice to add a correlation ID to every message. A correlation ID is a number or string that is the same for all log messages of a user action, service request or message but different for different user actions, service requests or messages. With that it is possible to filter the log messages. This uniqueness can be achieved by using a UUID as correlation ID.
The correlation ID is generated when a new user action, service request or message occurs. In distributed systems it is important to pass the correlation ID to called service to be able to find the log messages for the complete system.
For HTTP calls this is usually done in the header field X-Correlation-Id. For messaging systems like queues or service busses there is usually a special file in the message header to store the correlation ID.
This short guide shows how to build an observability stack using Grafana, Prometheus, Tempo and Loki.
The prerequisite is a spring boot app that is previously containerized with docker.
You also need Kubernetes installed, which comes with Rancher Desktop.
Helm should also be installed.
The following graphic shows how a Grafana stack is usually built up. Several services are used for this.
Build up the following folder-structure in your application-project:
├──/project-folder | ├──/kubernetes | ├─────/loki | | └──/loki.yaml | ├─────/prometheus-grafana | | └──/chart.yaml | | └──/values.yaml | ├─────/promtrail | | └──/promtrail.yaml | ├─────/springboot-app | | └──/springboot-app.yaml | ├─────/tempo | | └──/tempo.yaml | └──/springboot-app | ├──/source | | └──/main | | └──/test | └──...
We add the charts we need for our services and update the Helm repository:
helm repo add grafana https://grafana.github.io/helm-charts
helm repo updateAfter we have done this, we will create a namespace for the observability tools. To do so, go to the shell and type in:
kubectl create ns observabilityTo install Promtail, run:
cd promtail
helm upgrade --install promtail grafana/promtail -n observability -f promtail.yamlDeploy Loki inside the cluster:
helm upgrade --install loki grafana/loki-distributed -n observabilityWe are interested in the loki-loki-distributed-gateway service by Loki in order to get the logs send. Grafana also needs that as a datasource.
To install Tempo as a prerequisite we need to install minio. This is a tool that helps us to simulate an AWS Object Storage s3 service.
cd ../tempo
kubectl apply -f minio.yamlTo deploy Tempo, run:
helm upgrade --install tempo grafana/tempo-distributed -n observability -f tempo.yamlhelm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo updateafter that, run:
cd ../prometheus-grafana
helm dependency update
helm upgrade --install kube-prometheus-stack -n observability .The following command
helm ls -n observabilitywill show us this
kubectl get svc -n observabilitywill give us a list with all deployed services on our created namespace which we called observability.
After done this, we have to deploy our Springboot-Application on Kubernetes. For that, go to the springboot-app/ directory and run the kubectl command:
cd ../springboot-app
kubectl apply -f springboot-app.yaml|
Note
|
You can name the yaml-file anything you like, e.g.: deployment.yaml |
After successul deployment on Kubernetes, point out the external ip-address, on which the springboot-app run with:
kubectl get deploy,svc,cm -l app=springboot-appand obtain out the port for Grafana running:
kubectl get svc -n observabilityThe Springboot-Application can be tested via the URL: http://EXTERNAL-IP:8080/ENDPOINT
Grafana should be accessed with: http://EXTERNAL-IP:PORT-FOR-GRAFANA


