spring-boot health not showing details (withDetail info) - java

I have written a class implementing HealthIndicator, overriding the health-method. I return Health.down().withDetail("SupportServiceStatus", "UP").build();
This should make my health-endpoint return:
{
"status":"UP",
"applicationHealth": {
"status":"UP"
}
}
Instead it just returns (health, without details):
{
"status":"UP",
}
Javacode (somewhat simplified):
#Component
public class ApplicationHealth implements HealthIndicator {
#Override
public Health health() {
return check();
}
private Health check() {
return Health.up().withDetail("SupportServiceStatus", supportServiceStatusCode).build();
}
}

According to spring-boot docs:
. . . by default, only the health status is exposed over an unauthenticated HTTP connection. If you are happy for complete health information to always be exposed you can set endpoints.health.sensitive to false.
Solution is to set endpoints.health.sensitive to false in application.properties.
application.properties
endpoints.health.sensitive=false
For >1.5.1 application.properties
management.security.enabled=false
At Spring Boot 2.0.0.RELEASE (thx #rvit34 and #nisarg-panchal):
management:
endpoint:
health:
show-details: "ALWAYS"
endpoints:
web:
exposure:
include: "*"
management.endpoints.web.exposure.include=* exposes all endpoints, if that is what you want.
Current documentation can be found here: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

At Spring Boot 2.0.0.RELEASE:
management:
endpoint:
health:
show-details: "ALWAYS"

Thanks #rvit34 and #Ninja Code Monkey its working.
For Springboot 2.x.x.RELEASE,
Use below for application.properties,
management.endpoint.health.show-details=ALWAYS
Use below for applicaton.yml,
management:
endpoint:
health:
show-details: "ALWAYS"

Setting 'endpoints.health.sensitive' made no difference... had to set:
management:
security:
enabled: false

need to add
management.endpoint.health.show-details=always
to Application.properties

For Spring boot 2.X I have following in my application.properties file for detailed information:
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=ALWAYS

I had this same problem, on version Spring Boot 1.5.9 I had to set
management.security.enabled=false

Related

Spring Cloud config refreshed values are not updating with #value annotation

I have a spring boot project with cloud config server.I have enabled cloud bus with kafka and added required actuator endpoints to live reload properties on both server and client.
cloud:
bus:
enabled: true
management:
endpoints:
web:
exposure:
include: refresh, bus-refresh, beans, env
Issue is when I am using #value annotation to read property value. I am not getting updating value. (#value only get updated when I apply #RefreshScope,But I cannot use it because I have ton of client services and will to add #RefreshScope on all beans where properties are being used)
#Value("${message.testValue}")
private String info;
private String readValue() {
return info;
}
But when I read using Environment, I am getting updated value after refresh
private String readValue() {
return this.environment.getProperty("message.testValue");
}
What changes I need to implement to get updated value using #Value annotation withou #RefreshScope? Or there is something which I am missing in implementation.

Hystrix dashboard always showing loading screen

I have developed Micro service application using Netflix-OSS libraries. I am facing issue on Hystrix dashboard running on localhost:9091/hystrix. I want to monitor request metrics between Micro service-A and Micro service-B. Endpoint "hystrix.stream" is already registered.
hystrix dashboard stucks on loading without showing any results.
I inspected browser and found jquery error -
Uncaught TypeError: e.indexOf is not a function which seems to be a jquery version issue.
I am using Jdk 14 version and Spring boot 2.3 for my development
#bob0the0mighty
I am adding code snippet for your reference. This is my springboot main class
#SpringBootApplication
#EnableEurekaClient
#EnableCircuitBreaker
#EnableHystrixDashboard
public class DramaServiceApplication {
}
My controller looks like :
#GetMapping("/acts")
#com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand(fallbackMethod = "fallbackMethodForGetActor", commandKey = "test-Act", groupKey = "test-Act")
public ActorList getActors() {
ActorList actorList = restTemplate.getForObject("http://actor-service/actor/actorsList", ActorList.class);
return actorList;
}
public ActorList fallbackMethodForGetActor() {
return new ActorList(" Requested Actor page is under maintenance!!");
}
application.yml file looks like :
management:
endpoints:
web:
base-path: /
exposure:
include: hystrix.stream, health, info, metrics
After hitting request multiple times, I am getting hystrix dashboard as "loading" always
and screen looks like
[enter image description here][1]
[1]: https://i.stack.imgur.com/hOeZf.png
Updating the spring-cloud-dependencies version to "Hoxton.SR7" resolved the problem for me.
There is an issue with jquery 3.4.1 with spring-cloud-dependencies version "Hoxton.SR6".
You can get the details of the issue and the fix here.
https://github.com/spring-cloud/spring-cloud-netflix/issues/3811
https://github.com/spring-cloud/spring-cloud-netflix/pull/3817
This issue got fixed by adding following configuration changes:
1. Updating Hoxton to SR7 in pom.xml:
<properties>
<java.version>14</java.version>
<spring-cloud.version>Hoxton.SR7</spring-cloud.version>
</properties>
2. Add these entries in application.yml:
hystrix:
dashboard:
proxy-stream-allow-list: '*'
management:
endpoints:
web:
base-path: /
exposure:
include: '*'
3. Creating a separate config Java class:
package com.ibm.drama.controller;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
#Configuration
public class HystrixConfig {
#Bean
public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<HystrixMetricsStreamServlet>(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("hystrix.stream");
return registrationBean;
}
}

Spring Boot Actuator not showing any information

I'm using Spring Boot version 2.2.5.RELEASE and have trouble to receive any information from the actuator endpoint. What I'm receiving is only the empty structure of Actuator as following:
This is my configuration:
implementation "org.springframework.boot:spring-boot-starter-actuator"
#Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}
management:
endpoints:
web:
exposure:
include: "*"
What do I miss?
Hallelujah, finally found the issue of my above described problem!
The problem was that i configured my spring boot application to use Gson instead of the default Jackson json parser. Not completely clear why, but with the following lines of code it results in issues to show the data at the actuator endpoints.
implementation ("org.springframework.boot:spring-boot-starter-web") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-json"
}
implementation "com.google.code.gson:gson:2.8.6"
The following above described Bean is also unnecessary!
#Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}
The following configuration was hence as well a problem:
spring:
http:
converters:
preferred-json-mapper: gson
gson:
exclude-fields-without-expose-annotation: true
And finally with removing of all of my #Expose annotations it started to work perfectly fine again.
#Expose
private String content;
If anyone can explain to me why this happened, or how to configure Gson to work properly with Spring Boot Actuator in combination, I'm here to listen and understand.
I had the same problem and I fixed by removing the following line
gsonBuilder.excludeFieldsWithoutExposeAnnotation()

