BAEL-1430: Move Spring Boot 2 actuator module
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.actuator;
|
||||
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Component
|
||||
public class DownstreamServiceReactiveHealthIndicator implements ReactiveHealthIndicator {
|
||||
|
||||
@Override
|
||||
public Mono<Health> health() {
|
||||
return checkDownstreamServiceHealth().onErrorResume(
|
||||
ex -> Mono.just(new Health.Builder().down(ex).build())
|
||||
);
|
||||
}
|
||||
|
||||
private Mono<Health> checkDownstreamServiceHealth() {
|
||||
// we could use WebClient to check health reactively
|
||||
return Mono.just(new Health.Builder().up().build());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.actuator;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Component
|
||||
@Endpoint(id = "features", enableByDefault = true)
|
||||
public class FeaturesEndpoint {
|
||||
|
||||
private Map<String, Feature> features = new ConcurrentHashMap<>();
|
||||
|
||||
@ReadOperation
|
||||
public Map<String, Feature> features() {
|
||||
return features;
|
||||
}
|
||||
|
||||
@ReadOperation
|
||||
public Feature feature(@Selector String name) {
|
||||
return features.get(name);
|
||||
}
|
||||
|
||||
@WriteOperation
|
||||
public void configureFeature(@Selector String name, Feature feature) {
|
||||
features.put(name, feature);
|
||||
}
|
||||
|
||||
@DeleteOperation
|
||||
public void deleteFeature(@Selector String name) {
|
||||
features.remove(name);
|
||||
}
|
||||
|
||||
public static class Feature {
|
||||
private Boolean enabled;
|
||||
|
||||
public Boolean getEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.actuator;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.EndpointWebExtension;
|
||||
import org.springframework.boot.actuate.info.InfoEndpoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@EndpointWebExtension(endpoint = InfoEndpoint.class)
|
||||
public class InfoWebEndpointExtension {
|
||||
|
||||
private final InfoEndpoint delegate;
|
||||
|
||||
public InfoWebEndpointExtension(InfoEndpoint infoEndpoint) {
|
||||
this.delegate = infoEndpoint;
|
||||
}
|
||||
|
||||
@ReadOperation
|
||||
public WebEndpointResponse<Map> info() {
|
||||
Map<String, Object> info = this.delegate.info();
|
||||
Integer status = getStatus(info);
|
||||
return new WebEndpointResponse<>(info, status);
|
||||
}
|
||||
|
||||
private Integer getStatus(Map<String, Object> info) {
|
||||
// return 5xx if this is a snapshot
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public class SecurityConfig {
|
||||
public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) {
|
||||
return http.authorizeExchange()
|
||||
.pathMatchers("/admin").hasAuthority("ROLE_ADMIN")
|
||||
.pathMatchers("/actuator/**").permitAll()
|
||||
.anyExchange().authenticated()
|
||||
.and().formLogin()
|
||||
.and().build();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
server.port=8081
|
||||
management.endpoints.web.expose=*
|
||||
info.app.name=Spring Boot 2 actuator Application
|
||||
|
||||
logging.level.root=INFO
|
||||
Reference in New Issue
Block a user