The Spring url to get all request mappings does not work (anymore) - spring

Usually I could get a url mapping overview using the url:
/application/mappings
Now I get a
PageNotFound - No mapping found for HTTP request with URI [/application/mappings] in my log and Response Status: 404 (Not Found) in my browser.
Also the other Spring urls /application/autoconfig, /application/beans and /application/configprops give the same problem.
I'm using spring-boot 2.0.0.RELEASE.
The actuator artifact was added to the pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
What am I doing wrong?

According to the current Spring Boot 2.0 documentation the default actuator endpoints are prefixed with /actuator, not with /application. This was different for M4 and I think they've changed it in M7.
M4 docs:
For example, by default, the health endpoint will be mapped to
/application/health.
M7 docs:
For example, by default, the health endpoint is mapped to
/actuator/health

Related

How to get access to the Spring-boot actuator JSON payload

I m working on a customized health check for an API. Where I m using :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.5.5</version>
</dependency>
and implementing the HealthIndicator interface.
I m wondering if there is a way to get access to the payload returned by /actuator/health ?
so I can desterilize it, and base on the values on the object (payload), I will build the implementation for the heath() method from HealthIndicator Interface.
I have tried to use:
- HealthEndpoint but it needs an implementation for HealtContributorRegistary , not sure how to do that.
- SystemHealth (im getting the error : class Cannot be accessed from outside package).
any help is very welcomed.
Thank you.
I was able to get access to all my API components status by
#Autowired HealthContributor[] healthContributors;
in a service.
I have followed this answer : Direct access to Spring Boot Actuator Health beans/data?

Expose metrics from spring application to prometheus without using spring-boot actuator

I have been trying to collect micrometer metrics in a non springboot application and expose them to prometheus.I have added the following dependency and the test method for the same.I would like to know how to proceed and expose the collected metrics to prometheus from my non spring boot application(traditional spring application).
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.2.0</version>
</dependency>
public string testmetrics(){
private PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
registry.counter("ws metric collection","tktdoc metrics");
String metricsInfo = registry.scrape();
return metricsInfo;
}
You practically have to expose an HTTP endpoint and configure Prometheus with it; the HTTP endpoint will supply the data for the scrapes.
An example showing how to add the HTTP endpoint by starting up an HTTP Server (your application may already be using one) is here.

Unable to access /actuator endpoints

I've got a small project running Spring Boot and Spring Cloud Streams with version Greenwich.SR4.
So far I've tried to include the following dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
Wanting to have a /check/health endpoint which basically returns a code 200.
I've modified the config accordingly so that I don't have useless health configs within.
management.endpoints.web.base-path=/check
management.endpoint.health.enabled=true
management.health.solr.enabled=false
management.health.elasticsearch.enabled=false
However, whenever I try to run localhost:8080/check/health a 404 is prompted. What could be happening?
Also mentioning that I've tried including my own #RestController but same behavior happens.
The URL for the health check should be http://localhost:8080/check/health, not /check/status.
It is depends on the Spring-Boot version. After version 2.0 the path name is manage, so your right url is: http://localhost:8080/check/health
You can also change that with (.yml version):
management:
context-path: /manage
security:
enabled: false

WhyI am Getting 403 Forbidden error for actuator /refresh endpoint on Spring Boot 2 on Cloud Foundry{using Cloud Config Server service}

