fix(obs): wire Prometheus endpoint for Spring Boot 4.0
Four Spring Boot 4.0-specific issues prevented /actuator/prometheus from working: 1. spring-boot-starter-micrometer-metrics missing — Spring Boot 4.0 splits Micrometer metrics export (including the Prometheus scrape endpoint) out of spring-boot-starter-actuator into its own starter. Added dependency. 2. management.prometheus.metrics.export.enabled not set — Spring Boot 4.0 defaults metrics export to false (opt-in). Added the property to application.yaml. 3. SecurityConfig did not permit /actuator/prometheus — Spring Boot 4.0 with Jetty serves the management port (8081) via the same security filter chain as the main port (8080). The previous commit's exclusion of ManagementWebSecurityAutoConfiguration was a no-op (that class no longer exists in Spring Boot 4.0); removed it and added the correct permitAll() rule. Updated the architecture comment in application.yaml to reflect the true filter-chain behaviour. 4. Reverted invalid FamilienarchivApplication.java change from the prior commit (ManagementWebSecurityAutoConfiguration import compiled against a class that does not exist in the Spring Boot 4.0 BOM). Also adds ActuatorPrometheusIT — an integration test that asserts the /actuator/prometheus endpoint returns 200 with jvm_memory_used_bytes without credentials, serving as regression protection against future Spring Boot upgrades silently breaking metrics collection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package org.raddatz.familienarchiv;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.server.LocalManagementPort;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@ActiveProfiles("test")
|
||||
@Import(PostgresContainerConfig.class)
|
||||
class ActuatorPrometheusIT {
|
||||
|
||||
@LocalManagementPort
|
||||
private int managementPort;
|
||||
|
||||
@MockitoBean
|
||||
S3Client s3Client;
|
||||
|
||||
@Test
|
||||
void prometheus_endpoint_returns_jvm_metrics_without_credentials() {
|
||||
ResponseEntity<String> response = noThrowTemplate().getForEntity(
|
||||
"http://localhost:" + managementPort + "/actuator/prometheus", String.class);
|
||||
|
||||
assertThat(response.getStatusCode().value()).isEqualTo(200);
|
||||
assertThat(response.getBody()).contains("jvm_memory_used_bytes");
|
||||
}
|
||||
|
||||
private RestTemplate noThrowTemplate() {
|
||||
RestTemplate template = new RestTemplate();
|
||||
template.setErrorHandler(new DefaultResponseErrorHandler() {
|
||||
@Override
|
||||
public boolean hasError(org.springframework.http.client.ClientHttpResponse response) throws IOException {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return template;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user