Skip to content

Commit 7b863fa

Browse files
Add dropwizard based custom metrics client. Exclude jackson dependecy
1 parent 37a5ff6 commit 7b863fa

File tree

14 files changed

+96
-124
lines changed

14 files changed

+96
-124
lines changed
Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,56 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<parent>
6-
<groupId>com.sap.hcp.cf.logging</groupId>
7-
<artifactId>cf-java-monitoring-custom-metrics-clients</artifactId>
8-
<version>3.0.2</version>
9-
</parent>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.sap.hcp.cf.logging</groupId>
6+
<artifactId>cf-java-monitoring-custom-metrics-clients</artifactId>
7+
<version>3.0.2</version>
8+
</parent>
109

11-
<artifactId>cf-custom-metrics-clients-core</artifactId>
12-
<packaging>jar</packaging>
13-
<name>cf-java-monitoring-custom-metrics-clients-core</name>
10+
<artifactId>cf-custom-metrics-clients-core</artifactId>
11+
<packaging>jar</packaging>
12+
<name>cf-java-monitoring-custom-metrics-clients-core</name>
1413

15-
<dependencies>
16-
<dependency>
17-
<groupId>org.apache.httpcomponents</groupId>
18-
<artifactId>httpclient</artifactId>
19-
</dependency>
20-
<dependency>
21-
<groupId>com.google.code.gson</groupId>
22-
<artifactId>gson</artifactId>
23-
</dependency>
24-
<dependency>
25-
<groupId>org.slf4j</groupId>
26-
<artifactId>slf4j-api</artifactId>
27-
<scope>provided</scope>
28-
</dependency>
29-
<!-- Test dependencies-->
30-
<dependency>
31-
<groupId>junit</groupId>
32-
<artifactId>junit</artifactId>
33-
<scope>test</scope>
34-
</dependency>
35-
<dependency>
36-
<groupId>org.mockito</groupId>
37-
<artifactId>mockito-all</artifactId>
38-
<scope>test</scope>
39-
</dependency>
40-
</dependencies>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.apache.httpcomponents</groupId>
17+
<artifactId>httpclient</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>com.google.code.gson</groupId>
21+
<artifactId>gson</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.slf4j</groupId>
25+
<artifactId>slf4j-api</artifactId>
26+
<scope>provided</scope>
27+
</dependency>
28+
<!-- Test dependencies -->
29+
<dependency>
30+
<groupId>junit</groupId>
31+
<artifactId>junit</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.mockito</groupId>
36+
<artifactId>mockito-all</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
</dependencies>
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-jar-plugin</artifactId>
45+
<version>3.0.2</version>
46+
<executions>
47+
<execution>
48+
<goals>
49+
<goal>test-jar</goal>
50+
</goals>
51+
</execution>
52+
</executions>
53+
</plugin>
54+
</plugins>
55+
</build>
4156
</project>

cf-java-monitoring-custom-metrics-clients/cf-custom-metrics-clients-core/src/test/java/com/sap/cloud/cf/monitoring/client/configuration/EnvUtils.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import java.lang.reflect.Field;
44
import java.util.Collections;
5-
import java.util.HashMap;
65
import java.util.Map;
6+
import java.util.stream.Collectors;
7+
import java.util.stream.Stream;
78

89
public class EnvUtils {
910

1011
public static void setEnvs(String[][] envs) throws Exception {
11-
Map<String, String> envMap = new HashMap<>();
12-
for (String[] env : envs) {
13-
envMap.put(env[0], env[1]);
14-
}
12+
Map<String, String> envMap = Stream.of(envs).collect(Collectors.toMap(data -> data[0], data -> data[1]));
1513

1614
setNewEnvs(envMap);
1715
}
@@ -31,5 +29,4 @@ private static void setNewEnvs(Map<String, String> newenv) throws Exception {
3129
}
3230
}
3331
}
34-
35-
}
32+
}

cf-java-monitoring-custom-metrics-clients/cf-custom-metrics-clients-java/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,13 @@
4444
<artifactId>mockito-all</artifactId>
4545
<scope>test</scope>
4646
</dependency>
47+
<dependency>
48+
<groupId>com.sap.hcp.cf.logging</groupId>
49+
<artifactId>cf-custom-metrics-clients-core</artifactId>
50+
<version>${project.version}</version>
51+
<classifier>tests</classifier>
52+
<type>test-jar</type>
53+
<scope>test</scope>
54+
</dependency>
4755
</dependencies>
4856
</project>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.sap.cloud.cf.monitoring.java.converter;
22