Within my project, I have the following bootstrap.properties file:
spring.application.name=vault-demo
management.endpoints.web.exposure.include=*
Additionally to that, I defined the following dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
The config server is able to access the property but when I update that property in GitHub and POST to /refresh I get a 403: Forbidden. Do I need to make any change in my application or bootstrap.properties?
I got the solution, I needed to add a security configuration, for example:
#Configuration
#EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
#Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}
Additionally, I had to add the following dependency:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-rsa</artifactId>
<version>1.0.5.RELEASE</version>
</dependency>
I found this solution within the following GitHub issue:
https://github.com/spring-cloud/spring-cloud-config/issues/950
I notice that Spring Boot 2 cloud config dont need to be "hooked to /refresh endpoint" after commit (or other events), because the new version always request to remote git Server and compare the last commitId and if is diferrent commitId start to fetch the changes.
If debug and see the log traces, after request http://host:8888/{service}/{profile}/{label_branch} always ask github, and you will notice that if exist changes a "fetch proccess is started " , look at traces like github negotiation:
o.e.jgit.transport.PacketLineOut - git> want 4a766a1677....
o.e.jgit.transport.PacketLineOut - git> have 93cd4a98b5b3bb7d895...
and finally
o.e.jgit.transport.PacketLineOut - git> done
And after, the download:
o.e.jgit.transport.PacketLineIn - git< ACK 0f8d2413183d5.... common
and so on.
If you look traces and not exist changes (the last commitId is the same, the negotiation and download traces are not shown).
I think that is not a good performance behaviour, so would exist a property that disable it and therefore need a "forced refresh hook behaviour", but i couldn't find it on Spring boot 2.
On the other hand, I like it because you dont need to enable HTTP access to your config server to be notified, so the security configuration is not compromised.
I tried with Greenwich.RELEASE
Hope this helps and clarify this behaviour.

Spring-boot actuator: only some endpoints work

I'm trying to implement spring-boot actuator for the first time but I've noticed that:
It only works if I specify the version, otherwise not;
Only a few endpoints works among those declared by the /actuator endpoint response.
This is the dependencies I've inserted in my pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-docs</artifactId>
</dependency>
...
</dependencies>
This is my application.properties:
#info for Spring Boot Actuator
info.app.name=Spring Sample Application
info.app.description=Application to demonstrate Spring REST HATEOAS and Actuator
info.app.version=1.0.0
When I make this http request:
http://localhost:8080/actuator
it returns me:
{"links":[{"rel":"self","href":"http://localhost:8080/actuator"},{"rel":"loggers","href":"http://localhost:8080/loggers"},{"rel":"env","href":"http://localhost:8080/env"},{"rel":"info","href":"http://localhost:8080/info"},{"rel":"heapdump","href":"http://localhost:8080/heapdump"},{"rel":"mappings","href":"http://localhost:8080/mappings"},{"rel":"metrics","href":"http://localhost:8080/metrics"},{"rel":"configprops","href":"http://localhost:8080/configprops"},{"rel":"autoconfig","href":"http://localhost:8080/autoconfig"},{"rel":"beans","href":"http://localhost:8080/beans"},{"rel":"auditevents","href":"http://localhost:8080/auditevents"},{"rel":"trace","href":"http://localhost:8080/trace"},{"rel":"health","href":"http://localhost:8080/health"},{"rel":"dump","href":"http://localhost:8080/dump"},{"rel":"docs","href":"http://localhost:8080/docs"}]}
Among these links, only /health and /info seem to work.
In fact, when I ask for /health it returns:
{"status":"UP"}
When I ask for /info it returnes:
{"app":{"description":"Application to demonstrate Spring REST HATEOAS and Actuator","name":"Spring Sample Application","version":"1.0.0"}}
How comes that all the other endpoints gives me Whitelabel error page?
Did you try to see the logs when you try other endpoints. It says
Full authentication is required to access actuator endpoints. Consider adding Spring Security or set 'management.security.enabled' to false.
I guess this is self explanatory. Configure atleast basic auth or set the above mentioned property to false.
Whitelabel error page that you see also says
There was an unexpected error (type=Unauthorized, status=401).
Here is the link for the doc related to this.
In my case I was getting 404 Whitelabel Error Page because only /actuator/health and /actuator/info are the only endpoints enabled by default (as mentioned on the Spring Boot Actuator documentation)
To enable the other endpoints I ended up adding this configuration to my application.yml:
management:
endpoints:
web:
exposure:
include: info, health, loggers, logfile, configprops
I found a posting at Baeldung where it says
Unlike in previous versions, Actuator comes with most endpoints disabled. (Link)
So add management.endpoints.web.exposure.include=*. to your application.properties.

Resources