Skip to content

Commit 7c0260f

Browse files
author
wlatif
committed
Apply PR requested changes
1 parent 6d9432b commit 7c0260f

File tree

7 files changed

+53
-101
lines changed

7 files changed

+53
-101
lines changed

plume-web-jersey-monitoring/README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Plume Web Jersey info
1+
Plume Web Jersey monitoring
22
================
33

44
This module provides utilities to expose backend monitoring API similarly to what is offered by Spring Actuator:
@@ -18,14 +18,11 @@ Add the dependency to the `pom.xml` file
1818
```
1919

2020
### Install Guice modules
21-
In your application module :
22-
1. replace `GuiceJacksonModule`by the `GuiceJacksonWithMetricsModule`
23-
2. install the `GuiceJerseyMonitoringModule`
21+
In your application module replace `GuiceJacksonModule`by the `GuiceJacksonWithMetricsModule`
2422

2523
~~`install(new GuiceJacksonModule());`~~
2624
```java
2725
install(new GuiceJacksonWithMetricsModule());
28-
install(new GuiceJerseyMonitoringModule());
2926
```
3027

3128
Features
@@ -39,9 +36,9 @@ The `HealthCheckBuilder` provides a simple API to monitor the health status of y
3936
- `build`: create a health status provider
4037

4138

42-
### ApplicationInfo
43-
The `ApplicationInfo` is a singleton object available through dependency injection.
44-
It contains the basic application information retrieved from the `Pom.xml` file.
39+
### ApplicationInfoProvider
40+
The `ApplicationInfoProvider` provides an instance of `ApplicationInfo`.
41+
It contains the basic application information retrieved from the `pom.xml` file.
4542

4643
`ApplicationInfo` content:
4744
- name
@@ -74,6 +71,7 @@ Usage example
7471
**Web-service**
7572

7673
```java
74+
import com.coreoz.plume.db.transaction.TransactionManager;
7775
import com.coreoz.plume.jersey.security.permission.PublicApi;
7876

