Skip to content

Commit

Permalink
add Errorprone (#1139)
Browse files Browse the repository at this point in the history
* add errorprone

Signed-off-by: Gregor Zeitlinger <[email protected]>

* add errorprone

Signed-off-by: Gregor Zeitlinger <[email protected]>

* add errorprone

Signed-off-by: Gregor Zeitlinger <[email protected]>

* add errorprone

Signed-off-by: Gregor Zeitlinger <[email protected]>

* add errorprone

Signed-off-by: Gregor Zeitlinger <[email protected]>

* add errorprone

Signed-off-by: Gregor Zeitlinger <[email protected]>

* add errorprone

Signed-off-by: Gregor Zeitlinger <[email protected]>

* add errorprone

Signed-off-by: Gregor Zeitlinger <[email protected]>

---------

Signed-off-by: Gregor Zeitlinger <[email protected]>
  • Loading branch information
zeitlinger authored Oct 10, 2024
1 parent eb48f5d commit 8226348
Show file tree
Hide file tree
Showing 44 changed files with 137 additions and 142 deletions.
10 changes: 10 additions & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.prometheus.metrics.model.registry.MultiCollector;
import io.prometheus.metrics.model.registry.PrometheusScrapeRequest;
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
import io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot.Builder;
import io.prometheus.metrics.model.snapshots.GaugeSnapshot;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
Expand Down Expand Up @@ -46,7 +45,8 @@ protected MetricSnapshots collectMetricSnapshots(PrometheusScrapeRequest scrapeR
} else {
targetName = targetNames[0];
}
Builder counterDataPointBuilder = CounterSnapshot.CounterDataPointSnapshot.builder();
CounterSnapshot.CounterDataPointSnapshot.Builder counterDataPointBuilder =
CounterSnapshot.CounterDataPointSnapshot.builder();
io.prometheus.metrics.model.snapshots.GaugeSnapshot.GaugeDataPointSnapshot.Builder
gaugeDataPointBuilder = GaugeSnapshot.GaugeDataPointSnapshot.builder();
Labels lbls = Labels.of("target", targetName);
Expand Down Expand Up @@ -77,6 +77,7 @@ protected MetricSnapshots collectMetricSnapshots(PrometheusScrapeRequest scrapeR
return new MetricSnapshots(snaps);
}

@Override
public List<String> getPrometheusNames() {
List<String> names = new ArrayList<String>();
names.add("x_calls_total");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void testOpenMetricsTextFormat() throws IOException {
assertThat(response.getHeader("Transfer-Encoding")).isNull();
assertThat(response.getHeader("Content-Length"))
.isEqualTo(Integer.toString(response.body.length));
String bodyString = new String(response.body);
String bodyString = new String(response.body, UTF_8);
assertThat(bodyString)
.contains("integration_test_info{test_name=\"" + sampleApp + "\"} 1")
.contains("temperature_celsius{location=\"inside\"} 23.0")
Expand All @@ -90,7 +91,7 @@ public void testPrometheusTextFormat() throws IOException {
assertThat(response.getHeader("Transfer-Encoding")).isNull();
assertThat(response.getHeader("Content-Length"))
.isEqualTo(Integer.toString(response.body.length));
String bodyString = new String(response.body);
String bodyString = new String(response.body, UTF_8);
assertThat(bodyString)
.contains("integration_test_info{test_name=\"" + sampleApp + "\"} 1")
.contains("temperature_celsius{location=\"inside\"} 23.0")
Expand Down Expand Up @@ -370,6 +371,7 @@ private Response scrape(String method, String queryString, String... requestHead
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
// ignore
}
}
}
Expand All @@ -392,14 +394,14 @@ private Response(int status, Map<String, List<String>> headers, byte[] body) {
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
if (entry.getKey()
!= null) { // HttpUrlConnection uses pseudo key "null" for the status line
this.headers.put(entry.getKey().toLowerCase(), entry.getValue().get(0));
this.headers.put(entry.getKey().toLowerCase(Locale.ROOT), entry.getValue().get(0));
}
}
}

private String getHeader(String name) {
// HTTP headers are case-insensitive
return headers.get(name.toLowerCase());
return headers.get(name.toLowerCase(Locale.ROOT));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private static void runSslTest() throws IOException {

static TrustManager insecureTrustManager =
new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
Expand Down
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,28 @@
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
<arg>-XDcompilePolicy=simple</arg>
<arg>
-Xplugin:ErrorProne
-Xep:AlmostJavadoc:OFF
-Xep:MissingSummary:OFF
-Xep:LongDoubleConversion:OFF
-Xep:StringSplitter:OFF
-XepExcludedPaths:.*/generated/.*
</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.33.0</version>
</path>
<!-- Other annotation processors go here.
If 'annotationProcessorPaths' is set, processors will no longer be
discovered on the regular -classpath; see also 'Using Error Prone
together with other annotation processors' below. -->
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ private ExporterFilterProperties(
List<String> excludedNames,
List<String> allowedPrefixes,
List<String> excludedPrefixes) {
this(allowedNames, excludedNames, allowedPrefixes, excludedPrefixes, "");
}

private ExporterFilterProperties(
List<String> allowedNames,
List<String> excludedNames,
List<String> allowedPrefixes,
List<String> excludedPrefixes,
String prefix) {
this.allowedNames =
allowedNames == null ? null : Collections.unmodifiableList(new ArrayList<>(allowedNames));
this.excludedNames =
Expand All @@ -45,7 +36,6 @@ private ExporterFilterProperties(
excludedPrefixes == null
? null
: Collections.unmodifiableList(new ArrayList<>(excludedPrefixes));
validate(prefix);
}

public List<String> getAllowedMetricNames() {
Expand All @@ -64,8 +54,6 @@ public List<String> getExcludedMetricNamePrefixes() {
return excludedPrefixes;
}

private void validate(String prefix) throws PrometheusPropertiesException {}

/**
* Note that this will remove entries from {@code properties}. This is because we want to know if
* there are unused properties remaining after all properties have been loaded.
Expand All @@ -81,7 +69,7 @@ static ExporterFilterProperties load(String prefix, Map<Object, Object> properti
List<String> excludedPrefixes =
Util.loadStringList(prefix + "." + METRIC_NAME_MUST_NOT_START_WITH, properties);
return new ExporterFilterProperties(
allowedNames, excludedNames, allowedPrefixes, excludedPrefixes, prefix);
allowedNames, excludedNames, allowedPrefixes, excludedPrefixes);
}

public static Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private static Properties loadPropertiesFromClasspath() {
.getResourceAsStream("prometheus.properties")) {
properties.load(stream);
} catch (Exception ignored) {
// No properties file found on the classpath.
}
return properties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static Map<String, String> loadMap(String name, Map<Object, Object> properties)
if (keyValue.length == 2) {
String key = keyValue[0].trim();
String value = keyValue[1].trim();
if (key.length() > 0 && value.length() > 0) {
if (!key.isEmpty() && !value.isEmpty()) {
result.putIfAbsent(key, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface DistributionDataPoint extends DataPoint, TimerApi {
/** Observe {@code value}, and create a custom exemplar with the given labels. */
void observeWithExemplar(double value, Labels labels);

/** {@inheritDoc} */
@Override
default Timer startTimer() {
return new Timer(this::observe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ default void decWithExemplar(double amount, Labels labels) {
/** Set the gauge to {@code value}, and create a custom exemplar with the given labels. */
void setWithExemplar(double value, Labels labels);

/** {@inheritDoc} */
@Override
default Timer startTimer() {
return new Timer(this::set);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void observe(double value) {
return; // This is the hot path in a high-throughput application and should be as efficient as
// possible.
}
rateLimitedObserve(acceptingNewExemplars, value, exemplars, () -> doObserve(value));
rateLimitedObserve(acceptingNewExemplars, value, () -> doObserve(value));
}

public void observeWithExemplar(double value, Labels labels) {
Expand All @@ -107,10 +107,7 @@ public void observeWithExemplar(double value, Labels labels) {
// possible.
}
rateLimitedObserve(
acceptingNewCustomExemplars,
value,
customExemplars,
() -> doObserveWithExemplar(value, labels));
acceptingNewCustomExemplars, value, () -> doObserveWithExemplar(value, labels));
}

private long doObserve(double value) {
Expand Down Expand Up @@ -278,8 +275,8 @@ private long doObserveWithExemplarWithoutUpperBounds(double amount, Labels label
* <p>To avoid performance issues, we rate limit observing exemplars to {@link
* ExemplarSamplerConfig#getSampleIntervalMillis()} milliseconds.
*/
private void rateLimitedObserve(
AtomicBoolean accepting, double value, Exemplar[] exemplars, LongSupplier observeFunc) {
@SuppressWarnings("FutureReturnValueIgnored")
private void rateLimitedObserve(AtomicBoolean accepting, double value, LongSupplier observeFunc) {
if (Double.isNaN(value)) {
return;
}
Expand Down Expand Up @@ -352,6 +349,7 @@ private Labels doSampleExemplar() {
}
}
} catch (NoClassDefFoundError ignored) {
// ignore
}
return Labels.EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void reset() {
reset = true;
}

@SuppressWarnings("ThreadPriorityCheck")
<T extends DataPointSnapshot> T run(
Function<Long, Boolean> complete, Supplier<T> runnable, Consumer<Double> observeFunction) {
double[] buffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class CKMSQuantiles {
int n = 0;

/** List of sampled observations, ordered by Sample.value. */
@SuppressWarnings("JdkObsolete")
final LinkedList<Sample> samples = new LinkedList<>();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,36 @@ private Counter(Builder builder, PrometheusProperties prometheusProperties) {
}
}

/** {@inheritDoc} */
@Override
public void inc(long amount) {
getNoLabels().inc(amount);
}

/** {@inheritDoc} */
@Override
public void inc(double amount) {
getNoLabels().inc(amount);
}

/** {@inheritDoc} */
@Override
public void incWithExemplar(long amount, Labels labels) {
getNoLabels().incWithExemplar(amount, labels);
}

/** {@inheritDoc} */
@Override
public void incWithExemplar(double amount, Labels labels) {
getNoLabels().incWithExemplar(amount, labels);
}

/** {@inheritDoc} */
@Override
public double get() {
return getNoLabels().get();
}

/** {@inheritDoc} */
@Override
public long getLongValue() {
return getNoLabels().getLongValue();
}

/** {@inheritDoc} */
@Override
public CounterSnapshot collect() {
return (CounterSnapshot) super.collect();
Expand Down Expand Up @@ -131,26 +126,24 @@ private DataPoint(ExemplarSampler exemplarSampler) {
this.exemplarSampler = exemplarSampler;
}

/** {@inheritDoc} */
@Override
public double get() {
return longValue.sum() + doubleValue.sum();
}

/** {@inheritDoc} */
@Override
public long getLongValue() {
return longValue.sum() + (long) doubleValue.sum();
}

/** {@inheritDoc} */
@Override
public void inc(long amount) {
validateAndAdd(amount);
if (isExemplarsEnabled()) {
exemplarSampler.observe(amount);
exemplarSampler.observe((double) amount);
}
}

/** {@inheritDoc} */
@Override
public void inc(double amount) {
validateAndAdd(amount);
Expand All @@ -159,16 +152,14 @@ public void inc(double amount) {
}
}

/** {@inheritDoc} */
@Override
public void incWithExemplar(long amount, Labels labels) {
validateAndAdd(amount);
if (isExemplarsEnabled()) {
exemplarSampler.observeWithExemplar(amount, labels);
exemplarSampler.observeWithExemplar((double) amount, labels);
}
}

/** {@inheritDoc} */
@Override
public void incWithExemplar(double amount, Labels labels) {
validateAndAdd(amount);
Expand Down
Loading

0 comments on commit 8226348

Please sign in to comment.