Spring Yml configuration for CORS not used

I have configured the allowed origins for CORS in the Spring yml configuration as follows.
endpoints:
cors:
allowed-origins: http://client.local
allow-credentials: true
But it wasn't applied until I added a Java configuration as follows
#Configuration
#EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {
#Value("${endpoints.cors.allowed-origins}")
private String allowedOrigins;
#Value("${endpoints.cors.allow-credentials}")
private boolean allowCredentials;
#Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins(allowedOrigins)
.allowCredentials(allowCredentials);
}
}
I want to keep the yml configuration and discard the Java configuration, why is the yml config not applied?
I know, it might be too late, but I'll try...
Have you added spring-boot-starter-actuator to your dependencies?
Instead of using custom properties use endpoints provided by Spring Boot.
Ex:
management.endpoints.web.cors.allowed-origins=http://domain:port
Spring Boot Application.properties configuration

Spring Cloud Config Server lookup through Eureka using Java instead of bootstrap.yml

I'm attempting to build code into our base pom which autoconfigures Spring Cloud Config server lookup through Eureka. We're doing this to avoid templating .yml properties for developers building microservices. For example, we want to java config all behavior triggered from these properties:
spring:
application:
name: MyMicroservice
cloud:
config:
enabled: true
server:
prefix: /diagnostics/admin/config
failFast: true
discovery:
enabled: true
serviceId: echo
management:
context-path: /diagnostics/admin
eureka:
password: password
client:
serviceUrl:
defaultZone: http://user:${eureka.password}#localhost:8761/eureka/
instance:
leaseRenewalIntervalInSeconds: 10
statusPageUrlPath: /diagnostics/admin/info
healthCheckUrlPath: /diagnostics/admin/health
After much experimenting, the following approach mostly works except for the Eureka-discovered config server (resulting in no overridden config properties):
#Order(-1)
public class AdditionalBootstrapPropertySourceLocator implements PropertySourceLocator {
#Override
public PropertySource<?> locate(Environment environment) {
Map<String, Object> theBootstrapYmlConfig = new HashMap<>();
theBootstrapYmlConfig.put("spring.cloud.config.enabled", new Boolean(true));
theBootstrapYmlConfig.put("spring.cloud.config.server.prefix", "/diagnostics/admin/config");
theBootstrapYmlConfig.put("spring.cloud.config.failFast", new Boolean(true));
theBootstrapYmlConfig.put("spring.cloud.config.discovery.enabled", new Boolean(true));
theBootstrapYmlConfig.put("spring.cloud.config.discovery.serviceId", "echo");
theBootstrapYmlConfig.put("management.context-path", "/diagnostics/admin");
theBootstrapYmlConfig.put("eureka.client.serviceUrl.defaultZone", "http://user:password#localhost:8761/eureka/");
theBootstrapYmlConfig.put("eureka.instance.leaseRenewalIntervalInSeconds", new Integer(10));
theBootstrapYmlConfig.put("eureka.instance.statusPageUrlPath", "/diagnostics/admin/info");
theBootstrapYmlConfig.put("eureka.instance.healthCheckUrlPath", "/diagnostics/admin/health");
return new MapPropertySource("myExtraBootstrap", theBootstrapYmlConfig);
}
}
And I seem to need this Bean as well:
#ConditionalOnWebApplication
#Configuration
#Import(EurekaClientAutoConfiguration.class)
public class WorkfrontDiscoveryClientConfigServiceBootstrapConfiguration {
#Bean
#ConditionalOnClass({ DiscoveryClient.class, ConfigServicePropertySourceLocator.class })
#ConditionalOnMissingBean
DiscoveryClientConfigServiceBootstrapConfiguration discoveryClientConfigServiceBootstrapConfiguration() {
DiscoveryClientConfigServiceBootstrapConfiguration discoveryClientConfigServiceBootstrapConfiguration =
new DiscoveryClientConfigServiceBootstrapConfiguration();
return discoveryClientConfigServiceBootstrapConfiguration;
}
}
Finally, I put both into spring.factories to ensure they are constructed. The problem is that the PropertySourceLocator is never used to construct the call within ConfigServicePropertySourceLocator to retrieve the properties. No matter what I do, I cant seem to match the behaviors that specifying the properties within bootstrap.yml would produce.
Edit 4 days later
The key factor (and restriction) here is the ability to look up the config server through Eureka. In the current spring cloud release (1.0.2), the property source is retrieved and constructed too early in the spring initialization cycle for the config-lookup-through-eureka java property source config I have above. Plus if the Eureka server is slow or not available at bootstrap startup time, the Config server property source is never reconstructed when Eureka finally comes up. This in my mind is a bug.
I solved this all by eliminating the concept of looking up the config server through Eureka, and requiring this minimum config in bootstrap.yml:
spring:
application:
name: MyMicroservice
cloud:
config:
uri: http://localhost:8888/diagnostics/admin/config
eureka:
client:
serviceUrl:
defaultZone: http://user:password#localhost:8761/eureka/
and then setting the rest in the java AdditionalBootstrapPropertySourceLocator
Edit 30 days later
Java-configing bootstrap properties continues to be a challenge. I'm doing this because I'm developing a framework without templating or code generation (the premise of spring boot). I've added spring-retry to the mix and client-to-config gets retried but re-registration to Eureka does not. This is why Eureka-first had to be abandoned for me. I'd put my vote in for integrating spring-retry into the Eureka registration process so I can go back to Eureka-first for my framework. Still on Spring Cloud 1.0.2.
Edit 100 days later
Update for where we ended up. Continuing along our mantra of avoiding property templating, enforcing policies and practices within code .. and continuing without a Eureka-first concept, we abandoned PropertySourceLocator and simply used a SpringApplicationRunListener as follows:
public class OurFrameworkProperties implements SpringApplicationRunListener {
:
public void started() {
if (TestCaseUtils.isRunningFromTestCase()) {
System.setProperty("spring.cloud.config.failFast", "false");
System.setProperty("spring.cloud.config.enabled", "false");
System.setProperty("eureka.client.enabled", "false");
} else {
// set production values same way
}
}
}
A caution that this started() actually gets called twice inside the spring code (once not passing any program arguments btw) everytime your Spring application runs or gets an Actuator refresh().
If your PropertySourceLocator is listed inspring.factories (I assume as a BootstrapConfiguration) then it needs to be a #Component (or maybe even a #Configuration).
you have to set this properties in the boostrap.properties
eureka.instance.metadataMap.configPath: /your-app-name
and comment this one
#spring.cloud.config.uri=http://localhost:8888/
and obviously it must be also this
eureka.client.serviceUrl.defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
eureka.client.instance.preferIpAddress: true
according with the documentation
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_client.html#discovery-first-bootstrap

Categories

Resources