Skip to content

Commit f1cc00a

Browse files
committed
Refactor Builders to use Spring/Lombok conventions
Signed-off-by: Fabian Stäber <[email protected]>
1 parent a09edde commit f1cc00a

File tree

116 files changed

+2271
-2222
lines changed

Some content is hidden

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

116 files changed

+2271
-2222
lines changed

examples/example-exemplars-tail-sampling/example-greeting-service/src/main/java/io/prometheus/metrics/examples/otel_exemplars/greeting/GreetingServlet.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public class GreetingServlet extends HttpServlet {
2121
private final Histogram histogram;
2222

2323
public GreetingServlet() {
24-
histogram = Histogram.newBuilder()
25-
.withName("request_duration_seconds")
26-
.withHelp("request duration in seconds")
27-
.withUnit(Unit.SECONDS)
28-
.withLabelNames("http_status")
24+
histogram = Histogram.builder()
25+
.name("request_duration_seconds")
26+
.help("request duration in seconds")
27+
.unit(Unit.SECONDS)
28+
.labelNames("http_status")
2929
.register();
3030
histogram.initLabelValues("200");
3131
}
@@ -41,7 +41,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO
4141
} catch (InterruptedException e) {
4242
throw new RuntimeException(e);
4343
} finally {
44-
histogram.withLabelValues("200").observe(nanosToSeconds(System.nanoTime() - start));
44+
histogram.labelValues("200").observe(nanosToSeconds(System.nanoTime() - start));
4545
}
4646
}
4747
}

