Skip to content

Commit 27ffb91

Browse files
authored
add test Coverage check (#1159)
* add coverage check Signed-off-by: Gregor Zeitlinger <[email protected]> * add coverage check Signed-off-by: Gregor Zeitlinger <[email protected]> * add coverage check Signed-off-by: Gregor Zeitlinger <[email protected]> * add coverage check Signed-off-by: Gregor Zeitlinger <[email protected]> * add coverage check Signed-off-by: Gregor Zeitlinger <[email protected]> * add coverage check Signed-off-by: Gregor Zeitlinger <[email protected]> * add coverage check Signed-off-by: Gregor Zeitlinger <[email protected]> --------- Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 413f889 commit 27ffb91

File tree

50 files changed

+1071
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1071
-85
lines changed

benchmarks/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<jmh.version>1.37</jmh.version>
2121
<simpleclient.version>0.16.0</simpleclient.version>
2222
<codahale.version>3.0.2</codahale.version>
23+
<jacoco.line-coverage>0.0</jacoco.line-coverage>
2324
</properties>
2425

2526
<dependencyManagement>

examples/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
Example projects for the Prometheus Metrics Library.
1717
</description>
1818

19+
<properties>
20+
<jacoco.line-coverage>0.0</jacoco.line-coverage>
21+
</properties>
22+
1923
<modules>
2024
<module>example-exemplars-tail-sampling</module>
2125
<module>example-exporter-servlet-tomcat</module>

integration-tests/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
Integration tests for the Exporter modules
1919
</description>
2020

21+
<properties>
22+
<jacoco.line-coverage>0.0</jacoco.line-coverage>
23+
</properties>
24+
2125
<modules>
2226
<module>it-common</module>
2327
<module>it-exporter</module>

otel-agent-resources/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
<otel-dynamic-load.version>1.29.0</otel-dynamic-load.version>
2424
</properties>
2525

26-
<dependencies>
27-
</dependencies>
28-
2926
<build>
3027
<resources>
3128
<resource>

pom.xml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<junit-jupiter.version>5.11.2</junit-jupiter.version>
2121
<otel.instrumentation.version>2.8.0-alpha</otel.instrumentation.version>
2222
<java.version>8</java.version>
23+
<jacoco.line-coverage>0.70</jacoco.line-coverage>
2324
</properties>
2425

2526
<licenses>
@@ -76,6 +77,16 @@
7677
<module>otel-agent-resources</module>
7778
</modules>
7879

80+
<dependencyManagement>
81+
<dependencies>
82+
<dependency>
83+
<groupId>com.google.guava</groupId>
84+
<artifactId>guava</artifactId>
85+
<version>33.3.1-jre</version>
86+
</dependency>
87+
</dependencies>
88+
</dependencyManagement>
89+
7990
<dependencies>
8091
<dependency>
8192
<groupId>org.junit.jupiter</groupId>
@@ -101,12 +112,23 @@
101112
<version>3.26.3</version>
102113
<scope>test</scope>
103114
</dependency>
115+
<dependency>
116+
<groupId>com.google.guava</groupId>
117+
<artifactId>guava</artifactId>
118+
<scope>test</scope>
119+
</dependency>
104120
<dependency>
105121
<groupId>org.slf4j</groupId>
106122
<artifactId>slf4j-simple</artifactId>
107123
<version>1.7.36</version>
108124
<scope>test</scope>
109125
</dependency>
126+
<dependency>
127+
<groupId>org.junit-pioneer</groupId>
128+
<artifactId>junit-pioneer</artifactId>
129+
<version>2.3.0</version>
130+
<scope>test</scope>
131+
</dependency>
110132
</dependencies>
111133

112134
<build>
@@ -200,6 +222,50 @@
200222
</execution>
201223
</executions>
202224
</plugin>
225+
<plugin>
226+
<groupId>org.jacoco</groupId>
227+
<artifactId>jacoco-maven-plugin</artifactId>
228+
<version>0.8.12</version>
229+
<configuration>
230+
<excludes>
231+
<exclude>**/generated/**</exclude>
232+
</excludes>
233+
</configuration>
234+
<executions>
235+
<execution>
236+
<goals>
237+
<goal>prepare-agent</goal>
238+
</goals>
239+
</execution>
240+
<execution>
241+
<id>report</id>
242+
<phase>test</phase>
243+
<goals>
244+
<goal>report</goal>
245+
</goals>
246+
</execution>
247+
<execution>
248+
<id>check</id>
249+
<goals>
250+
<goal>check</goal>
251+
</goals>
252+
<configuration>
253+
<rules>
254+
<rule>
255+
<element>CLASS</element>
256+
<limits>
257+
<limit>
258+
<counter>LINE</counter>
259+
<value>COVEREDRATIO</value>
260+
<minimum>${jacoco.line-coverage}</minimum>
261+
</limit>
262+
</limits>
263+
</rule>
264+
</rules>
265+
</configuration>
266+
</execution>
267+
</executions>
268+
</plugin>
203269
<plugin>
204270
<groupId>org.apache.maven.plugins</groupId>
205271
<artifactId>maven-enforcer-plugin</artifactId>

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExemplarsProperties.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/** Properties starting with io.prometheus.exemplars */
66
public class ExemplarsProperties {
77

8+
private static final String PREFIX = "io.prometheus.exemplars";
89
private static final String MIN_RETENTION_PERIOD_SECONDS = "minRetentionPeriodSeconds";
910
private static final String MAX_RETENTION_PERIOD_SECONDS = "maxRetentionPeriodSeconds";
1011
private static final String SAMPLE_INTERVAL_MILLISECONDS = "sampleIntervalMilliseconds";
@@ -55,42 +56,42 @@ public Integer getSampleIntervalMilliseconds() {
5556
* Note that this will remove entries from {@code properties}. This is because we want to know if
5657
* there are unused properties remaining after all properties have been loaded.
5758
*/
58-
static ExemplarsProperties load(String prefix, Map<Object, Object> properties)
59+
static ExemplarsProperties load(Map<Object, Object> properties)
5960
throws PrometheusPropertiesException {
6061
Integer minRetentionPeriodSeconds =
61-
Util.loadInteger(prefix + "." + MIN_RETENTION_PERIOD_SECONDS, properties);
62+
Util.loadInteger(PREFIX + "." + MIN_RETENTION_PERIOD_SECONDS, properties);
6263
Integer maxRetentionPeriodSeconds =
63-
Util.loadInteger(prefix + "." + MAX_RETENTION_PERIOD_SECONDS, properties);
64+
Util.loadInteger(PREFIX + "." + MAX_RETENTION_PERIOD_SECONDS, properties);
6465
Integer sampleIntervalMilliseconds =
65-
Util.loadInteger(prefix + "." + SAMPLE_INTERVAL_MILLISECONDS, properties);
66+
Util.loadInteger(PREFIX + "." + SAMPLE_INTERVAL_MILLISECONDS, properties);
6667

6768
Util.assertValue(
6869
minRetentionPeriodSeconds,
6970
t -> t > 0,
7071
"Expecting value > 0.",
71-
prefix,
72+
PREFIX,
7273
MIN_RETENTION_PERIOD_SECONDS);
7374
Util.assertValue(
74-
minRetentionPeriodSeconds,
75+
maxRetentionPeriodSeconds,
7576
t -> t > 0,
7677
"Expecting value > 0.",
77-
prefix,
78+
PREFIX,
7879
MAX_RETENTION_PERIOD_SECONDS);
7980
Util.assertValue(
8081
sampleIntervalMilliseconds,
8182
t -> t > 0,
8283
"Expecting value > 0.",
83-
prefix,
84+
PREFIX,
8485
SAMPLE_INTERVAL_MILLISECONDS);
8586

8687
if (minRetentionPeriodSeconds != null && maxRetentionPeriodSeconds != null) {
8788
if (minRetentionPeriodSeconds > maxRetentionPeriodSeconds) {
8889
throw new PrometheusPropertiesException(
89-
prefix
90+
PREFIX
9091
+ "."
9192
+ MIN_RETENTION_PERIOD_SECONDS
9293
+ " must not be greater than "
93-
+ prefix
94+
+ PREFIX
9495
+ "."
9596
+ MAX_RETENTION_PERIOD_SECONDS
9697
+ ".");

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterFilterProperties.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ExporterFilterProperties {
1313
public static final String METRIC_NAME_MUST_NOT_BE_EQUAL_TO = "metricNameMustNotBeEqualTo";
1414
public static final String METRIC_NAME_MUST_START_WITH = "metricNameMustStartWith";
1515
public static final String METRIC_NAME_MUST_NOT_START_WITH = "metricNameMustNotStartWith";
16+
private static final String PREFIX = "io.prometheus.exporter.filter";
1617

1718
private final List<String> allowedNames;
1819
private final List<String> excludedNames;
@@ -58,16 +59,16 @@ public List<String> getExcludedMetricNamePrefixes() {
5859
* Note that this will remove entries from {@code properties}. This is because we want to know if
5960
* there are unused properties remaining after all properties have been loaded.
6061
*/
61-
static ExporterFilterProperties load(String prefix, Map<Object, Object> properties)
62+
static ExporterFilterProperties load(Map<Object, Object> properties)
6263
throws PrometheusPropertiesException {
6364
List<String> allowedNames =
64-
Util.loadStringList(prefix + "." + METRIC_NAME_MUST_BE_EQUAL_TO, properties);
65+
Util.loadStringList(PREFIX + "." + METRIC_NAME_MUST_BE_EQUAL_TO, properties);
6566
List<String> excludedNames =
66-
Util.loadStringList(prefix + "." + METRIC_NAME_MUST_NOT_BE_EQUAL_TO, properties);
67+
Util.loadStringList(PREFIX + "." + METRIC_NAME_MUST_NOT_BE_EQUAL_TO, properties);
6768
List<String> allowedPrefixes =
68-
Util.loadStringList(prefix + "." + METRIC_NAME_MUST_START_WITH, properties);
69+
Util.loadStringList(PREFIX + "." + METRIC_NAME_MUST_START_WITH, properties);
6970
List<String> excludedPrefixes =
70-
Util.loadStringList(prefix + "." + METRIC_NAME_MUST_NOT_START_WITH, properties);
71+
Util.loadStringList(PREFIX + "." + METRIC_NAME_MUST_NOT_START_WITH, properties);
7172
return new ExporterFilterProperties(
7273
allowedNames, excludedNames, allowedPrefixes, excludedPrefixes);
7374
}

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterHttpServerProperties.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public class ExporterHttpServerProperties {
77

88
private static final String PORT = "port";
9+
private static final String PREFIX = "io.prometheus.exporter.httpServer";
910
private final Integer port;
1011

1112
private ExporterHttpServerProperties(Integer port) {
@@ -20,10 +21,10 @@ public Integer getPort() {
2021
* Note that this will remove entries from {@code properties}. This is because we want to know if
2122
* there are unused properties remaining after all properties have been loaded.
2223
*/
23-
static ExporterHttpServerProperties load(String prefix, Map<Object, Object> properties)
24+
static ExporterHttpServerProperties load(Map<Object, Object> properties)
2425
throws PrometheusPropertiesException {
25-
Integer port = Util.loadInteger(prefix + "." + PORT, properties);
26-
Util.assertValue(port, t -> t > 0, "Expecting value > 0", prefix, PORT);
26+
Integer port = Util.loadInteger(PREFIX + "." + PORT, properties);
27+
Util.assertValue(port, t -> t > 0, "Expecting value > 0.", PREFIX, PORT);
2728
return new ExporterHttpServerProperties(port);
2829
}
2930

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterOpenTelemetryProperties.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class ExporterOpenTelemetryProperties {
1919
private static final String SERVICE_VERSION = "serviceVersion";
2020
private static final String RESOURCE_ATTRIBUTES =
2121
"resourceAttributes"; // otel.resource.attributes
22+
private static final String PREFIX = "io.prometheus.exporter.opentelemetry";
2223

2324
private final String protocol;
2425
private final String endpoint;
@@ -98,19 +99,19 @@ public Map<String, String> getResourceAttributes() {
9899
* Note that this will remove entries from {@code properties}. This is because we want to know if
99100
* there are unused properties remaining after all properties have been loaded.
100101
*/
101-
static ExporterOpenTelemetryProperties load(String prefix, Map<Object, Object> properties)
102+
static ExporterOpenTelemetryProperties load(Map<Object, Object> properties)
102103
throws PrometheusPropertiesException {
103-
String protocol = Util.loadString(prefix + "." + PROTOCOL, properties);
104-
String endpoint = Util.loadString(prefix + "." + ENDPOINT, properties);
105-
Map<String, String> headers = Util.loadMap(prefix + "." + HEADERS, properties);
106-
String interval = Util.loadStringAddSuffix(prefix + "." + INTERVAL_SECONDS, properties, "s");
107-
String timeout = Util.loadStringAddSuffix(prefix + "." + TIMEOUT_SECONDS, properties, "s");
108-
String serviceName = Util.loadString(prefix + "." + SERVICE_NAME, properties);
109-
String serviceNamespace = Util.loadString(prefix + "." + SERVICE_NAMESPACE, properties);
110-
String serviceInstanceId = Util.loadString(prefix + "." + SERVICE_INSTANCE_ID, properties);
111-
String serviceVersion = Util.loadString(prefix + "." + SERVICE_VERSION, properties);
104+
String protocol = Util.loadString(PREFIX + "." + PROTOCOL, properties);
105+
String endpoint = Util.loadString(PREFIX + "." + ENDPOINT, properties);
106+
Map<String, String> headers = Util.loadMap(PREFIX + "." + HEADERS, properties);
107+
String interval = Util.loadStringAddSuffix(PREFIX + "." + INTERVAL_SECONDS, properties, "s");
108+
String timeout = Util.loadStringAddSuffix(PREFIX + "." + TIMEOUT_SECONDS, properties, "s");
109+
String serviceName = Util.loadString(PREFIX + "." + SERVICE_NAME, properties);
110+
String serviceNamespace = Util.loadString(PREFIX + "." + SERVICE_NAMESPACE, properties);
111+
String serviceInstanceId = Util.loadString(PREFIX + "." + SERVICE_INSTANCE_ID, properties);
112+
String serviceVersion = Util.loadString(PREFIX + "." + SERVICE_VERSION, properties);
112113
Map<String, String> resourceAttributes =
113-
Util.loadMap(prefix + "." + RESOURCE_ATTRIBUTES, properties);
114+
Util.loadMap(PREFIX + "." + RESOURCE_ATTRIBUTES, properties);
114115
return new ExporterOpenTelemetryProperties(
115116
protocol,
116117
endpoint,

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterProperties.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class ExporterProperties {
77

88
private static final String INCLUDE_CREATED_TIMESTAMPS = "includeCreatedTimestamps";
99
private static final String EXEMPLARS_ON_ALL_METRIC_TYPES = "exemplarsOnAllMetricTypes";
10+
private static final String PREFIX = "io.prometheus.exporter";
1011

1112
private final Boolean includeCreatedTimestamps;
1213
private final Boolean exemplarsOnAllMetricTypes;
@@ -33,12 +34,12 @@ public boolean getExemplarsOnAllMetricTypes() {
3334
* Note that this will remove entries from {@code properties}. This is because we want to know if
3435
* there are unused properties remaining after all properties have been loaded.
3536
*/
36-
static ExporterProperties load(String prefix, Map<Object, Object> properties)
37+
static ExporterProperties load(Map<Object, Object> properties)
3738
throws PrometheusPropertiesException {
3839
Boolean includeCreatedTimestamps =
39-
Util.loadBoolean(prefix + "." + INCLUDE_CREATED_TIMESTAMPS, properties);
40+
Util.loadBoolean(PREFIX + "." + INCLUDE_CREATED_TIMESTAMPS, properties);
4041
Boolean exemplarsOnAllMetricTypes =
41-
Util.loadBoolean(prefix + "." + EXEMPLARS_ON_ALL_METRIC_TYPES, properties);
42+
Util.loadBoolean(PREFIX + "." + EXEMPLARS_ON_ALL_METRIC_TYPES, properties);
4243
return new ExporterProperties(includeCreatedTimestamps, exemplarsOnAllMetricTypes);
4344
}
4445

0 commit comments

Comments
 (0)