Liveness probe failed when using lettuce instead of jedis in spring-starter-data-redis - spring

I have a spring boot application using spring cloud bom : Hoxton.SR1
The app is deployed in a kubernetes cluster.
To connect the app to the redis database I tested 2 different configuration :
Jedis connection pool configuration :
pom.xml :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
application.yml :
spring:
redis:
host: localhost
port: 6379
password: password
database: 0
jedis:
pool:
min-idle: 0
max-idle: 12
max-active: 12
max-wait: 500ms
Deployment in the K8S cluster works well.
Lettuce connection pool configuration :
pom.xml :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--lettuce connection pool-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
application.yml :
spring:
redis:
host: localhost
port: 6379
password: password
database: 0
lettuce:
pool:
min-idle: 0
max-idle: 12
max-active: 12
max-wait: 500ms
Deployment in the K8S cluster DOES NOT WORK, error is : Liveness probe failed: Get http://10.68.13.246:8080/actuator/health: net/http: request canceled (Client.Timeout exceeded while awaiting headers).
What am I missing ?
What could be the root cause of this ?
Is it related to spring actuator or lettuce connector ?

Related

Spring Boot app: Failed to determine a suitable driver class

I tried to connect springboot;
When I run, I get an error "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured."
My pom.xml
<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-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
application.yml
spring:
datasource:
dbcp2:
driver-class-name: com.mysql.cj.jdbc.driver
url: jdbc:mysql://localhost:3306/dbName
username: root
password: ********(pass)
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect
show-sql: true
mysql config
(https://i.stack.imgur.com/RjdYl.png)
Output
***************************
APPLICATION FAILED TO START
***************************
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).
Iam unable to run it
I believe dbcp2 stands in your way. Remove it from YAML
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/dbName
username: root
password: ********(pass)
or follow this:
https://javadeveloperzone.com/spring-boot/spring-boot-common-dbcp2-connection-pool/

Why is my Spring Consul Retry configuration not working

I am trying to use retry functionality in spring consul so that the application fail-fast after certain number of retries.
I am using following bootstrap.yml
spring:
profiles:
active: dev
application:
name: consultest
cloud:
consul:
token: ${token}
enabled: true
host: ${host}
port: 8500
retry:
initial-interval: 5000
max-attempts: 6
max-interval: 600000
multiplier: 3
profiles: dev
Also my pom.xml has following dependencies
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-consul-discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
</dependencies>
I am using springboot version 2.2.2.RELEASE.
The problem is that whenever i start the application and it is not able to connect to consul, it only tries one time and then the application fails
Following is the log,
2023-01-25 09:08:16.245 ERROR 1166405 --- [ main] o.s.c.c.c.ConsulPropertySourceLocator : Fail fast is set and there was an error reading configuration from consul.
2023-01-25 09:08:16.252 ERROR 1166405 --- [ main] o.s.boot.SpringApplication : Application run failed
As you can see the application does not retry.
Am i missing some configuration? Can anyone help with this issue?

Actuator endpoint not showing up

I am trying to add prometheus into my spring boot project. I am using spring boot actuator to expose the metrics endpoint . Did everything following tutorials but I keep on getting a 404 error. I also tried every single solution given in:
Unable to access Spring Boot Actuator "/actuator" endpoint
and
Spring Boot 2 - Actuator Metrics Endpoint not working
My dependecies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.7.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
<version>3.5.1</version>
</dependency>
context.xml (external properties):
<Parameter name="management.endpoints.web.exposure.include" value="*"/>
<Parameter name="management.security.enabled" value="false"/>
<Parameter name="management.endpoints.beans.enabled" value="false"/>
<Parameter name="endpoints.actuator.enabled" value="true"/>
<Parameter name="management.endpoints.web.base-path" value="/actuator"/>
It looks like you missing configuration in your application.yml file (If you use the application.properties file try to change code format):
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: '*'
metrics:
export:
prometheus:
enabled: false
I hope that's help you

Spring boot server startup issue elastic search

I am using elasticsearch7.5. I have turned on the following properties
xpack.security.enabled: true
xpack.security.authc.api_key.enabled: true
I have generated API keys to connect our springboot to elasticsearch.I am using
spring-boot-starter-data-elasticsearch
All my requests are from "RestHighClient" and able to trigger the requests.Only problem is during server startup, they are some errors where it is not able to connect to Elasticsearch.
org.elasticsearch.transport.RemoteTransportException: [ADMIN-PC][127.0.0.1:9300][cluster:monitor/nodes/liveness]
Caused by: org.elasticsearch.ElasticsearchSecurityException: missing authentication credentials for action [cluster:monitor/nodes/liveness]
In pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.8.3</version>
</dependency>
in application properties:
spring.elasticsearch.server=localhost:9200
spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
spring.data.elasticsearch.repositories.enabled=true
Can someone suggest me ,How I can fix it.
Remove these lines from your configuration:
spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
These make Spring Boot to configure the transport client.

How to externalise spring application configuration using config server?

I have written my own config server to centralise configuration management and exposing application configuration using APIs. Now i want to consume configuration properties from spring and spring-boot applications. But i am not able to figure out the correct way for that. I tried placing my config server client code to listen for application context start event and reading configuration from config server. But i am not able to inject this configuration into other beans.
How can i read application configuration from config server (using rest client) and inject this read config to application environment for further processing ?
create an application that for config and your application
#SpringBootApplication
#EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(ConfigApplication.class, args);
}
}
application.yml in config server
spring:
cloud:
config:
server:
native:
search-locations: classpath:/shared
profiles:
active: native
security:
user:
password: pass
server:
port: 8888
and create shared folder in src/main/resources/shared and your-service.yml like this
spring:
security:
basic:
enabled: false
server:
port: 8083
maven pom.xml in config server
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>config</finalName>
</configuration>
</plugin>
</plugins>
</build>
in your-service spring boot application add /src/main/resources/bootstrap.yml
like this
spring:
application:
name: your-service
cloud:
config:
uri: http://localhost:8888
fail-fast: true
username: user
password: pass
and add this dependency to your service
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
first run config server and then your spring boot service

Resources