Skip to content

Commit 3662341

Browse files
committed
nullaway
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent d9e1e77 commit 3662341

File tree

18 files changed

+74
-71
lines changed

18 files changed

+74
-71
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
package io.prometheus.metrics.config;
22

33
import java.util.Map;
4+
import javax.annotation.Nullable;
45

56
public class ExporterPushgatewayProperties {
67

78
private static final String ADDRESS = "address";
89
private static final String JOB = "job";
910
private static final String SCHEME = "scheme";
1011
private static final String PREFIX = "io.prometheus.exporter.pushgateway";
11-
private final String scheme;
12-
private final String address;
13-
private final String job;
12+
@Nullable private final String scheme;
13+
@Nullable private final String address;
14+
@Nullable private final String job;
1415

15-
private ExporterPushgatewayProperties(String address, String job, String scheme) {
16+
private ExporterPushgatewayProperties(
17+
@Nullable String address, @Nullable String job, @Nullable String scheme) {
1618
this.address = address;
1719
this.job = job;
1820
this.scheme = scheme;
1921
}
2022

2123
/** Address of the Pushgateway in the form {@code host:port}. Default is {@code localhost:9091} */
24+
@Nullable
2225
public String getAddress() {
2326
return address;
2427
}
@@ -27,6 +30,7 @@ public String getAddress() {
2730
* {@code job} label for metrics being pushed. Default is the name of the JAR file that is
2831
* running.
2932
*/
33+
@Nullable
3034
public String getJob() {
3135
return job;
3236
}
@@ -35,6 +39,7 @@ public String getJob() {
3539
* Scheme to be used when pushing metrics to the pushgateway. Must be "http" or "https". Default
3640
* is "http".
3741
*/
42+
@Nullable
3843
public String getScheme() {
3944
return scheme;
4045
}
@@ -67,7 +72,6 @@ public static class Builder {
6772
@Nullable private String address;
6873
@Nullable private String job;
6974
@Nullable private String scheme;
70-
@Nullable private EscapingScheme escapingScheme;
7175

7276
private Builder() {}
7377

@@ -86,13 +90,8 @@ public Builder scheme(String scheme) {
8690
return this;
8791
}
8892

89-
public Builder escapingScheme(EscapingScheme escapingScheme) {
90-
this.escapingScheme = escapingScheme;
91-
return this;
92-
}
93-
9493
public ExporterPushgatewayProperties build() {
95-
return new ExporterPushgatewayProperties(address, job, scheme, escapingScheme);
94+
return new ExporterPushgatewayProperties(address, job, scheme);
9695
}
9796
}
9897
}

prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPushgatewayPropertiesTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ void builder() {
4040
.address("http://localhost")
4141
.job("job")
4242
.scheme("http")
43-
.escapingScheme(EscapingScheme.DOTS_ESCAPING)
4443
.build();
4544

4645
assertThat(properties.getAddress()).isEqualTo("http://localhost");
4746
assertThat(properties.getJob()).isEqualTo("job");
4847
assertThat(properties.getScheme()).isEqualTo("http");
49-
assertThat(properties.getEscapingScheme()).isEqualTo(EscapingScheme.DOTS_ESCAPING);
5048
}
5149
}

prometheus-metrics-exporter-pushgateway/src/main/java/io/prometheus/metrics/exporter/pushgateway/PushGateway.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,6 @@ private String getJob(@Nullable ExporterPushgatewayProperties properties) {
434434
}
435435
}
436436

437-
private EscapingScheme getEscapingScheme(ExporterPushgatewayProperties properties) {
438-
if (properties != null && properties.getEscapingScheme() != null) {
439-
return properties.getEscapingScheme();
440-
}
441-
return EscapingScheme.NO_ESCAPING;
442-
}
443-
444437
private Format getFormat() {
445438
// currently not configurable via properties
446439
if (this.format != null) {

prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExports.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.dropwizard.metrics5.Meter;
77
import io.dropwizard.metrics5.Metric;
88
import io.dropwizard.metrics5.MetricFilter;
9+
import io.dropwizard.metrics5.MetricName;
910
import io.dropwizard.metrics5.MetricRegistry;
1011
import io.dropwizard.metrics5.Snapshot;
1112
import io.dropwizard.metrics5.Timer;
@@ -224,10 +225,10 @@ public MetricSnapshots collect() {
224225

225226
private <T> void collectMetricKind(
226227
MetricSnapshots.Builder builder,
227-
Map<String, T> metric,
228+
Map<MetricName, T> metric,
228229
BiFunction<String, T, MetricSnapshot> toSnapshot) {
229-
for (Map.Entry<String, T> entry : metric.entrySet()) {
230-
String metricName = entry.getKey();
230+
for (Map.Entry<MetricName, T> entry : metric.entrySet()) {
231+
String metricName = entry.getKey().getKey();
231232
try {
232233
MetricSnapshot snapshot = toSnapshot.apply(metricName, entry.getValue());
233234
if (snapshot != null) {

prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/CustomLabelMapper.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
public class CustomLabelMapper {
1414
private final List<CompiledMapperConfig> compiledMapperConfigs;
1515

16-
public CustomLabelMapper(final List<MapperConfig> mapperConfigs) {
16+
public CustomLabelMapper(List<MapperConfig> mapperConfigs) {
1717
if (mapperConfigs == null || mapperConfigs.isEmpty()) {
1818
throw new IllegalArgumentException("CustomLabelMapper needs some mapper configs!");
1919
}
2020

21-
this.compiledMapperConfigs = new ArrayList<CompiledMapperConfig>(mapperConfigs.size());
21+
this.compiledMapperConfigs = new ArrayList<>(mapperConfigs.size());
2222
for (MapperConfig config : mapperConfigs) {
2323
this.compiledMapperConfigs.add(new CompiledMapperConfig(config));
2424
}
2525
}
2626

27-
public String getName(final String dropwizardName) {
27+
public String getName(String dropwizardName) {
2828
if (dropwizardName == null) {
2929
throw new IllegalArgumentException("Dropwizard metric name cannot be null");
3030
}
@@ -73,8 +73,8 @@ public Labels getLabels(
7373
return Labels.of(additionalLabelNames, additionalLabelValues);
7474
}
7575

76-
protected NameAndLabels getNameAndLabels(
77-
final MapperConfig config, final Map<String, String> parameters) {
76+
@SuppressWarnings("NullAway") // not sure if it can be null here
77+
protected NameAndLabels getNameAndLabels(MapperConfig config, Map<String, String> parameters) {
7878
final String metricName = formatTemplate(config.getName(), parameters);
7979
final List<String> labels = new ArrayList<String>(config.getLabels().size());
8080
final List<String> labelValues = new ArrayList<String>(config.getLabels().size());
@@ -86,7 +86,7 @@ protected NameAndLabels getNameAndLabels(
8686
return new NameAndLabels(metricName, labels, labelValues);
8787
}
8888

89-
private String formatTemplate(final String template, final Map<String, String> params) {
89+
private String formatTemplate(String template, Map<String, String> params) {
9090
String result = template;
9191
for (Map.Entry<String, String> entry : params.entrySet()) {
9292
result = result.replace(entry.getKey(), entry.getValue());
@@ -99,7 +99,8 @@ static class CompiledMapperConfig {
9999
final MapperConfig mapperConfig;
100100
final GraphiteNamePattern pattern;
101101

102-
CompiledMapperConfig(final MapperConfig mapperConfig) {
102+
@SuppressWarnings("NullAway") // not sure if it can be null here
103+
CompiledMapperConfig(MapperConfig mapperConfig) {
103104
this.mapperConfig = mapperConfig;
104105
this.pattern = new GraphiteNamePattern(mapperConfig.getMatch());
105106
}

prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/GraphiteNamePattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class GraphiteNamePattern {
3131
*
3232
* @param pattern The glob style pattern to be used.
3333
*/
34-
GraphiteNamePattern(final String pattern) throws IllegalArgumentException {
34+
GraphiteNamePattern(String pattern) throws IllegalArgumentException {
3535
if (!VALIDATION_PATTERN.matcher(pattern).matches()) {
3636
throw new IllegalArgumentException(
3737
String.format("Provided pattern [%s] does not matches [%s]", pattern, METRIC_GLOB_REGEX));

prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/labels/MapperConfig.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.HashMap;
44
import java.util.Map;
55
import java.util.regex.Pattern;
6+
import javax.annotation.Nullable;
67

78
/**
89
* POJO containing info on how to map a graphite metric to a prometheus one. Example mapping in yaml
@@ -30,7 +31,7 @@ public final class MapperConfig {
3031
* allowed. E.g: org.company.controller.*.status.* Will be used to match
3132
* org.company.controller.controller1.status.200 and org.company.controller.controller2.status.400
3233
*/
33-
private String match;
34+
@Nullable private String match;
3435

3536
/**
3637
* New metric name. Can contain placeholders to be replaced with actual values from the incoming
@@ -41,7 +42,7 @@ public final class MapperConfig {
4142
* <p>A metric "test.dispatcher.old.test.yay" will be converted in a new metric with name
4243
* "dispatcher_events_total_test"
4344
*/
44-
private String name;
45+
@Nullable private String name;
4546

4647
/**
4748
* Labels to be extracted from the metric name. They should contain placeholders to be replaced
@@ -54,19 +55,19 @@ public final class MapperConfig {
5455
*
5556
* <p>Label names have to match the regex ^[a-zA-Z_][a-zA-Z0-9_]+$
5657
*/
57-
private Map<String, String> labels = new HashMap<String, String>();
58+
private Map<String, String> labels = new HashMap<>();
5859

5960
public MapperConfig() {
6061
// empty constructor
6162
}
6263

6364
// for tests
64-
MapperConfig(final String match) {
65+
MapperConfig(String match) {
6566
validateMatch(match);
6667
this.match = match;
6768
}
6869

69-
public MapperConfig(final String match, final String name, final Map<String, String> labels) {
70+
public MapperConfig(String match, String name, Map<String, String> labels) {
7071
this.name = name;
7172
validateMatch(match);
7273
this.match = match;
@@ -79,33 +80,35 @@ public String toString() {
7980
return String.format("MapperConfig{match=%s, name=%s, labels=%s}", match, name, labels);
8081
}
8182

83+
@Nullable
8284
public String getMatch() {
8385
return match;
8486
}
8587

86-
public void setMatch(final String match) {
88+
public void setMatch(String match) {
8789
validateMatch(match);
8890
this.match = match;
8991
}
9092

93+
@Nullable
9194
public String getName() {
9295
return name;
9396
}
9497

95-
public void setName(final String name) {
98+
public void setName(String name) {
9699
this.name = name;
97100
}
98101

99102
public Map<String, String> getLabels() {
100103
return labels;
101104
}
102105

103-
public void setLabels(final Map<String, String> labels) {
106+
public void setLabels(Map<String, String> labels) {
104107
validateLabels(labels);
105108
this.labels = labels;
106109
}
107110

108-
private void validateMatch(final String match) {
111+
private void validateMatch(String match) {
109112
if (!MATCH_EXPRESSION_PATTERN.matcher(match).matches()) {
110113
throw new IllegalArgumentException(
111114
String.format(
@@ -114,9 +117,9 @@ private void validateMatch(final String match) {
114117
}
115118
}
116119

117-
private void validateLabels(final Map<String, String> labels) {
120+
private void validateLabels(Map<String, String> labels) {
118121
if (labels != null) {
119-
for (final String key : labels.keySet()) {
122+
for (String key : labels.keySet()) {
120123
if (!LABEL_PATTERN.matcher(key).matches()) {
121124
throw new IllegalArgumentException(
122125
String.format("Label [%s] does not match required pattern %s", match, LABEL_PATTERN));
@@ -126,7 +129,7 @@ private void validateLabels(final Map<String, String> labels) {
126129
}
127130

128131
@Override
129-
public boolean equals(final Object o) {
132+
public boolean equals(Object o) {
130133
if (this == o) {
131134
return true;
132135
}

prometheus-metrics-instrumentation-jvm/src/main/java/io/prometheus/metrics/instrumentation/jvm/JvmBufferPoolMetrics.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.lang.management.BufferPoolMXBean;
88
import java.lang.management.ManagementFactory;
99
import java.util.List;
10+
import javax.annotation.Nullable;
1011

1112
/**
1213
* JVM Buffer Pool metrics. The {@link JvmBufferPoolMetrics} are registered as part of the {@link
@@ -106,7 +107,7 @@ public static Builder builder(PrometheusProperties config) {
106107
public static class Builder {
107108

108109
private final PrometheusProperties config;
109-
private List<BufferPoolMXBean> bufferPoolBeans;
110+
@Nullable private List<BufferPoolMXBean> bufferPoolBeans;
110111

111112
private Builder(PrometheusProperties config) {
112113
this.config = config;

prometheus-metrics-instrumentation-jvm/src/main/java/io/prometheus/metrics/instrumentation/jvm/JvmClassLoadingMetrics.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.prometheus.metrics.model.registry.PrometheusRegistry;
77
import java.lang.management.ClassLoadingMXBean;
88
import java.lang.management.ManagementFactory;
9+
import javax.annotation.Nullable;
910

1011
/**
1112
* JVM Class Loading metrics. The {@link JvmClassLoadingMetrics} are registered as part of the
@@ -84,7 +85,7 @@ public static Builder builder(PrometheusProperties config) {
8485
public static class Builder {
8586

8687
private final PrometheusProperties config;
87-
private ClassLoadingMXBean classLoadingBean;
88+
@Nullable private ClassLoadingMXBean classLoadingBean;
8889

8990
private Builder(PrometheusProperties config) {
9091
this.config = config;

prometheus-metrics-instrumentation-jvm/src/main/java/io/prometheus/metrics/instrumentation/jvm/JvmCompilationMetrics.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.prometheus.metrics.model.snapshots.Unit;
99
import java.lang.management.CompilationMXBean;
1010
import java.lang.management.ManagementFactory;
11+
import javax.annotation.Nullable;
1112

1213
/**
1314
* JVM Compilation metrics. The {@link JvmCompilationMetrics} are registered as part of the {@link
@@ -70,7 +71,7 @@ public static Builder builder(PrometheusProperties config) {
7071
public static class Builder {
7172

7273
private final PrometheusProperties config;
73-
private CompilationMXBean compilationBean;
74+
@Nullable private CompilationMXBean compilationBean;
7475

7576
private Builder(PrometheusProperties config) {
7677
this.config = config;

0 commit comments

Comments
 (0)