I am trying to enable Prometheus endpoint in my springboot project having below dependencies.
SpringBoot version:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.12-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
I am using restTemplate to make outbound call but when i check Prometheus endpoint, the data related with http_client_requests_* are missing
Application properties:
management.endpoints.web.exposure.include=health,metrics,prometheus
management.endpoint.health.show-details=always
management.endpoint.health.enabled=true
management.endpoint.info.enabled=true
management.metrics.web.server.request.autotime.percentiles=0.90,0.95
management.metrics.web.client.request.autotime.percentiles=0.90,0.95
management.metrics.web.client.request.autotime.enabled=true
Just ensure you create your RestTemplate as a spring managed bean to ensure it gets a chance for instrumentation (if not auto created). You can customise with RestTemplateBuilder, and then inject it into the place you need like any other Spring bean.
#Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder.additionalCustomizers(myRestTemplateCustomizer())
.build();
}
And you may also require
<!-- Micrometer core dependency -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
Manual creation (using 'new' within a class) is one cause for it to not link up to metrics.
Related
I am trying to enable Prometheus endpoint in my springboot project having below dependencies.
SpringBoot version:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.12-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
I am using restTemplate to make outbound call but when I check Prometheus endpoint, the data related with http_client_requests are missing
Looking for a solution to fix http_client_requests_ missing issue.
I think you're missing this piece of code in a #Configuration file:
#Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder.build();
}
Which will somewhere downstreams add a MetricsClientHttpRequestInterceptor that produces the actually metrics utilizing a Timer
I want to connect a Spring Boot REST Api project to a MongoDb via aplication.properties file. Why? Because it seems easier to me.
I know how to do this connection with a MySQL db. I have downloaded MongoDb Compass GUI.
application.properties file
spring.data.mongodb.uri=mongodb://localhost:27017/springtest
spring.data.mongodb.username=mihai
spring.data.mongodb.password=mihai
I use uri because I have found that if the MongoDb version is > 3.x.x you should use that. My MongoDb version is 4.4.4
Users collection: link
pom file:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.8</version>
</dependency>
<!--##################################################-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.4</version>
</plugin>
</plugins>
</build>
</project>
UserRepository file:
public interface UserRepository extends MongoRepository<Users, String> {
}
Main application file:
#SpringBootApplication(exclude={SecurityAutoConfiguration.class})
public class AdServicesApplication {
public static void main(String[] args) {
SpringApplication.run(AdServicesApplication.class, args);
}
}
I get the following error trance:
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 0
From my research I found that the problem might be because of the configuration provided in the application.properties file but I don't really know how to write it properly for MongoDb.
For instance if I change the application.properties content to:
spring.datasource.url=jdbc:mysql://localhost:3306/employee_directory?useSSL=false
spring.datasource.username=mihai
spring.datasource.password=mihai
It works perfectly fine.
Thanks!
Try removing the dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
And use the configuration
spring.data.mongodb.uri=mongodb://localhost:27017/springtest
spring.data.mongodb.username=mihai
spring.data.mongodb.password=mihai
When you add the dependency it requires a datasource url that you not provide
remove the spring-data-jpa
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
because you're using a no-relational database (MongoDB) jpa is used only for relational database
and it will work.
I am using Spring Boot with Hystrix for my university project.
The problem I have is when I add Netflix Hystrix dependency to pom.xml file and run the program, It throws an Error called AbstractMethodError : null, but without Netflix Hystrix dependency program runs without any error. How can I slove this?
These are my dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
This is due to dependency mismatch. Application is trying to call an abstractt method but it doesn't find that method. So, it is throwing the null exception.
Use two dependency netflix-hystrix-dashboard and hystrix as below.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
I have integrated spring boot (2.0.3) with Apache ignite (2.7),while starting apache ignite in a embeded mode, It is throwing Null Pointer Exception while creating bean.
With the analysis, i was able to figure out the issue.
Spring boot (2.0.3) internally has dependency on spring (5.0.7) and Apache Ignite on spring (4.3.18).
while creating bean for ignite.cfg, apache ignite is referring the spring (5.0.7) due to priority in pom.xml and is throwing null pointer exception.
Solution I tried
1. I moved the ignite dependency at the begining of pom.xml just above spring boot dependency, that solved the ignite problem, but issues are getting created for spring boot (2.0.3 ) because of older spring(4.3.18) versions
please find the below pom
-----------------------------------------------------
<dependencies>
<!-- Apache Ignite For Cache -->
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.195</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.0.7.Final</version>
</dependency>
<!-- spring-boot web dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<!-- spring-boot thymeleaf dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<!-- spring-boot jpa dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.0.3.RELEASE</version>
<scope>test</scope>
</dependency>
-------------------------------------------------
I need suggestion on below points to tackle the above mentioned scenario.
1.Is apache ignite supports spring (5.x) versions, so that i can exclude dependency from apache-ignite and it can use spring dependency from spring boot ?
Or any other suggestions to tackle this isssue ?
I have a spring boot based project with following declaration in pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
and following dependencies among others
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
But seems like spring boot is not pulling in SecurityEvaluationContextExtension class on the classpath.
Am I missing a dependency or am I using an older version of spring boot?
EDIT:
I directly added the following dependency in my pom.xml and now I can see the class, but STS is showing warning : "Duplicating managed version 4.0.3.RELEASE for spring-security-data"
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-data</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
I am not shure what you mean with 'spring is not pulling in..'
But to use this extension you have to create a bean of this type see
SecurityEvaluationContextExtension
EDIT :
The warning you are getting is no problem. You can try removing the version from the dependency, because it seems available through dependencyManagement.