3-
import java.util.Arrays;
3+
import java.util.ArrayList;
44
import java.util.List;
55
import java.util.Map.Entry;
66

@@ -11,8 +11,10 @@ public final class CounterConverter extends MetricConverter<Counter> {
1111

1212
@Override
1313
protected List<Metric> convertMetricEntry(Entry<String, Counter> metricEntry, long timestamp) {
14+
List<Metric> result = new ArrayList<>();
1415
Counter counter = metricEntry.getValue();
15-
return Arrays.asList(buildCustomMetric(metricEntry.getKey() + ".count", counter.getCount(), MetricType.COUNTER,
16-
timestamp));
16+
result.add(buildCustomMetric(metricEntry.getKey() + ".count", counter.getCount(), MetricType.COUNTER, timestamp));
17+
18+
return result;
1719
}
1820
}

cf-java-monitoring-custom-metrics-clients/cf-custom-metrics-clients-java/src/main/java/com/sap/cloud/cf/monitoring/java/converter/GaugeConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public final class GaugeConverter extends MetricConverter<Gauge> {
1111

1212
@Override
1313
protected List<Metric> convertMetricEntry(Entry<String, Gauge> metricEntry, long timestamp) {
14-
ArrayList<Metric> result = new ArrayList<>();
14+
List<Metric> result = new ArrayList<>();
1515
Object gaugeValue = metricEntry.getValue().getValue();
1616
if (gaugeValue instanceof Number) {
1717
Number number = (Number) gaugeValue;
1818
result.add(buildCustomMetric(metricEntry.getKey() + ".value", number.doubleValue(), MetricType.GAUGE,
1919
timestamp));
2020
} else {
21-
throw new IllegalArgumentException();
21+
throw new IllegalArgumentException(String.format("The type for Gauge {%s} is invalid. The supported type is {%s}", gaugeValue.getClass().getName(), Number.class.getName()));
2222
}
2323
return result;
2424
}

cf-java-monitoring-custom-metrics-clients/cf-custom-metrics-clients-java/src/main/java/com/sap/cloud/cf/monitoring/java/converter/HistogramConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public HistogramConverter(boolean metricQuantiles) {
1818

1919
@Override
2020
protected List<Metric> convertMetricEntry(Entry<String, Histogram> metricEntry, long timestamp) {
21-
ArrayList<Metric> result = new ArrayList<>();
21+
List<Metric> result = new ArrayList<>();
2222
Histogram histogram = metricEntry.getValue();
2323
Snapshot snapshot = histogram.getSnapshot();
2424
String key = metricEntry.getKey();

cf-java-monitoring-custom-metrics-clients/cf-custom-metrics-clients-java/src/main/java/com/sap/cloud/cf/monitoring/java/converter/MeterConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public MeterConverter(boolean metricQuantiles) {
1717

1818
@Override
1919
protected List<Metric> convertMetricEntry(Entry<String, Meter> metricEntry, long timestamp) {
20-
ArrayList<Metric> result = new ArrayList<>();
20+
List<Metric> result = new ArrayList<>();
2121
Meter meter = metricEntry.getValue();
2222
String key = metricEntry.getKey();
2323
MetricType type = MetricType.METER;

cf-java-monitoring-custom-metrics-clients/cf-custom-metrics-clients-java/src/main/java/com/sap/cloud/cf/monitoring/java/converter/TimerConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public TimerConverter(boolean metricQuantiles) {
1818

1919
@Override
2020
protected List<Metric> convertMetricEntry(Entry<String, Timer> metricEntry, long timestamp) {
21-
ArrayList<Metric> result = new ArrayList<>();
21+
List<Metric> result = new ArrayList<>();
2222
Timer timer = metricEntry.getValue();
2323
Snapshot snapshot = timer.getSnapshot();
2424
String key = metricEntry.getKey();

cf-java-monitoring-custom-metrics-clients/cf-custom-metrics-clients-java/src/test/java/com/sap/cloud/cf/monitoring/java/CustomMetricRegistryTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.codahale.metrics.MetricRegistry;
2020
import com.sap.cloud.cf.monitoring.client.configuration.CFConfigurationProvider;
21+
import com.sap.cloud.cf.monitoring.client.configuration.EnvUtils;
2122

2223
@RunWith(MockitoJUnitRunner.class)
2324
public class CustomMetricRegistryTest {

cf-java-monitoring-custom-metrics-clients/cf-custom-metrics-clients-java/src/test/java/com/sap/cloud/cf/monitoring/java/EnvUtils.java

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

0 commit comments

Comments
 (0)