I am trying to expose additional actuator endpoints in my Spring Boot 2.3 service. Attempting to add endpoints such as the prometheus and metrics for monitoring. But for some reason, the exposed endpoints are locked to the default loggers,health,info.
For some background, within the org, there is a parent Spring dependency which automatically brings all of the Spring essentials, as well as some generic code useful within the org. I use this dependency in many of my other projects and was able to expose these additional actuator endpoints successfully. However, in this project with multiple artifacts, I am unable to edit the default exposed actuator endpoints.
Printing the configurableEnvironment post init always shows the exposure property as follows
management.endpoints.web.exposure.include = loggers,health,info
This is after trying to override this property to an expanded list (loggers,health,info,Prometheus,metrics) using below methods:
Enabling specific endpoint via management.endpoint.metrics.enabled: true
Specifying these values in application.yaml
Passing this as a Command line arguement Dmanagement.endpoints.web.exposure.include=loggers,health,info,prometheus,metrics
Using mvn dependency:tree To exclude any transitive actuator dependencies
I don’t believe its due to the org’s parent pom, likely due to another dependency we are using. But due to the size of this project, it is quite hard to remove dependencies to test. Is there any way to track down where these properties are set. Or perhaps additional ways to force exposure of the additional endpoints I want?
——
Actuator config
management:
endpoints:
web:
exposure:
include: metrics,prometheus,info,health,logging
endpoint:
env:
enabled: true
metrics:
enabled: true
info:
enabled: true
health:
enabled: true
show-details: always
beans:
enabled: true
caches:
enabled: true
threaddump:
enabled: true
prometheus:
enabled: true
Actuator info
{"_links":{"self":{"href":"http://localhost:9050/actuator","templated":false},"health":{"href":"http://localhost:9050/actuator/health","templated":false},"health-path":{"href":"http://localhost:9050/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:9050/actuator/info","templated":false},"loggers":{"href":"http://localhost:9050/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:9050/actuator/loggers/{name}","templated":true}}}
Your question lacks some background, like your pom.xml or build.gradle files and full application.yml config.
I will go through the basic steps, which you may have missed.
Firstly, please make sure that you've included the Prometheus dependency:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
Also, don't forget that some metrics require the AOP dependency (like custome timers, for example):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
To enable the Prometheus metrics exposure, you should specify such configuration in your application.yml file (it seems like you did it correctly, but let's list it here for the full picture):
management:
endpoints:
web.exposure.include: health, info, prometheus
To verify that the Prometheus endpoints were exposed, please use the GET request to this URL: http://localhost:8080/actuator/prometheus
If those steps don't help you resolve your issue, please add more details to your question.
Related
So I am reading about Kubernetes PropertySource in Spring Cloud and how to configure spring to reload a value when it is changed in kubernetes configmap. As far as the doc says:
refresh (default): Only configuration beans annotated with
#ConfigurationProperties or #RefreshScope are reloaded. This reload
level leverages the refresh feature of Spring Cloud Context.
The RefreshScope is a bean in the context and has a public
refreshAll() method to refresh all beans in the scope by clearing the
target cache. The /refresh endpoint exposes this functionality (over
HTTP or JMX). To refresh an individual bean by name, there is also a
refresh(String) method.
To expose the /refresh endpoint, you need to add following
configuration to your application:
management: endpoints:
web:
exposure:
include: refresh
So I'm guessing the refresh actuator endpoint needs to be enabled otherwise it won't work, right?
But I have a microservice that is configured as follows but it is working completely correct and when configmap changes, the value gets updated.
bootstrap.yaml:
spring:
cloud:
kubernetes:
reload:
enabled: true
mode: polling
strategy: refresh
config:
name: foo
application.yaml:
management:
endpoint:
health:
show-details: "ALWAYS"
probes:
enabled: true
endpoints:
web:
exposure:
include: metrics, health, caches, restart
As you can see, there is no refresh endpoint enabled. How is it working properly then?
I am trying to add a shutdown endpoint actuator/shutdown in my Spring application as explained in this tutorial so that I can gracefully shutdown the application using a call like curl -X POST localhost:8080/actuator/shutdown.
I added
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
to my pom.xml and
management:
endpoints.web.exposure.include: *
endpoint.shutdown.enabled: true
endpoints.shutdown.enabled: true
management.endpoint.shutdown.enabled: true
to src/main/resources/application.yaml.
But when I run curl -X POST localhost:8080/actuator/shutdown, I get the following response:
{"timestamp":"2020-04-10T10:49:36.758+0000","status":404,"error":"Not Found",
"message":"No message available","path":"/actuator/shutdown"}
I don't see the shutdown endpoint at http://localhost:8080/actuator:
What am I doing wrong? What do I need to change in order for the actuator/shutdown endpoint to appear?
It appears you are using yaml, * has a special meaning in yaml and must be quoted.
The following should work
management:
endpoint:
shutdown:
enabled: true
endpoints:
web:
exposure:
include: "*"
That may be, because of Spring/Actuator version, that you are using, Endpoints have changed quite a bit in Spring Boot 2.0 and, as a result, your configuration is out of date.
Try next:
management.endpoints.web.expose=*
management.endpoint.shutdown.enabled=true
OR
management.endpoints.web.exposure.include=shutdown
management.endpoint.shutdown.enabled=true
You can check more about changes in Spring Boot 2.0 in release notes.
For Micronaut Redis, is there a way to toggle whether or not caching is enabled using configuration properties? I see some other available caches have the ability to be enabled/disabled via configuration properties such as Ehcache.
Maybe bit late but:
Add in your pom.xml the following:
<dependency>
<groupId>io.micronaut.cache</groupId>
<artifactId>micronaut-cache-noop</artifactId>
</dependency>
Or gradle:
implementation("io.micronaut.cache:micronaut-cache-noop:2.3.0")
And in your application.yml (at this point you can user env variables)
noop-cache.enabled: true
Source: https://micronaut-projects.github.io/micronaut-cache/latest/guide/#noop
I'm setting up a (Spring boot 2) Spring cloud zuul/gateway and ran into timeout issues. After reading the official docs and checking a similar question, I'm not convinced about the proposed solution.
I use the following type of route configuration:
routes:
test-service:
path: /test-service/**
serviceId: test-service
which I believe to not be "url routes", so I think these properties do not apply:
zuul.host.connect-timeout-millis
zuul.host.connection-request-timeout-millis
zuul.host.socket-timeout-millis
I tried setting the properties below, but IntelliJ indicates these properties "do not exist". Is this a quirk in the IDE, or are these properties only present/active under certain circumstances?
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds= 11000
hystrix.command.default.execution.timeout.enabled=false
ribbon.ConnectTimeout= 10000
ribbon.ReadTimeout: 10000
E.g. see this screenshot from my bootstrap.yml, where it only suggests other properties:
Is Ribbon and hystrix present and active by default with this maven dependency?
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
If you want to configure timeout in Zuul you have two options ,
If you have configured Zuul to use service discovery, you need to configure these timeouts with the below Ribbon properties
ribbon.ReadTimeout
ribbon.SocketTimeout
If you have configured Zuul routes by specifying URLs then use below properties ,as per your configuration you need to use this one
zuul.host.connect-timeout-millis
zuul.host.socket-timeout-millis
Offical doc is here (Look into Zuul Timeouts section)
https://cloud.spring.io/spring-cloud-netflix/multi/multi__router_and_filter_zuul.html
Below will show how they work with Hystrix,
https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_service_discovery_configuration
Note : Properties are case sensitive
I tried setting the properties below, but IntelliJ indicates these
properties "do not exist". Is this a quirk in the IDE, or are these
properties only present/active under certain circumstances?
May be quirk in the IDE.We have official doc that says the property exits.
I cannot get database information or filesystem information to show up on the /health endpoint. I only can get:
{
"status": "UP"
}
Details about my setup and configuration:
- Spring Boot 1.3.3
- Running the WAR on JBoss EAP 6.4
- Datasource is a JNDI resource.
- Oracle is the database
spring:
datasource:
# Must match the datasource name in JBoss standalone.xml
jndi-name: java:jboss/beautiful-ds
driver-class-name: oracle.jdbc.driver.OracleDriver
jpa:
properties:
# escapes reserved words used as column names (if any)
globally_quoted_identifiers: true
show-sql: true
hibernate:
naming_strategy: org.hibernate.cfg.EJB3NamingStrategy
server:
servlet-path: /*
management:
health:
diskspace:
enabled: true
db:
enabled: true
endpoints.health.sensitive: false
One thing i found on /configprops is this, which I'm not sure whether it is related:
"spring.datasource.CONFIGURATION_PROPERTIES": {
"prefix": "spring.datasource",
"properties": {
"error": "Cannot serialize 'spring.datasource'"
}
I had tried adding "driver-class-name: oracle.jdbc.driver.OracleDriver" thinking it maybe needed more details, but that didn't change the situation.
so yeah, what gives? I made a vanilla example project which at least shows the filesystem stuff out the gate, so not sure why either don't want to show in my "real" app. Tell me your great and wise answers! :)
By default Spring sets the below property to never.
To be able to see full health details add the below property to your application.properties.
management.endpoint.health.show-details=always
From the spring-boot documentation:
45.6 Security with HealthIndicators
Information returned by HealthIndicators is often somewhat sensitive in nature. For example,
you probably don’t want to publish details of your database server to
the world. For this reason, 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. Health responses are also cached
to prevent “denial of service” attacks. Use the
endpoints.health.time-to-live property if you want to change the
default cache period of 1000 milliseconds.
Make sure to have following properties set.
endpoints.health.sensitive=true # Mark if the endpoint exposes sensitive information.
management.health.db.enabled=true # Enable database health check.
management.health.defaults.enabled=true # Enable default health indicators.
management.health.diskspace.enabled=true # Enable disk space health check.
In cases if you are using spring security, then by default security is enabled for actuator endpoints, disable it in your yml file -
management:
security:
enabled: false
IIUC, the aggregate health is shown under /health, at least (IIUC) for springboot2. Meaning, that even if you have everything configured just right, only one line will be shown.
UPDATE: and if this is not what you need, you have to specifically ask to see details. Check these settings:
management.endpoint.health.show-details=when-authorized
management.endpoint.health.roles=ADMIN
You mixed YAML and Properties syntax in your configuration file. Replace the last line by the following, and it should work:
endpoints:
health:
sensitive: false