Performance: Custom actuator endpoints
MEDIUM IMPACT
This affects the server response time and the size of monitoring data sent to clients, impacting backend performance and network load.
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import java.util.concurrent.atomic.AtomicReference; import java.util.Map; @Endpoint(id = "cachedMetrics") public class CachedMetricsEndpoint { private final AtomicReference<Map<String, Object>> cache = new AtomicReference<>(); public CachedMetricsEndpoint() { // Precompute or update cache asynchronously cache.set(Map.of("data", "precomputed result")); } @ReadOperation public Map<String, Object> metrics() { return cache.get(); } }
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import java.util.Map; @Endpoint(id = "heavyMetrics") public class HeavyMetricsEndpoint { @ReadOperation public Map<String, Object> metrics() throws InterruptedException { // Simulate expensive operation Thread.sleep(5000); return Map.of("data", "heavy computation result"); } }
| Pattern | Server Processing | Response Delay | Network Payload | Verdict |
|---|---|---|---|---|
| Blocking heavy computation in endpoint | High CPU and blocking | 5 seconds delay | Small JSON | [X] Bad |
| Cached or precomputed endpoint data | Minimal CPU, non-blocking | Instant response | Small JSON | [OK] Good |