Export Prometheus Metrics for Spring Boot Application in Kubernestes using Sidecar/ Adapter Pattern

884 Views Asked by At

Hi All I'm working on designing a Kubernetes sidecar / Adapter pattern for the Spring Boot Application to export Prometheus metrics, I am aware that we can use maven dependency io.micrometer:micrometer-registry-prometheus to expose Prometheus metrics directly. However, with my limited knowledge, I got to know adapter/sidecar patterns we can extend apps in Kubernetes without changing the code. Being new to the Kubernetes concept I am struggling to figure out whether it can be achieved to adapter/sidecar pattern or not. With my research, I find out example to expose Elasticsearch Prometheus metrics using adapter pattern example where Elasticsearch does not support natively exporting Prometheus metrics.

I need help with the following points

  • Since Spring Boot provides a way to export Prometheus metrics using a micrometer, is it the correct approach to use a sidecar/adapter pattern to export metrics?
  • if yes can you please guide me on how can we achieve this using the sidecar/adapter pattern in Kubernetes?
  • any example would be great help.
1

There are 1 best solutions below

1
On

One way of accomplishing this is using a solution such as Open-Telemetry. You can choose to auto-instrument your application using OTEL agents and corresponding collectors (that run as a side-car application)

An example of this for the Java Petstore is here : https://signoz.io/blog/opentelemetry-spring-boot/

While this is not for Prometheus , you get the idea of this. In place of the Signoz exporter here , you can export it to the Prometheus sink and auto instrument & also trace your application