examples/example-exemplars-tail-sampling/example-greeting-service/src/main/java/io/prometheus/metrics/examples/otel_exemplars/greeting/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Main {
1515

1616
public static void main(String[] args) throws LifecycleException {
1717

18-
JvmMetrics.newBuilder().register();
18+
JvmMetrics.builder().register();
1919

2020
Tomcat tomcat = new Tomcat();
2121
tomcat.setPort(8081);

examples/example-exemplars-tail-sampling/example-hello-world-app/src/main/java/io/prometheus/metrics/examples/otel_exemplars/app/HelloWorldServlet.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public class HelloWorldServlet extends HttpServlet {
2828
private final Histogram histogram;
2929

3030
public HelloWorldServlet() {
31-
histogram = Histogram.newBuilder()
32-
.withName("request_duration_seconds")
33-
.withHelp("request duration in seconds")
34-
.withUnit(Unit.SECONDS)
35-
.withLabelNames("http_status")
31+
histogram = Histogram.builder()
32+
.name("request_duration_seconds")
33+
.help("request duration in seconds")
34+
.unit(Unit.SECONDS)
35+
.labelNames("http_status")
3636
.register();
3737
histogram.initLabelValues("200");
3838
}
@@ -49,7 +49,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
4949
} catch (Exception e) {
5050
throw new ServletException(e);
5151
} finally {
52-
histogram.withLabelValues("200").observe(nanosToSeconds(System.nanoTime() - start));
52+
histogram.labelValues("200").observe(nanosToSeconds(System.nanoTime() - start));
5353
}
5454
}
5555

examples/example-exemplars-tail-sampling/example-hello-world-app/src/main/java/io/prometheus/metrics/examples/otel_exemplars/app/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Main {
1515

1616
public static void main(String[] args) throws LifecycleException {
1717

18-
JvmMetrics.newBuilder().register();
18+
JvmMetrics.builder().register();
1919

2020
Tomcat tomcat = new Tomcat();
2121
tomcat.setPort(8080);

examples/example-exporter-httpserver/src/main/java/io/prometheus/metrics/examples/httpserver/Main.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ public class Main {
1414

1515
public static void main(String[] args) throws IOException, InterruptedException {
1616

17-
JvmMetrics.newBuilder().register();
17+
JvmMetrics.builder().register();
1818

1919
// Note: uptime_seconds_total is not a great example:
2020
// The built-in JvmMetrics have an out-of-the-box metric named process_start_time_seconds
2121
// with the start timestamp in seconds, so if you want to know the uptime you can simply
2222
// run the Prometheus query
2323
// time() - process_start_time_seconds
2424
// rather than creating a custom uptime metric.
25-
Counter counter = Counter.newBuilder()
26-
.withName("uptime_seconds_total")
27-
.withHelp("total number of seconds since this application was started")
28-
.withUnit(Unit.SECONDS)
25+
Counter counter = Counter.builder()
26+
.name("uptime_seconds_total")
27+
.help("total number of seconds since this application was started")
28+
.unit(Unit.SECONDS)
2929
.register();
3030

31-
HTTPServer server = HTTPServer.newBuilder()
32-
.withPort(9400)
31+
HTTPServer server = HTTPServer.builder()
32+
.port(9400)
3333
.buildAndStart();
3434

3535
System.out.println("HTTPServer listening on port http://localhost:" + server.getPort() + "/metrics");

examples/example-exporter-opentelemetry/src/main/java/io/prometheus/metrics/examples/opentelemetry/Main.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ public static void main(String[] args) throws Exception {
1515
// Note: Some JVM metrics are also defined as OpenTelemetry's semantic conventions.
1616
// We have plans to implement a configuration option for JvmMetrics to use OpenTelemetry
1717
// naming conventions rather than the Prometheus names.
18-
JvmMetrics.newBuilder().register();
18+
JvmMetrics.builder().register();
1919

2020
// Note: uptime_seconds_total is not a great example:
2121
// The built-in JvmMetrics have an out-of-the-box metric named process_start_time_seconds
2222
// with the start timestamp in seconds, so if you want to know the uptime you can simply
2323
// run the Prometheus query
2424
// time() - process_start_time_seconds
2525
// rather than creating a custom uptime metric.
26-
Counter counter = Counter.newBuilder()
27-
.withName("uptime_seconds_total")
28-
.withHelp("total number of seconds since this application was started")
29-
.withUnit(Unit.SECONDS)
26+
Counter counter = Counter.builder()
27+
.name("uptime_seconds_total")
28+
.help("total number of seconds since this application was started")
29+
.unit(Unit.SECONDS)
3030
.register();
3131

32-
OpenTelemetryExporter.newBuilder()
33-
.withIntervalSeconds(5)
32+
OpenTelemetryExporter.builder()
33+
.intervalSeconds(5)
3434
.buildAndStart();
3535

3636
while (true) {

examples/example-exporter-opentelemetry/src/main/java/io/prometheus/metrics/examples/opentelemetry/ManualCompleteMetricsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public static void main(String[] args) throws Exception {
4242
.withLabelNames("location")
4343
.register();
4444
45-
gauge.withLabelValues("inside").set(23.4);
46-
gauge.withLabelValues("outside").set(9.3);
45+
gauge.labelValues("inside").set(23.4);
46+
gauge.labelValues("outside").set(9.3);
4747
4848
// By default, the histogram will be exported as an exponential histogram in OpenTelemetry.
4949
Histogram histogram = Histogram.newBuilder()
@@ -55,7 +55,7 @@ public static void main(String[] args) throws Exception {
5555
5656
Random random = new Random(0);
5757
for (int i = 0; i < 1000; i++) {
58-
histogram.withLabelValues("200").observe(random.nextGaussian());
58+
histogram.labelValues("200").observe(random.nextGaussian());
5959
}
6060
6161
// Explicitly use a classic-only histogram to have an example of a classic histogram in OpenTelemetry
@@ -69,7 +69,7 @@ public static void main(String[] args) throws Exception {
6969
.register();
7070
7171
for (int i = 0; i < 15; i++) {
72-
classicHistogram.withLabelValues("200").observe(random.nextInt(3000));
72+
classicHistogram.labelValues("200").observe(random.nextInt(3000));
7373
}
7474
7575
Summary summary = Summary.newBuilder()
@@ -116,8 +116,8 @@ public static void main(String[] args) throws Exception {
116116
.withStates("feature1", "feature2")
117117
.register();
118118
119-
stateSet.withLabelValues("dev").setFalse("feature1");
120-
stateSet.withLabelValues("dev").setTrue("feature2");
119+
stateSet.labelValues("dev").setFalse("feature1");
120+
stateSet.labelValues("dev").setTrue("feature2");
121121
122122
PrometheusRegistry.defaultRegistry.register(() -> UnknownSnapshot.newBuilder()
123123
.withName("my_unknown_metric")

examples/example-exporter-servlet-tomcat/src/main/java/io/prometheus/metrics/examples/tomcat_servlet/HelloWorldServlet.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ public class HelloWorldServlet extends HttpServlet {
2121

2222
// Note: The requests_total counter is not a great example, because the
2323
// request_duration_seconds histogram below also has a count with the number of requests.
24-
private final Counter counter = Counter.newBuilder()
25-
.withName("requests_total")
26-
.withHelp("total number of requests")
27-
.withLabelNames("http_status")
24+
private final Counter counter = Counter.builder()
25+
.name("requests_total")
26+
.help("total number of requests")
27+
.labelNames("http_status")
2828
.register();
2929

30-
private final Histogram histogram = Histogram.newBuilder()
31-
.withName("request_duration_seconds")
32-
.withHelp("request duration in seconds")
33-
.withUnit(Unit.SECONDS)
34-
.withLabelNames("http_status")
30+
private final Histogram histogram = Histogram.builder()
31+
.name("request_duration_seconds")
32+
.help("request duration in seconds")
33+
.unit(Unit.SECONDS)
34+
.labelNames("http_status")
3535
.register();
3636

3737
public HelloWorldServlet() {
@@ -50,8 +50,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO
5050
} catch (InterruptedException e) {
5151
throw new RuntimeException(e);
5252
} finally {
53-
counter.withLabelValues("200").inc();
54-
histogram.withLabelValues("200").observe(nanosToSeconds(System.nanoTime() - start));
53+
counter.labelValues("200").inc();
54+
histogram.labelValues("200").observe(nanosToSeconds(System.nanoTime() - start));
5555
}
5656
}
5757
}

examples/example-exporter-servlet-tomcat/src/main/java/io/prometheus/metrics/examples/tomcat_servlet/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Main {
1818

1919
public static void main(String[] args) throws LifecycleException, IOException {
2020

21-
JvmMetrics.newBuilder().register();
21+
JvmMetrics.builder().register();
2222

2323
Tomcat tomcat = new Tomcat();
2424
Path tmpDir = Files.createTempDirectory("prometheus-tomcat-servlet-example-");

examples/example-simpleclient-bridge/src/main/java/io/prometheus/metrics/examples/simpleclient/Main.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void main(String[] args) throws IOException, InterruptedException
1616
// The following call will register all metrics from the old CollectorRegistry.defaultRegistry
1717
// with the new PrometheusRegistry.defaultRegistry.
1818

19-
SimpleclientCollector.newBuilder().register();
19+
SimpleclientCollector.builder().register();
2020

2121
// Register a counter with the old CollectorRegistry.
2222
// It doesn't matter whether the counter is registered before or after bridging with PrometheusRegistry.
@@ -30,8 +30,8 @@ public static void main(String[] args) throws IOException, InterruptedException
3030

3131
// Expose metrics from the new PrometheusRegistry. This should contain the events_total metric.
3232

33-
HTTPServer server = HTTPServer.newBuilder()
34-
.withPort(9400)
33+
HTTPServer server = HTTPServer.builder()
34+
.port(9400)
3535
.buildAndStart();
3636

3737
System.out.println("HTTPServer listening on port http://localhost:" + server.getPort() + "/metrics");

0 commit comments

Comments
 (0)