If you have used Spring Boot, you may know that Spring Boot is all about convenience, and the Spring Boot actuator is one of such features that provides a convenient way to interact with your app using HTTP and JMX. It's also essential from the Spring Boot interview point of view. While I did include some Spring Boot Actuator questions in my earlier post about frequently sked Spring boot interview questions, many of you asked for more questions to cover Spring Boot Actuator in depth, so I decided to write a separate article. In this article, we will see some popular Spring boot Actuator interview questions and, along the way, learn more about this helpful Spring boot Feature.
1. What value does Spring Boot Actuator provide?
Spring Boot actuator allows you to monitor and interact with your application which is very important for a production application. Without a spring boot actuator, you need to build your own monitoring and interaction system using JMX. Spring boot provides this out-of-box. You can now dynamically change the log level and perform such an operation without restarting your Java and Spring boot applications.
2. What are the two protocols you can use to access actuator endpoints?
Spring Boot allows you to access actuator endpoints using both HTTP and JMX. You can also secure endpoints using Spring Security, and in that case, Spring Security's content negotiation strategy is used. You can also enable SSH to access Actuator endpoints.
3. What are the actuator endpoints that are provided out of the box?
The Actuator provides a lot of endpoints by default, both sensitive and non-sensitive, but it also allows you to disable sensitive endpoints by configuring them in the application.properties file. Anyway, here are some of the actuator endpoints that are provided out-of-the-box:
4. What is the info endpoint for? How do you supply data?
Spring Boot Actuator provides an /info endpoint that can provide information about your spring boot application; the best thing about this is that you can customize it as per your application need. You can add custom information about your application on application.properties file using the info.app.* properties
Here is an example of how to configure info endpoint:
Spring will automatically add all the properties prefixed with info to the /info endpoint:
5. How do you change the logging level of a package using the logger's endpoint?
Spring Boot allows you to view and change the logging level of a spring boot application at runtime using loggers endpoint like http://localhost:8080/actuator/loggers. You can connect with this to see all the logging levels provided by the logging framework, and then you can also check a particular logger like root logger at
9. What is Health Indicator?
A Spring Boot Actuator Health Indicator provides health information of a Spring Boot Application. This health information is accessible at the /health endpoint and can be consumed by monitoring software. By default, multiple Health Indicators are auto-configured.
If you are running a spring boot app with a database app, you will see the database status, and by default, you will see also the diskSpace from your system.
10. What are the Health Indicators that are provided out of the box?
Out of the box, Spring Boot registers many HealthIndicators to report the healthiness of a particular application aspect.
Some of those indicators are almost always registered, such as DiskSpaceHealthIndicator or PingHealthIndicator. The DiskSpaceHealthIndicator shows the disk's current state, and the PingHealthIndicator serves as a ping endpoint for the application.
Similarly, Spring Boot also registers some indicators conditionally depending on which dependencies are available on the classpath or if other conditions are met.
11. What is the Health Indicator status?
It's similar to HTTP status, which indicates the health status of your spring boot application, and it's components; the following are some of the common health indicator statuses:
The health status affects the HTTP status code of the health endpoint. By default, Spring Boot maps the DOWN and OUT_OF_SERVICE states to throw a 503 status code. On the other hand, UP and any unmapped statuses will be translated to a 200 OK status code.
12. What are the Health Indicator statuses that are provided out of the box?
As I said before, some of the health indicators are provided out-of-the-box by spring boot; here are they:
13. How do you change the Health Indicator status severity order?
You can use the property management.health.status.order to change your application's Health Indicator status severity. For example, if you have a new Status with code FATAL in one of your HealthIndicator implementations.
The Actuator is mainly used to expose operational and monitoring
information about a live Spring boot application like health, metrics, info, dump, env, etc. It provides HTTP endpoints or JMX beans to enable developers and support to interact with them.
When you add spring-boot-starter-actuator maven
dependency on the classpath, several endpoints are available for you out of the box. That's what I mean when I say Spring boot is all about developer productivity and convenience. You just add a starter dependency in your Maven or Gradle
build file, and everything is automatically set up for you.
You can use these endpoints to query your application status and some important metrics like how many requests have been processed, how many of those requests are resulted in errors etc. As a spring boot developer, having a basic knowledge of The Actuator is essential.
In most spring boot interviews, the Interviewer will just ask about what the Actuator is, how it works, and some standard endpoints used often. Still, if you are preparing for spring professional certification, you need to know this topic in depth.
For example, knowing how to interact with the spring boto application is not enough; you should also know how to enable/disable some endpoints. You should be able to create your own HealthIndicator and create your own metrics.
While this is not a detailed post on how to do those things on Spring boot, it does have some questions on those topics to encourage you to learn more about them. If you need a resource, I highly recommend this Spring Boot Actuator course from Udemy to learn in-depth about the spring boot actuator.
In most spring boot interviews, the Interviewer will just ask about what the Actuator is, how it works, and some standard endpoints used often. Still, if you are preparing for spring professional certification, you need to know this topic in depth.
For example, knowing how to interact with the spring boto application is not enough; you should also know how to enable/disable some endpoints. You should be able to create your own HealthIndicator and create your own metrics.
While this is not a detailed post on how to do those things on Spring boot, it does have some questions on those topics to encourage you to learn more about them. If you need a resource, I highly recommend this Spring Boot Actuator course from Udemy to learn in-depth about the spring boot actuator.
13 Spring Boot Actuator Interview Questions with Answers
Now, let's see some of the common Spring Boot Actuator interview questions, which are also helpful for spring professional certification. They are picked from the official exam guide for Spring certification.1. What value does Spring Boot Actuator provide?
Spring Boot actuator allows you to monitor and interact with your application which is very important for a production application. Without a spring boot actuator, you need to build your own monitoring and interaction system using JMX. Spring boot provides this out-of-box. You can now dynamically change the log level and perform such an operation without restarting your Java and Spring boot applications.
2. What are the two protocols you can use to access actuator endpoints?
Spring Boot allows you to access actuator endpoints using both HTTP and JMX. You can also secure endpoints using Spring Security, and in that case, Spring Security's content negotiation strategy is used. You can also enable SSH to access Actuator endpoints.
3. What are the actuator endpoints that are provided out of the box?
The Actuator provides a lot of endpoints by default, both sensitive and non-sensitive, but it also allows you to disable sensitive endpoints by configuring them in the application.properties file. Anyway, here are some of the actuator endpoints that are provided out-of-the-box:
- /Actuator - provides a hypermedia-based discovery page for all the other endpoints
- /autoconfig - displays the auto-configuration report in two groups: positive matches and negative matches.
- /beans - displays all the spring beans used in the application
- /configprops - list all the configuration properties defined by the @ConfigurationProperties beans.
- /docs - documentation for all the Actuator module endpoints, requires spring-boot-actuator-docs dependency in pom.xml
- /dump - to get a thread dump of your application
- /env - exposes all the properties from the Spring's ConfigurableEnvironment interface
- /flyway - provides all the information about your database migration scripts; it's based on the Flyway project for database
- /health - shows the health of the application
- /info - displays the public application info
- /logfile - shows the contents of the log file specified by the logging.file property
- /metrics - Various metrics about the app
- /caches - Check available caches
4. What is the info endpoint for? How do you supply data?
Spring Boot Actuator provides an /info endpoint that can provide information about your spring boot application; the best thing about this is that you can customize it as per your application need. You can add custom information about your application on application.properties file using the info.app.* properties
Here is an example of how to configure info endpoint:
## Configuring info endpoint
info.app.name= My Spring Boot Application
info.app.description=This is my first spring boot application
info.app.version=1.0.0
Spring will automatically add all the properties prefixed with info to the /info endpoint:
{
"app": {
"description": "This is my first spring boot application",
"version": "1.0.0",
"name": "My Spring Boot Application"
}
}
And, if you want to learn more about creating a Spring Boot application from scratch, I highly recommend you to check out this Spring Framework 5: Beginner to Guru course on Udemy. It's a complete course to learn both Spring 5 and Spring Boot 2, and it's also very affordable; you can get this for just $10 on Udemy sales.
5. How do you change the logging level of a package using the logger's endpoint?
Spring Boot allows you to view and change the logging level of a spring boot application at runtime using loggers endpoint like http://localhost:8080/actuator/loggers. You can connect with this to see all the logging levels provided by the logging framework, and then you can also check a particular logger like root logger at
http://localhost:8080/actuator/loggers/root.
By the way, Starting with Spring Boot 2.x, most endpoints are not enabled by default, so you will need to enable the /loggers endpoint in our application.properties file as shown below:
6. How do you access an endpoint using a tag?
tag is a beneficial thing to filter metrics, and you should definitely use it to extract meaningful information. You can add any number of tag=KEY:VALUE query parameters to the end of the URL to filter any metric information.
For example, you may know that your application has received 100K requests, but you are only interested in requests that result in errors like HTTP 404 or HTTP 500 response status. You can get this information by using the status tag as shown below:
7. What are metrics for?
This Spring Boot actuator endpoint shows the metrics information of your spring boot application, where you can determine how much memory it's using, how much memory is free, the uptime of your application, the size of the heap is being used, the number of threads used, and so on.
8. How do you create a custom metric?
Actuator metrics are implemented by Micrometer, which means you can also create and publish your custom metric through Micrometer's MeterRegistry.All you need to do is inject a MeterRegistry wherever you may need to publish counters, timers, or gauges that capture the metrics for your spring boot application.
Here is an example of creating and registering a custom metric in spring-boot:
If you want to learn more about metrics in spring boot, I also recommend you to check out the Spring Framework: Spring Boot Actuator By Dustin Schultz course on Pluralsight. It's a great course to learn Spring boot actuators in depth.
By the way, Starting with Spring Boot 2.x, most endpoints are not enabled by default, so you will need to enable the /loggers endpoint in our application.properties file as shown below:
management.endpoints.web.exposure.include=loggers
management.endpoint.loggers.enabled=true
Once enabled, you can change the logging level of a particular package by using an HTTP POST request like this$ curl -i -X POST
-H 'Content-Type: application/json'
-d '{"configuredLevel": "DEBUG"}'
http://localhost:8080/actuator/loggers/com.javarevisited.app.management.logging
6. How do you access an endpoint using a tag?
tag is a beneficial thing to filter metrics, and you should definitely use it to extract meaningful information. You can add any number of tag=KEY:VALUE query parameters to the end of the URL to filter any metric information.
For example, you may know that your application has received 100K requests, but you are only interested in requests that result in errors like HTTP 404 or HTTP 500 response status. You can get this information by using the status tag as shown below:
$ curl localhost:8081/actuator/metrics/http.server.requests?tag=status:404
7. What are metrics for?
This Spring Boot actuator endpoint shows the metrics information of your spring boot application, where you can determine how much memory it's using, how much memory is free, the uptime of your application, the size of the heap is being used, the number of threads used, and so on.
8. How do you create a custom metric?
Actuator metrics are implemented by Micrometer, which means you can also create and publish your custom metric through Micrometer's MeterRegistry.All you need to do is inject a MeterRegistry wherever you may need to publish counters, timers, or gauges that capture the metrics for your spring boot application.
Here is an example of creating and registering a custom metric in spring-boot:
@Component
public class OrderMetrics extends AbstractRepositoryEventListener {
private MeterRegistry meterRegistry;
public OrderMetrics(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}
@Override
protected void onAfterCreate(Order order{
List items = order.getItems();
for (Item itm : items) {
meterRegistry.counter("orderstat", "items", item.getId()).increment();
}
}
}
9. What is Health Indicator?
A Spring Boot Actuator Health Indicator provides health information of a Spring Boot Application. This health information is accessible at the /health endpoint and can be consumed by monitoring software. By default, multiple Health Indicators are auto-configured.
If you are running a spring boot app with a database app, you will see the database status, and by default, you will see also the diskSpace from your system.
If you are running your app, you can go to http://localhost:8080/health endpoint to access
health status, and If you want to learn more, check the previous course, it also covers health indicators in good detail.
10. What are the Health Indicators that are provided out of the box?
Out of the box, Spring Boot registers many HealthIndicators to report the healthiness of a particular application aspect.
Some of those indicators are almost always registered, such as DiskSpaceHealthIndicator or PingHealthIndicator. The DiskSpaceHealthIndicator shows the disk's current state, and the PingHealthIndicator serves as a ping endpoint for the application.
Similarly, Spring Boot also registers some indicators conditionally depending on which dependencies are available on the classpath or if other conditions are met.
11. What is the Health Indicator status?
It's similar to HTTP status, which indicates the health status of your spring boot application, and it's components; the following are some of the common health indicator statuses:
- UP — The element or subsystem is working as expected
- DOWN — The component is not working
- OUT_OF_SERVICE — The component has been out of service temporarily
- UNKNOWN — The component state is unknown
The health status affects the HTTP status code of the health endpoint. By default, Spring Boot maps the DOWN and OUT_OF_SERVICE states to throw a 503 status code. On the other hand, UP and any unmapped statuses will be translated to a 200 OK status code.
12. What are the Health Indicator statuses that are provided out of the box?
As I said before, some of the health indicators are provided out-of-the-box by spring boot; here are they:
- UP — The component or subsystem is working as expected
- DOWN — The component is not working
- OUT_OF_SERVICE — The component has been out of service temporarily
- UNKNOWN — The component state is unknown
13. How do you change the Health Indicator status severity order?
You can use the property management.health.status.order to change your application's Health Indicator status severity. For example, if you have a new Status with code FATAL in one of your HealthIndicator implementations.
You may
also want to register custom status mappings if you access the health endpoint over HTTP, which you can do by adding the following properties in your spring boot application configuration
That's all about the Spring Boot Actuator Interview Questions and answers for 3 to 5 years experienced Java programmers. You can review these questions before you go for any spring boot interview. Since Actuator is an important topic, a good knowledge of Actuator is necessary for cracking Java and Spring Boot interviews and working effectively in Spring Boot application in your day-to-day life.
management.health.status.order= BUSY, DOWN, OUT_OF_SERVICE, UNKNOWN, UP
management.health.status.http-mapping.FATAL=503
That's all about the Spring Boot Actuator Interview Questions and answers for 3 to 5 years experienced Java programmers. You can review these questions before you go for any spring boot interview. Since Actuator is an important topic, a good knowledge of Actuator is necessary for cracking Java and Spring Boot interviews and working effectively in Spring Boot application in your day-to-day life.
Other Java and Spring articles you may like
Thanks for reading this article so far; if you find these Spring boot Actuator interview questions and answers useful, please share them with your friends and colleagues.
- 15 Spring Data JPA Interview Questions with answers (questions)
- 5 courses to learn Spring Boot and Spring Cloud ( courses)
- 15 Spring Cloud Interview Questions for Java developers (answers)
- 5 Courses to learn Spring Cloud and Microservices (courses)
- 15 Microservices Interview questions (answers)
- 5 Course to Master Spring Boot online (courses)
- 10 Courses to learn Spring Security with OAuth 2 (courses)
- Top 5 Books and Courses to learn RESTful Web Service (books)
- 5 Spring Boot Annotations for full-stack Java developers (tutorial)
- 3 ways to change Tomcat port in Spring Boot (tutorial)
- 10 Spring MVC annotations Java developers should learn (annotations)
- 10 Tools Java Developers use in their day-to-day life (tools)
- Top 5 Courses to learn Microservices in Java? (courses)
- 10 Advanced Spring Boot Courses for Java Programmers (courses)
- 3 Best Practices Java Programmers can learn from Spring (best practices)
P. S. - If you want to learn about Spring Boot and look for a free Spring Boot online course, I also recommend you join the Introducing Spring Boot (FREE ) class by Dan Vega on Udemy. It's one of the best free courses to learn Spring Boot for Java developers.
No comments:
Post a Comment
Feel free to comment, ask questions if you have any doubt.