spring boot + splunk - spring

I have a spring boot app which writes to a log file and uses a splunk forwarder. Everything works fine and my logs appear on splunk. when i upgrade from spring boot version 2.2.5 to spring boot 2.3.4. My logs do not get pushed to splunk.
I have tried downgrading, and the logs start getting pushed to splunk again.
here is a snippet of my yml which handles logging config
logging:
file: myLogs.log
level:
org:
springframework:
web:
filter:
CommonsRequestLoggingFilter: DEBUG

The problem with this was after upgrading spring boot you now need to use a yml structure like this:
logging:
level:
org:
springframework:
web:
filter:
CommonsRequestLoggingFilter: DEBUG
file:
name: server.log
Not forgetting that your java arg for
-Dlogging
needs to change from
-Dlogging.file
to
-Dlogging.file.name

Related

Disable Spring cloud server in spring boot 2.0.0

For one of our customer, who is using Spring Boot version 2.0.0 Release, we have Spring cloud config server with native settings. For local development, we want to disable spring cloud config server so that other spring boot micro-services can use application-local.yml settings.
I tried below options but its not working
Setting spring.cloud.config.enabled=false in bootstrap.yml file
Setting -Dspring.profiles.active="local"
When I run the micro-services, it is still looking for config server. Any inputs.
Can not remove the dependency of config-starter reference in gradle file as a workaround
These are the configurations that worked for me. I'm using Eureka service to find where the config server is.
spring:
cloud:
config:
enabled: false
discovery:
enabled: false
eureka:
client:
enabled: false
to run the local service without loading props from any remote config server you need to disable the bootstrap file and config.
resources/bootstrap.yml --> resources/application.yml
with this springboot will load your application.yml by default.

Spring Boot 2.2.2 - Prometheus not working in Actuator

I've upgraded my Spring Boot application to the latest 2.2.2 Boot version. Since then, I only have a metrics endpoint but no Prometheus.
My build.gradle.kts file has org.springframework.boot:spring-boot-starter-actuator as dependency, I also added io.micrometer:micrometer-registry-prometheus as the reference suggests (Prometheus endpoint).
My application.yml looks like the following:
management:
server:
port: 9000
endpoints:
web:
exposure:
include: health, shutdown, prometheus
endpoint:
shutdown:
enabled: true
Can someone guide me to the right direction?
Edit: It was working in Spring Boot 2.2.0. This is the link to download an identical project: link
Edit 2: I can verify that it works with 2.2.1 as well.
I followed your setup, I created a project from this project loaded Spring Boot 2.2.2.RELEASE, I added the following dependency for Prometheus
implementation("io.micrometer:micrometer-registry-prometheus")
Also I added the following configuration in application.yml
management:
server:
port: 9000
endpoints:
web:
exposure:
include: health, shutdown, prometheus
endpoint:
shutdown:
enabled: true
When the application starts you will see the following info which shows you that 3 endpoints are exposed (health, shutdown and prometheus).
2020-01-05 23:48:19.489 INFO 7700 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 3 endpoint(s) beneath base path '/actuator'
And used Postman for method GET this endpoint http://localhost:9000/actuator/prometheus and it works well. I created a repository by following these steps here So please let me know what error is displayed, or what happens when you don't get the expected result so that I can help and edit this answer.
Add below maven dependency for prometheus
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
In application.yml, add the below configuration
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-components: always
show-details: always
probes:
enabled: true
Now you could see the below message when you restart the server
Exposing 15 endpoint(s) beneath base path '/actuator'
Access the prometheus url: http://localhost:8080/actuator/prometheus

Refreshing Spring Cloud Config from filesystem not working once my app is deployed on docker

I have a Spring Boot application for which I externalized the configuration with Spring Cloud Config so I can modify and refresh its properties on the fly.
Here is my bootstrap.yml :
spring:
application:
name: ${appName:tasky}
profiles:
include:
- native
cloud:
config:
failFast: true
server:
bootstrap: true
prefix: /config
native:
search-locations: classpath:config/{profile}
Updating then refreshing a property (for eg. app.api-key) on my local project works perfectly :
curl -X POST http://localhost:9190/management/refresh
["app.api-key"]
I dockerized my app and tried to achieve the same result from my container, so I tried the following :
sed -i -e 's/oldvalue/newvalue/g' tasky-prod.properties
This correctly changes my file, but when I try to refresh the values in my app (from within the container), my spring boot context is restarted but nothing is picked up from the actuator and the new value is also not used by my app :
curl -X POST http://localhost:9999/management/refresh
[]
What did I do wrong ?

Why Spring Boot app doesn't consume application.yml file?

I have Intellij IDEA 2017.2.5 and few spring boot applications with gradle as a build tool.
For example in one them I have application.yml file with next content:
spring:
profiles:
active: native
application:
name: config-service
management.security.enabled: false
server:
port: 8888
But when I start it from the spring dashboard it doesn't consume the properties file and just uses default values:
Sometimes after rebuild it starts working, but it frustrates me.
Also when I start it from the terminal it works, so it's definitely a problem with Intellij IDEA or/and Gradle.
Is there any solution for this?

Spring Boot + Spring Cloud Config - How to add more profiles from the Git external configuration

I have this configuration in a spring boot application:
spring:
application:
name: my-app
profiles:
active: ${ENVIRONMENT}
cloud:
config:
uri: http://localhost:8888
My config server reads the following files:
my-app-dev.yaml
prop: dev property
my-app-pro.yaml
prop: pro property.
I launch the spring boot app setting -DENVIRONMENT=dev, loading correctly the dev external Git properties.
When I inject the Environment in let's say a controller and do env.getActiveProfiles() I get "dev" as expected.
I would like to add more profiles from the git configuration. For instance:
my-app-dev.yaml
prop: dev property
spring:
active:
profiles: dev,business1
my-app-pro.yaml
prop: dev property
spring:
active:
profiles: pro,business2
So that env.getActiveProfiles() returns ["dev","business1"]. However what it returns is the initial "dev".
How could this be done?
UPDATE:
As suggested by Dave Syer I tried using spring.profiles.include in the Git files but the new profiles aren't added to the Environment:
my-app-dev.yaml
prop: dev property
spring:
profiles:
include: business1
my-app-pro.yaml
prop: dev property
spring:
profiles:
include: business2
environment.getActiveProfiles() ---> "dev"
Update your spring-boot to 1.5.4.
I tested the same case on my Mac, I found that spring with different version behaves different.
When I'm using Spring Boot 1.3.8.RELEASE with Spring Cloud Brixton.SR7, I got the [dev] profile as active profile(also with Spring Boot 1.4.5.RELEASE)
When I'm using Spring Boot 1.5.4.RELEASE with Spring Cloud Dalston.SR1, I got the
[business1, dev] profile as active profile
So I believe it is a bug in Spring Boot 1.3.x and 1.4.x

Resources