7977
@Path("/monitor")
@@ -88,11 +86,11 @@ public class MonitoringWs {
8886
private final BasicAuthenticator<String> basicAuthenticator;
8987

9088
@Inject
91-
public MonitoringWs(ApplicationInfo applicationInfo) {
92-
this.applicationInfo = applicationInfo;
89+
public MonitoringWs(ApplicationInfoProvider applicationInfoProvider, TransactionManager transactionManager) {
90+
this.applicationInfo = applicationInfoProvider.get();
9391
// Registering health checks
9492
this.healthStatusProvider = new HealthCheckBuilder()
95-
.registerDatabaseHealthCheck()
93+
.registerDatabaseHealthCheck(transactionManager)
9694
.build();
9795

9896
// Registering metrics to monitor
@@ -112,7 +110,7 @@ public class MonitoringWs {
112110
@Path("/info")
113111
public ApplicationInfo get(@Context ContainerRequestContext requestContext) {
114112
basicAuthenticator.requireAuthentication(requestContext);
115-
return this.infoService.getAppInfo();
113+
return this.applicationInfo;
116114
}
117115

118116
@GET

plume-web-jersey-monitoring/pom.xml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@
3131
<groupId>com.coreoz</groupId>
3232
<artifactId>plume-conf</artifactId>
3333
</dependency>
34+
<dependency>
35+
<groupId>com.coreoz</groupId>
36+
<artifactId>plume-web-jersey</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.coreoz</groupId>
40+
<artifactId>plume-db</artifactId>
41+
<optional>true</optional>
42+
</dependency>
3443

44+
<!-- logger -->
3545
<dependency>
3646
<groupId>org.slf4j</groupId>
3747
<artifactId>slf4j-api</artifactId>
@@ -51,30 +61,22 @@
5161
<artifactId>metrics-healthchecks</artifactId>
5262
</dependency>
5363

54-
<!-- Dependency injection -->
55-
<dependency>
56-
<groupId>javax.inject</groupId>
57-
<artifactId>javax.inject</artifactId>
58-
</dependency>
59-
6064
<!-- Pom.xml reader -->
6165
<dependency>
6266
<groupId>org.apache.maven</groupId>
6367
<artifactId>maven-model</artifactId>
6468
</dependency>
6569

66-
<dependency>
67-
<groupId>com.coreoz</groupId>
68-
<artifactId>plume-db</artifactId>
69-
<optional>true</optional>
70-
</dependency>
70+
<!-- dependency injection -->
7171
<dependency>
7272
<groupId>com.google.inject</groupId>
7373
<artifactId>guice</artifactId>
7474
</dependency>
75+
76+
<!-- lombok -->
7577
<dependency>
76-
<groupId>com.coreoz</groupId>
77-
<artifactId>plume-web-jersey</artifactId>
78+
<groupId>org.projectlombok</groupId>
79+
<artifactId>lombok</artifactId>
7880
</dependency>
7981
</dependencies>
8082

plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/guice/GuiceJerseyMonitoringModule.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/json/JerseyMonitoringObjectMapperProvider.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,16 @@
1515
@Singleton
1616
public class JerseyMonitoringObjectMapperProvider implements Provider<ObjectMapper> {
1717
private final ObjectMapper objectMapper;
18-
private static final HealthCheckModule healthCheckModule = new HealthCheckModule();
19-
private static final MetricsModule metricsModule = new MetricsModule(
20-
TimeUnit.SECONDS,
21-
TimeUnit.SECONDS,
22-
false
23-
);
2418

2519
@Inject
2620
public JerseyMonitoringObjectMapperProvider(ObjectMapperProvider objectMapperProvider) {
2721
this.objectMapper = objectMapperProvider.get()
28-
.registerModule(healthCheckModule)
29-
.registerModule(metricsModule)
22+
.registerModule(new HealthCheckModule())
23+
.registerModule(new MetricsModule(
24+
TimeUnit.SECONDS,
25+
TimeUnit.SECONDS,
26+
false
27+
))
3028
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
3129
.enable(SerializationFeature.INDENT_OUTPUT)
3230
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
package com.coreoz.plume.jersey.monitoring.utils.health.beans;
22

33
import com.codahale.metrics.health.HealthCheck;
4+
import lombok.Value;
45

56
import java.util.Map;
6-
import java.util.SortedMap;
77

8+
@Value
89
public class HealthStatus {
9-
private final boolean isHealthy;
10-
private final Map<String, HealthCheck.Result> healthChecksResults;
11-
12-
public HealthStatus(boolean isHealthy, SortedMap<String, HealthCheck.Result> healthChecksResults) {
13-
this.isHealthy = isHealthy;
14-
this.healthChecksResults = Map.copyOf(healthChecksResults);
15-
}
16-
17-
public boolean isHealthy() {
18-
return isHealthy;
19-
}
20-
21-
public Map<String, HealthCheck.Result> getHealthChecksResults() {
22-
return healthChecksResults;
23-
}
10+
boolean isHealthy;
11+
Map<String, HealthCheck.Result> healthChecksResults;
2412
}

plume-web-jersey-monitoring/src/main/java/com/coreoz/plume/jersey/monitoring/utils/info/ApplicationInfoProvider.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,30 @@
44
import com.coreoz.plume.jersey.monitoring.utils.info.beans.ApplicationInfo;
55
import org.apache.maven.model.Model;
66
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
7+
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
78

89
import javax.inject.Inject;
910
import javax.inject.Provider;
1011
import javax.inject.Singleton;
1112
import java.io.FileReader;
13+
import java.io.IOException;
1214
import java.util.Map;
1315

1416
@Singleton
1517
public class ApplicationInfoProvider implements Provider<ApplicationInfo> {
1618
private final ApplicationInfo applicationInfo;
1719

1820
@Inject
19-
private ApplicationInfoProvider(JerseyMonitoringConfigurationService configurationService) {
21+
private ApplicationInfoProvider(JerseyMonitoringConfigurationService configurationService) throws IOException, XmlPullParserException {
2022
MavenXpp3Reader reader = new MavenXpp3Reader();
21-
try {
22-
Model model = reader.read(new FileReader("pom.xml"));
23-
Map<String, Object> additionalInformation = configurationService.getCustomInfo();
24-
this.applicationInfo = new ApplicationInfo(
25-
model.getName(),
26-
model.getDescription(),
27-
model.getVersion(),
28-
additionalInformation.isEmpty() ? null : additionalInformation
29-
);
30-
} catch (Exception e) {
31-
throw new RuntimeException("Failed to retrieve the application information", e);
32-
}
23+
Model model = reader.read(new FileReader("pom.xml"));
24+
Map<String, Object> additionalInformation = configurationService.getCustomInfo();
25+
this.applicationInfo = new ApplicationInfo(
26+
model.getName(),
27+
model.getDescription(),
28+
model.getVersion(),
29+
additionalInformation.isEmpty() ? null : additionalInformation
30+
);
3331
}
3432

3533
@Override
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
11
package com.coreoz.plume.jersey.monitoring.utils.info.beans;
22

3+
import lombok.Value;
4+
35
import java.util.Map;
46

7+
@Value
58
public class ApplicationInfo {
6-
private final String name;
7-
private final String description;
8-
private final String version;
9-
private final Map<String, Object> additionalInformation;
10-
11-
public ApplicationInfo(String name, String description, String version, Map<String, Object> additionalInformation) {
12-
this.name = name;
13-
this.description = description;
14-
this.version = version;
15-
this.additionalInformation = additionalInformation;
16-
}
17-
18-
public String getName() {
19-
return name;
20-
}
21-
22-
public String getDescription() {
23-
return description;
24-
}
25-
26-
public String getVersion() {
27-
return version;
28-
}
29-
30-
public Map<String, Object> getAdditionalInformation() {
31-
return additionalInformation;
32-
}
9+
String name;
10+
String description;
11+
String version;
12+
Map<String, Object> additionalInformation;
3313
}

0 commit comments

Comments
 (0)