Sleuth can't send traces to zipkin. Exportable always false - spring-boot

When i run my spring boot application locally i always have trace information with exportable information = true
[my-service-v1,d074fc20fbfe0615,d074fc20fbfe0615,true]
but when app running on AWS ECS in docker container i have always exportable false for all logs
[my-service-v1,2fa3d680aaf0d41f,2fa3d680aaf0d41f,false]
except classpath org.hibernate. On this classpath exportable = true
I use below dependencies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
And below properties :
spring:
zipkin:
base-url: http://zipkin-server
discovery-client-enabled: true
enabled: true
sleuth.sampler.probability: 1.0
Which may be the reason for different actions ? Maybe log levels ?
base-url: http://zipkin-server must be reachable ?

Related

Spring Cloud Configuration Server leaks GIT environment via actuator endpoints

I am setting up a Spring Cloud Configuration Server. Just few dependencies and an annotation. The source of properties comes from git. Server has the actuator enabled with default basic settings. I am surprised that the actuator unexpectedly reacts to any (even nonexisting endpoints) and reveals full environment (git property source) which is also used to store secrets.
pom dependencies:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>cz.leveland</groupId>
<artifactId>actutest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>actutest</name>
<description>Actuator test</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2021.0.3</spring-cloud.version>
</properties>
<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>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
application.properties:
server:
port: 8080
spring:
application:
name: CONFIG-SERVER
cloud:
config:
server:
git:
uri: https://bitbucket.org/repo-name/actuator-test
clone-on-start: true
username: repouser
password: xxxxxxxxxx
default-label: master
encrypt:
keyStore:
location: classpath:/server2.jks
password: letmein
alias: mytestkey
secret: letmein
management:
endpoints:
web:
exposure:
include: "health"
Spring application:
#EnableConfigServer
#SpringBootApplication
public class ActutestApplication {
public static void main(String[] args) {
SpringApplication.run(ActutestApplication.class, args);
}
}
git application.properties contains encoded password:
spring.datasource.username=admin
spring.datasource.password={cipher}AQA50Mh4...
NOW THE PROBLEM
The server responds to ANY actuator endpoint like .../actuator/foo-bar and always returns the full git property source (example bellow).
When I remove #EnableConfigServer annotation the actuator starts working as expected. So this "feature" must be activated with spring cloud config server.
Server response to .../actuator/foo-bar:
{
"name": "actuator",
"profiles": [
"foo-bar"
],
"label": null,
"version": "da200e047354e889e6503b10cbb9cbbc7e3dbb28",
"state": null,
"propertySources": [
{
"name": "https://bitbucket.org/repo-name/actuator-test/application.properties",
"source": {
"spring.datasource.username": "admin",
"spring.datasource.password": "secret-password"
}
}
]
}
I must be doing something terribly wrong or is this a security bug?
Thank you for helping me.
Test project https://github.com/Klapsa2503/actuator-test
Actuator metrics not working
Change
management:
endpoints:
web:
exposure:
include: "health"
to
management:
endpoints:
web:
exposure:
include: "health,metrics"
so metrics are exposed and http://localhost:8080/actuator/metrics working
Endpoint leaking properties
By default spring config is exposing default properties from application.properties from your config repository. Spring config server has a strict naming convention that you should follow to prevent that. See https://www.baeldung.com/spring-cloud-configuration
Just change application.yml to something different and those properties will not be exposed.
Tried to find the code responsible for fetching those configs and the logic behind it but simply don't have time for this ConfigDataEnvironment::processAndApply

Duplicate key Endpoint exception while starting - in Spring Boot Admin Client

