Integration of Resilience 4j and Prometheus - microservices

How to integrate Resilience-4J and Prometheus with micro-services.
I have integrated Micro-services with resilience 4j and also with Prometheus .
My problem is ,in Prometheus i am not getting any resilience query,only HTTP and other which comes default are populating .
Kindly help
Steps that i have implemented so far are listed below...
1>created micro-services
2>Integrate micro-services with Resilience 4j by following steps
i>dependency in pom.xml file
ii>created separate class of Circuit-breaker and retry module.
iii>After that i have added Prometheus by adding its jar
which is...
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
3>In Prometheus Dashboard resilience queries/matrices are not populating.
i.e # HELP resilience4j_circuit-breaker_calls Circuit Breaker Call Stats
# TYPE resilience4j_circuit-breaker_calls gauge
resilience4j_circuit-breaker_calls{name="backendB",call_result="successful",} 0.0
resilience4j_circuit-breaker_calls{name="backendB",call_result="failed",} 0.0
Kindly help.
Thanks in Advance
i have also added below dependencies for resilience 4j and Prometheus integration...
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-metrics</artifactId>
<version>0.16.0</version>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-prometheus</artifactId>
<version>0.16.0</version>
</dependency>
want resilience matrices on Prometheus dashboard.

Do you use a Framework like Spring Boot 1 or Spring Boot 2?
If that's the case you can have a look at our demo which also includes a Grafana Dashboard for Prometheus.
https://github.com/resilience4j/resilience4j-spring-boot2-demo
If you want to use Micrometer you should not add resilience4j-prometheus or resilience4j-metrics. resilience4j-prometheus uses the Prometheus Java library and resilience4j-metrics uses Dropwizard Metrics.
You should add resilience4j-micrometer instead. But it's not necessary if you use our Spring Boot 2 starter.

Related

Specify sampler probability using annotations or programmatically using Spring Cloud Sleuth?

We're using Spring Boot 2.7.0, Spring cloud 2021.0.3 in GCP and have added these dependencies:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-trace</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-logging</artifactId>
</dependency>
We have specified the generic sample probability in our properties file like this:
spring.sleuth.sampler.probability=0.1
spring.sleuth.web.skipPattern=(^/admin/.*|.+favicon.*|^/ping$)
But for some methods we'd like to use a different sampler probability (e.g. we always want to generate a trace for some methods).
Questions:
Is it possible to specify the sample rate probability of a method when using annotations from the Spring Sleuth (or related) projects?
If not, is it possible to specify the sample rate probability of a method programmatically (without annotations)?
If not, is it possible to configure different sample rates in the spring property file / yaml file?
You can create a bean of type org.springframework.cloud.sleuth.exporter.SpanFilter. There you have access to FinishedSpan basing on which you can return true if you want to export the span or not.

Spring: spring-data-mongodb or spring-boot-starter-data-mongodb

Which's the difference between
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
and,
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
I'm developing an spring boot service.
spring-boot-starter-data-mongodb contains configuration classes for Spring Boot. It also includes the spring-data-mongodb library so you would only need to include the start in your boot app:
https://search.maven.org/artifact/org.springframework.boot/spring-boot-starter-data-mongodb/2.0.5.RELEASE/jar
spring-boot-starter-data-mongodb is a spring boot starter pom. For more information on starters:
spring-boot-starters
Dependency management is a critical aspects of any complex project. And doing this manually is less than ideal; the more time you spent on it the less time you have on the other important aspects of the project.
Spring Boot starters were built to address exactly this problem. Starter POMs are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need, without having to hunt through sample code and copy paste loads of dependency descriptors.

Spring Initializer - Zipkin Server missing?

Can't see Zipkin Server when using Spring Initializer . Has it been removed? What is the alternative?
Zipkin Server is not part of Spring initializers. You have to use the official release of the Zipkin server
https://github.com/openzipkin/zipkin#quick-start
And custom servers are not supported anymore meaning you can't use #EnableZipkinServer anymore since 2.7
https://github.com/openzipkin/zipkin#quick-start
Lately I have been trying the same and couldn't find that option in initializer. I am just posting this if anyone encounters the same issues and lands on this page. You can refer below sample GitHub project which is consists of four micro services ( zipkin server, client, rest service, and Eureka ) using Edgware release with latest version of sleuth.
Sample Zipkin Server/Client
Create spring starter project and add the below dependencies manually.
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>2.12.0</version>
</dependency>

spring actuator for standalone spring boot application

we have standalone spring boot application which triggers some quartz jobs based on triggers. it is standalone jar file , no application server involved.
i am planning to add Spring actuator to it. is it possible to add actuator to spring boot application which is not running on any application server.
i did search in google and spring.io website but haven't found any relevant info. if i can add can someone help me how to do it or any link for documentation.
Thanks
Try adding the spring-boot-starter-web dependency to your pom.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
I had the same issue and this resolved it for me.

Spring Boot Deployment Strategy

Am implementing the swagger 2 using Spring Boot. Using Dependencies-
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
It works good. But want to implement swagger in such a way that in production
swagger does not get deployed. Also will it be possible to host the swagger build differently than the application build on different host machines?
There are two approaches to do this.
Maven profile
By intrudue a maven profile like 'swagger' and add the springfox-swagger-ui related depdencenty to this maven profile. As maybe you need to use some swagger annotations in the java code, so it cannot eliminate the springfox-swagger2 dependency.
Spring profile( should be more better than option 1 )
For a standard spring-boot swagger2 config class, for example you can add the #Profile("swagger") annoation to enable the swagger2 integration only when add the spring.profiles.active=swagger in app running.
For the different host machines, I has no idea about that, but as my understanding, swagger will select all the spring boot endpoints so suppose you cannot leave them alone. But there is a library which can provides a way to publish springfox-swagger2 on spring boot actuator. so you can add management.port=8181 property in application.properties to makes spring-boot-actuator run on another TCP port.

Resources