Skip to content

Commit 40e5b4c

Browse files
authored
Feature/fixing prometheus (#745)
* Fixing prometheus so that it actually works. Also seems related to micrometer-metrics/micrometer#5093 * cleaning up override * Limiting exposure * Added docs * Added smoketest for prometheus endpoint * Removing metrics and prometheus exposure by default * Removing 'info' Adding parameterized tests for endpoints * Reintroduced 'info' * Remove info * Adjusted comment
1 parent e2d2ea7 commit 40e5b4c

File tree

5 files changed

+97
-25
lines changed

5 files changed

+97
-25
lines changed

pom.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,7 @@
4343
<dependencyManagement>
4444
<dependencies>
4545

46-
<!-- Temporarily override CR depedencies for debugging -->
47-
<!-- <dependency>-->
48-
<!-- <groupId>org.opencds.cqf.fhir</groupId>-->
49-
<!-- <artifactId>cqf-fhir-bom</artifactId>-->
50-
<!-- <version>3.4.0</version>-->
51-
<!-- <type>pom</type>-->
52-
<!-- <scope>import</scope>-->
53-
<!-- </dependency>-->
54-
<dependency>
46+
<dependency>
5547
<groupId>org.glassfish.jaxb</groupId>
5648
<artifactId>jaxb-runtime</artifactId>
5749
<version>2.3.8</version>
@@ -364,6 +356,14 @@
364356
<version>1.13.3</version>
365357
</dependency>
366358

359+
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus-simpleclient -->
360+
<dependency>
361+
<groupId>io.micrometer</groupId>
362+
<artifactId>micrometer-registry-prometheus-simpleclient</artifactId>
363+
<version>1.13.3</version>
364+
</dependency>
365+
366+
367367
<dependency>
368368
<groupId>com.zaxxer</groupId>
369369
<artifactId>HikariCP</artifactId>

src/main/resources/application.yaml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
#Uncomment the "servlet" and "context-path" lines below to make the fhir endpoint available at /example/path/fhir instead of the default value of /fhir
22
server:
3-
# servlet:
4-
# context-path: /example/path
3+
# servlet:
4+
# context-path: /example/path
55
port: 8080
66
#Adds the option to go to eg. http://localhost:8080/actuator/health for seeing the running configuration
77
#see https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints
88
management:
9+
#The following configuration will enable the actuator endpoints at /actuator/health, /actuator/info, /actuator/prometheus, /actuator/metrics. For security purposes, only /actuator/health is enabled by default.
10+
endpoints:
11+
enabled-by-default: false
12+
web:
13+
exposure:
14+
include: 'health' # or e.g. 'info,health,prometheus,metrics' or '*' for all'
915
endpoint:
10-
endpoints:
11-
enabled-by-default: false
12-
web:
13-
exposure:
14-
include: health,prometheus
16+
info:
17+
enabled: true
18+
metrics:
19+
enabled: true
1520
health:
1621
enabled: true
1722
probes:
1823
enabled: true
19-
livenessState:
20-
enabled: true
21-
readinessState:
22-
enabled: true
24+
group:
25+
liveness:
26+
include:
27+
- livenessState
28+
- readinessState
2329
prometheus:
2430
enabled: true
25-
metrics:
26-
export:
27-
enabled: true
28-
31+
prometheus:
32+
metrics:
33+
export:
34+
enabled: true
2935
spring:
3036
main:
3137
allow-circular-references: true

src/main/resources/cds.application.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,32 @@ server:
66
#Adds the option to go to eg. http://localhost:8080/actuator/health for seeing the running configuration
77
#see https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints
88
management:
9+
#The following configuration will enable the actuator endpoints at /actuator/health, /actuator/info, /actuator/prometheus, /actuator/metrics. For security purposes, only /actuator/health is enabled by default.
910
endpoints:
11+
enabled-by-default: false
1012
web:
1113
exposure:
12-
include: "health,prometheus"
14+
include: 'health' # or e.g. 'info,health,prometheus,metrics' or '*' for all'
15+
endpoint:
16+
info:
17+
enabled: true
18+
metrics:
19+
enabled: true
20+
health:
21+
enabled: true
22+
probes:
23+
enabled: true
24+
group:
25+
liveness:
26+
include:
27+
- livenessState
28+
- readinessState
29+
prometheus:
30+
enabled: true
31+
prometheus:
32+
metrics:
33+
export:
34+
enabled: true
1335
spring:
1436
main:
1537
allow-circular-references: true

src/test/java/ca/uhn/fhir/jpa/starter/ExampleServerR4IT.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import jakarta.websocket.ContainerProvider;
1414
import jakarta.websocket.Session;
1515
import jakarta.websocket.WebSocketContainer;
16+
import org.apache.http.client.methods.CloseableHttpResponse;
17+
import org.apache.http.client.methods.HttpGet;
18+
import org.apache.http.impl.client.CloseableHttpClient;
19+
import org.apache.http.impl.client.HttpClients;
1620
import org.hl7.fhir.instance.model.api.IBaseResource;
1721
import org.hl7.fhir.instance.model.api.IIdType;
1822
import org.hl7.fhir.r4.model.Bundle;
@@ -29,6 +33,8 @@
2933
import org.junit.jupiter.api.BeforeEach;
3034
import org.junit.jupiter.api.Order;
3135
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.params.ParameterizedTest;
37+
import org.junit.jupiter.params.provider.ValueSource;
3238
import org.springframework.beans.factory.annotation.Autowired;
3339
import org.springframework.boot.test.context.SpringBootTest;
3440
import org.springframework.boot.test.web.server.LocalServerPort;
@@ -306,6 +312,17 @@ private int activeSubscriptionCount() {
306312
.size();
307313
}
308314

315+
@ParameterizedTest
316+
@ValueSource(strings = {"prometheus", "health", "metrics", "info"})
317+
void testActuatorEndpointExists(String endpoint) throws IOException {
318+
319+
CloseableHttpClient httpclient = HttpClients.createDefault();
320+
CloseableHttpResponse response = httpclient.execute(new HttpGet("http://localhost:" + port + "/actuator/" + endpoint));
321+
int statusCode = response.getStatusLine().getStatusCode();
322+
assertEquals(200, statusCode);
323+
324+
}
325+
309326
@BeforeEach
310327
void beforeEach() {
311328

src/test/resources/application.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
management:
2+
#The following configuration will enable the actuator endpoints at /actuator/health, /actuator/info, /actuator/prometheus
3+
endpoints:
4+
enabled-by-default: false
5+
web:
6+
exposure:
7+
include: 'info,health,prometheus,metrics' # or '*' for all'
8+
endpoint:
9+
info:
10+
enabled: true
11+
metrics:
12+
enabled: true
13+
health:
14+
enabled: true
15+
probes:
16+
enabled: true
17+
group:
18+
liveness:
19+
include:
20+
- livenessState
21+
- readinessState
22+
prometheus:
23+
enabled: true
24+
prometheus:
25+
metrics:
26+
export:
27+
enabled: true
128
spring:
229
main:
330
allow-circular-references: true

0 commit comments

Comments
 (0)