I'm trying to configure Spring Boot Admin Client but i'm start the client application not able to register with Server. While starting of the application I'm getting the below exception.
java.lang.IllegalStateException: Duplicate key Endpoint(id=threaddump, url=http://localhost:9082/client-web/management/actuator/dump)
i'm using dependency version of client same version which I have used it for Spring Boot Admin Server
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.1</version>
</dependency>
what's causing the issue?
It was the known bug in 'Spring boot admin 1.x'. But has been fixed in the later version (2.0.2).
Endpoints list is obtained from the AdminServerProperties class and defaults to
{
"health", "env", "metrics", "httptrace:trace",
"httptrace","threaddump:dump","threaddump", "jolokia", "info",
"logfile", "refresh", "flyway",
"liquibase", "heapdump", "loggers","auditevents"
};
The problem with the duplicate key seems to be caused by the presence of both "httptrace:trace" and "httptrace" (and similarly for threaddump)
Overriding this in config by adding the line seems to solve the problem.
spring.boot.admin.probed-endpoints: [ "health", "env", "metrics", "httptrace:trace", "threaddump:dump", "jolokia", "info", "logfile", "refresh", "flyway", "liquibase", "heapdump", "loggers", "auditevents" ]
Pls see this for more: https://github.com/codecentric/spring-boot-admin/issues/828
Alternatively, you can update pom.xml as below
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.2 or above</version>
</dependency>

Do Spring LDAP and Spring Cloud Consul work together?

I had a project with Spring LDAP in place. I am trying to put in Spring Consul into this project and have been facing issues with respect to it.
Here is the pom.xml :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
Here is application properties :
#consul properties
spring.cloud.consul.config.format=PROPERTIES
spring.cloud.consul.discovery.healthCheckPath=/<root>/health
spring.cloud.consul.discovery.healthCheckInterval=15s
spring.application.name=<App_Name>
spring.profiles.active=dev
And I enabled discovery client using #EnableDiscoveryClient on SpringBootApplication class.
But, I am ending up with this error and the app never starts :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field ldapTemplate in com.<package>.config.LdapClient required a bean of type 'org.springframework.ldap.core.LdapTemplate' that could not be found.
- Bean method 'ldapTemplate' not loaded because #ConditionalOnClass did not find required class 'org.springframework.data.ldap.repository.LdapRepository'
Action:
Consider revisiting the conditions above or defining a bean of type 'org.springframework.ldap.core.LdapTemplate' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:62703', transport: 'socket'
I figure it has something to do with autodiscovery of Ldap and introducing Consul is causing this issue, but, I am not able to pin-point the problem.
Can someone please help me resolve this issue?

Eureka client exception com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

I am new to microservices. I'm trying to create one small application for learning purpose. Here is my code:
EurekaServer - application.yml
spring:
application:
name: EurekaServer
server:
port: 8080
servlet:
context-path: /EurekaServer
eureka:
client:
fetch-registry: false
register-with-eureka: false
Eureka Server is working fine and I am able to see the dashboard at http://localhost:8080/EurekaServer
EmployeeClient: application.yml is below:
spring:
application:
name: EmployeeClient
server:
port: 8586
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8080/EurekaServer
In last line I need to write serviceUrl explicitly as on pressing ctrl+space in sts it doesnot show option serviceUrl but it shows service-url, hyphen sign. And same with defaultZone. Am I missing some jar or specific version?
My EmployeeClientApplication.java
#EnableEurekaClient
#SpringBootApplication
public class EmployeeClientApplication {
public static void main(String[] args) {
SpringApplication.run(EmployeeClientApplication.class, args);
}
}
when I try to run EmployeeClientApplication.java it gives me below exception:
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
I also tried using #EnableDiscoveryClient in place of #EnableEurekaClient, but with no luck.
A part of EmployeeClient pom.xml is below:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<dependency>
Where I'm making a mistake?
I think, you will have to change default Zone in client property from /EurekaServer to /eureka
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8080/eureka
"/eureka" is the rest endpoint to register services to eureka registry.
Make the changes and try, it should work.
In addition to this, if you are willing to change the UI dashboard url you should use eureka.dashboard.path property.
I had to use below line in EmployeeClient application.yml
defaultZone: http://localhost:8080/EurekaServer/eureka
Adding eureka.instance.hostname=localhost can solve your issue, if you have added DiscoveryServer as the application name in the server's application properties file.

Unable to connect to Command Metric Stream for Hystrix Dashboard with Spring Cloud

I have microservices project with Spring Cloud, the snippet from parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
All services are running under Eureka server:
All services are running fine. I can call make appropriate calls with Postman and everything works fine.
I have separate service which handles Hystrix dashboard, a snippet from pom:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
Configuration main class:
#SpringBootApplication
#EnableHystrixDashboard
public class DashboardApp {
public static void main(String[] args) {
SpringApplication.run(DashboardApp.class, args);
}
}
and config yaml file:
spring:
application:
name: Dashboard
server:
port: 8000
eureka:
client:
fetchRegistry: true
registerWithEureka: false
serviceUrl:
defaultZone: http://localhost:8761/eureka
I have next dashboard looking:
Full stack trace from the console is here. Following is some snippet:
2018-04-12 11:28:25.089 ERROR 15762 --- [qtp295055909-16] ashboardConfiguration$ProxyStreamServlet : Error proxying request: http://localhost:8082/hystrix.stream
java.lang.RuntimeException: org.eclipse.jetty.io.EofException
at org.springframework.cloud.netflix.hystrix.dashboard.HystrixDashboardConfiguration$ProxyStreamServlet.doGet(HystrixDashboardConfiguration.java:208)
....
Caused by: org.eclipse.jetty.io.EofException: null
...
Caused by: java.io.IOException: Broken pipe
...
Service itself is accessible with spring actuator:
snippet from it's pom:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Config class looks:
#EnableHystrix
#EnableEurekaClient
#SpringBootApplication
public class TableApp {
public static void main(String[] args) {
SpringApplication.run(TableApp.class, args);
}
}
How to solve this issue?
For those who are using spring boot 2, the hystrix.stream endpoint has been moved to /actuator/hystrix.stream.
For me this url worked:
http://localhost:8082/actuator/hystrix.stream
And yes, have this actuator endpoint enabled via following property:
management.endpoints.web.exposure.include=hystrix.stream
Of course you must have the actutator dependency included in your project.
Hystrix dashboard itself can't be used for monitoring several instances at once. The thing that you need is turbine+dashboard. In a couple of words turbine is an aggregator for several hystrix metrics streams.
Configuration of instance:
management:
endpoints:
web:
exposure:
include: hystrix.stream, info, health
spring:
application:
name: WRITING
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
The important thing here is to expose hystix.stream actuator. This endpoint will be used by the turbine to read metrics. Also, do not forget to add actuators starter.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
If you did everything correctly http://localhost:8080/actuator/hystrix.stream endpoint should become available.
Turbine config will look like:
server:
port: 8888
spring:
application:
name: TURBINE
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
turbine:
appConfig: WRITING,READING
clusterNameExpression: new String('default')
In appConfig, you should specify service names for monitoring.
After starting turbine localhost:8888/turbine.stream will be available.
You can pass this URL to the dashboard and monitor all data aggregated for hystrix commands of discovered instances.
Github project example.
p.s.
Dependencies that you have used are deprecated. Please check maven repo
I was able to solve this issue for the spring-boot-starter-parent version 2.0.7.RELEASE and spring-cloud-dependencies version Finchley.SR2 by adding below two properties in the application.properties.
management.endpoints.web.exposure.include=*
management.endpoints.web.base-path=/
Finally, I found the solution.
Problem was that Controller API has to be market by HystrixCommand annotation.
Snippet from a documentation:
Turbine AMQP by Spring Cloud offers a different model where each
application instance pushes the metrics from Hystrix commands to
Turbine through a central AMQP broker.
I added it without any parameters to all Controller's methods, like following:
#RestController
#AllArgsConstructor
public class GuestController {
private DinnerService dinnerService;
#HystrixCommand
#PostMapping("/dinner")
public Integer startDinner(#RequestBody List<Integer> menuItems) {
return dinnerService.startDinner(menuItems);
}
#HystrixCommand
#DeleteMapping("/dinner/{tableId}")
public void finishDinner(#PathVariable Integer tableId) {
dinnerService.finishDinner(tableId);
}
}
And now all works like charming:
Now I understand that I was so close to it.
Make sure you have added this in your application.properties.
hystrix.dashboard.proxy-stream-allow-list=localhost
I had the same issues with the latest version of Spring-boot(2.3.3-XXX) and spring-cloud (Hoxton.SR7) but when I did the downgrade the version in pom.xml file then it starts working fine for me.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.16.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
and
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR6</spring-cloud.version>
</properties>
Hope, this would be helpful :)
Correct your hystrix.stream url to http://localhost:8082/actuator/hystrix.stream
Exposure 'hystrix.steam' web endpoints in your hystrix application's config file:
management:
endpoints:
web:
exposure:
include: 'hystrix.stream'
Make sure you have added your host to hystrix.dashboard.proxyStreamAllowList, in your config file of hystrix-dashboard application, it looks like:
hystrix:
dashboard:
proxy-stream-allow-list:
- 'localhost'
check details on
github: https://github.com/HuiyingWang0108/hystrix-dashboard
related microservice:
https://github.com/HuiyingWang0108/cloud-gateway
https://github.com/HuiyingWang0108/registry-service
In my case:
app like this:
Step1:
(1) change pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>2.2.10.RELEASE</version>
</dependency>
to
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.2.10.RELEASE</version>
</dependency>
(2) added below in the application.yml
hystrix:
dashboard:
proxy-stream-allow-list: "*"
(3) and then start app, open:
http://localhost:9295/hystrix
works:
Step2:
(1) added below in the pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
(2)added below in the application.yml
management:
endpoints:
web:
exposure:
include: hystrix.stream, info, health
(3) Open:
http://localhost:9191/actuator/hystrix.steam
shows:

Resources