Skip to content

Commit b94dfb3

Browse files
committed
add checkstyle
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 615c459 commit b94dfb3

File tree

9 files changed

+439
-49
lines changed

9 files changed

+439
-49
lines changed

checkstyle.xml

Lines changed: 380 additions & 4 deletions
Large diffs are not rendered by default.

prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/datapoints/StateSetDataPoint.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ public interface StateSetDataPoint extends DataPoint {
1414
*/
1515
void setTrue(String state);
1616

17-
/**
18-
* {@code state} must be one of the states from when the {@code StateSet} was created with {@link
19-
* io.prometheus.metrics.core.metrics.StateSet.Builder#states(String...)}.
20-
*/
21-
void setFalse(String state);
22-
2317
/**
2418
* {@code state} must be one of the states from when the {@code StateSet} was created with {@link
2519
* io.prometheus.metrics.core.metrics.StateSet.Builder#states(Class)}.
@@ -28,6 +22,12 @@ default void setTrue(Enum<?> state) {
2822
setTrue(state.toString());
2923
}
3024

25+
/**
26+
* {@code state} must be one of the states from when the {@code StateSet} was created with {@link
27+
* io.prometheus.metrics.core.metrics.StateSet.Builder#states(String...)}.
28+
*/
29+
void setFalse(String state);
30+
3131
/**
3232
* {@code state} must be one of the states from when the {@code StateSet} was created with {@link
3333
* io.prometheus.metrics.core.metrics.StateSet.Builder#states(Class)}.

prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/CKMSQuantiles.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.LinkedList;
2727
import java.util.ListIterator;
2828

29-
//CHECKSTYLE:OFF: checkstyle
29+
// CHECKSTYLE:OFF: checkstyle
3030

3131
/**
3232
* Algorithm solving the "Targeted Quantile Problem" as described in "Effective Computation of
@@ -276,4 +276,4 @@ public String toString() {
276276
}
277277
}
278278

279-
//CHECKSTYLE:ON: checkstyle
279+
// CHECKSTYLE:ON: checkstyle

prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Histogram.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class Histogram extends StatefulMetric<DistributionDataPoint, Histogram.D
6363
implements DistributionDataPoint {
6464

6565
// nativeSchema == CLASSIC_HISTOGRAM indicates that this is a classic histogram only.
66-
private final int CLASSIC_HISTOGRAM = Integer.MIN_VALUE;
66+
private static final int CLASSIC_HISTOGRAM = Integer.MIN_VALUE;
6767

6868
// NATIVE_BOUNDS is used to look up the native bucket index depending on the current schema.
6969
private static final double[][] NATIVE_BOUNDS;
@@ -152,7 +152,7 @@ private Histogram(Histogram.Builder builder, PrometheusProperties prometheusProp
152152
double min =
153153
getConfigProperty(properties, MetricsProperties::getHistogramNativeMinZeroThreshold);
154154
nativeMaxZeroThreshold =
155-
max == builder.DEFAULT_NATIVE_MAX_ZERO_THRESHOLD && min > max ? min : max;
155+
max == Builder.DEFAULT_NATIVE_MAX_ZERO_THRESHOLD && min > max ? min : max;
156156
nativeMinZeroThreshold = Math.min(min, nativeMaxZeroThreshold);
157157
nativeMaxBuckets =
158158
getConfigProperty(properties, MetricsProperties::getHistogramNativeMaxNumberOfBuckets);
@@ -447,9 +447,9 @@ private void maybeScaleDown(AtomicBoolean wasReset) {
447447
// Now we are in the synchronized block while new observations go into the buffer.
448448
// Check again if we need to limit the bucket size, because another thread might
449449
// have limited it in the meantime.
450-
int nBuckets =
450+
int numBuckets =
451451
nativeBucketsForPositiveValues.size() + nativeBucketsForNegativeValues.size();
452-
if (nBuckets <= nativeMaxBuckets || nativeSchema == -4) {
452+
if (numBuckets <= nativeMaxBuckets || nativeSchema == -4) {
453453
return null;
454454
}
455455
if (maybeReset()) {
@@ -668,11 +668,11 @@ public static class Builder extends StatefulMetric.Builder<Histogram.Builder, Hi
668668
public static final double[] DEFAULT_CLASSIC_UPPER_BOUNDS =
669669
new double[] {.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10};
670670

671-
private final double DEFAULT_NATIVE_MIN_ZERO_THRESHOLD = Math.pow(2.0, -128);
672-
private final double DEFAULT_NATIVE_MAX_ZERO_THRESHOLD = Math.pow(2.0, -128);
673-
private final int DEFAULT_NATIVE_INITIAL_SCHEMA = 5;
674-
private final int DEFAULT_NATIVE_MAX_NUMBER_OF_BUCKETS = 160;
675-
private final long DEFAULT_NATIVE_RESET_DURATION_SECONDS = 0; // 0 means no reset
671+
private static final double DEFAULT_NATIVE_MIN_ZERO_THRESHOLD = Math.pow(2.0, -128);
672+
private static final double DEFAULT_NATIVE_MAX_ZERO_THRESHOLD = Math.pow(2.0, -128);
673+
private static final int DEFAULT_NATIVE_INITIAL_SCHEMA = 5;
674+
private static final int DEFAULT_NATIVE_MAX_NUMBER_OF_BUCKETS = 160;
675+
private static final long DEFAULT_NATIVE_RESET_DURATION_SECONDS = 0; // 0 means no reset
676676

677677
private Boolean nativeOnly;
678678
private Boolean classicOnly;

prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/StateSet.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,6 @@ public StateSetSnapshot collect() {
7676
return (StateSetSnapshot) super.collect();
7777
}
7878

79-
@Override
80-
public void setTrue(String state) {
81-
getNoLabels().setTrue(state);
82-
}
83-
84-
@Override
85-
public void setFalse(String state) {
86-
getNoLabels().setFalse(state);
87-
}
88-
8979
@Override
9080
protected StateSetSnapshot collect(List<Labels> labels, List<DataPoint> metricDataList) {
9181
List<StateSetSnapshot.StateSetDataPointSnapshot> data = new ArrayList<>(labels.size());
@@ -97,6 +87,16 @@ protected StateSetSnapshot collect(List<Labels> labels, List<DataPoint> metricDa
9787
return new StateSetSnapshot(getMetadata(), data);
9888
}
9989

90+
@Override
91+
public void setTrue(String state) {
92+
getNoLabels().setTrue(state);
93+
}
94+
95+
@Override
96+
public void setFalse(String state) {
97+
getNoLabels().setFalse(state);
98+
}
99+
100100
@Override
101101
protected DataPoint newDataPoint() {
102102
return new DataPoint();

prometheus-metrics-exporter-common/src/main/java/io/prometheus/metrics/exporter/common/PrometheusScrapeHandler.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public PrometheusScrapeHandler(PrometheusProperties config, PrometheusRegistry r
4646
public void handleRequest(PrometheusHttpExchange exchange) throws IOException {
4747
try {
4848
PrometheusHttpRequest request = exchange.getRequest();
49-
PrometheusHttpResponse response = exchange.getResponse();
5049
MetricSnapshots snapshots = scrape(request);
5150
if (writeDebugResponse(snapshots, exchange)) {
5251
return;
@@ -57,6 +56,7 @@ public void handleRequest(PrometheusHttpExchange exchange) throws IOException {
5756
ExpositionFormatWriter writer = expositionFormats.findWriter(acceptHeader);
5857
writer.write(responseBuffer, snapshots);
5958
lastResponseSize.set(responseBuffer.size());
59+
PrometheusHttpResponse response = exchange.getResponse();
6060
response.setHeader("Content-Type", writer.getContentType());
6161

6262
if (shouldUseCompression(request)) {
@@ -106,16 +106,6 @@ private Predicate<String> makeNameFilter(ExporterFilterProperties props) {
106106
}
107107
}
108108

109-
private MetricSnapshots scrape(PrometheusHttpRequest request) {
110-
111-
Predicate<String> filter = makeNameFilter(request.getParameterValues("name[]"));
112-
if (filter != null) {
113-
return registry.scrape(filter, request);
114-
} else {
115-
return registry.scrape(request);
116-
}
117-
}
118-
119109
private Predicate<String> makeNameFilter(String[] includedNames) {
120110
Predicate<String> result = null;
121111
if (includedNames != null && includedNames.length > 0) {
@@ -129,6 +119,16 @@ private Predicate<String> makeNameFilter(String[] includedNames) {
129119
return result;
130120
}
131121

122+
private MetricSnapshots scrape(PrometheusHttpRequest request) {
123+
124+
Predicate<String> filter = makeNameFilter(request.getParameterValues("name[]"));
125+
if (filter != null) {
126+
return registry.scrape(filter, request);
127+
} else {
128+
return registry.scrape(request);
129+
}
130+
}
131+
132132
private boolean writeDebugResponse(MetricSnapshots snapshots, PrometheusHttpExchange exchange)
133133
throws IOException {
134134
String debugParam = exchange.getRequest().getParameter("debug");

prometheus-metrics-exporter-opentelemetry/src/main/java/io/prometheus/metrics/exporter/opentelemetry/PrometheusMetricProducer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Collection<MetricData> collectAllMetrics() {
4444
// registry.scrape(filter) if a filter is configured, like in the Servlet exporter.
4545
MetricSnapshots snapshots = registry.scrape();
4646
Resource resourceWithTargetInfo = resource.merge(resourceFromTargetInfo(snapshots));
47-
InstrumentationScopeInfo scopeFromInfo = instrumentationScopeFromOTelScopeInfo(snapshots);
47+
InstrumentationScopeInfo scopeFromInfo = instrumentationScopeFromOtelScopeInfo(snapshots);
4848
List<MetricData> result = new ArrayList<>(snapshots.size());
4949
MetricDataFactory factory =
5050
new MetricDataFactory(
@@ -93,7 +93,7 @@ private Resource resourceFromTargetInfo(MetricSnapshots snapshots) {
9393
return result.build();
9494
}
9595

96-
private InstrumentationScopeInfo instrumentationScopeFromOTelScopeInfo(
96+
private InstrumentationScopeInfo instrumentationScopeFromOtelScopeInfo(
9797
MetricSnapshots snapshots) {
9898
for (MetricSnapshot snapshot : snapshots) {
9999
if (snapshot.getMetadata().getPrometheusName().equals("otel_scope")

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@
1010
import io.prometheus.metrics.model.registry.Collector;
1111
import io.prometheus.metrics.model.registry.MultiCollector;
1212
import io.prometheus.metrics.model.registry.PrometheusRegistry;
13-
import java.io.*;
14-
import java.net.*;
13+
import java.io.ByteArrayOutputStream;
14+
import java.io.IOException;
15+
import java.io.InputStream;
16+
import java.io.OutputStream;
17+
import java.io.UnsupportedEncodingException;
18+
import java.net.HttpURLConnection;
19+
import java.net.InetAddress;
20+
import java.net.MalformedURLException;
21+
import java.net.URI;
22+
import java.net.URL;
23+
import java.net.URLEncoder;
24+
import java.net.UnknownHostException;
1525
import java.nio.charset.StandardCharsets;
16-
import java.util.*;
26+
import java.util.Base64;
27+
import java.util.Collections;
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
import java.util.TreeMap;
1731

1832
/**
1933
* Export metrics via the <a href="https://github.com/prometheus/pushgateway">Prometheus

prometheus-metrics-exposition-formats/src/main/generated/io/prometheus/metrics/expositionformats/generated/com_google_protobuf_4_28_3/Metrics.java

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)