Skip to content

Commit c07e430

Browse files
committed
format
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 7490dc3 commit c07e430

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

+7376
-31536
lines changed

.editorconfig

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
root = true
22

3-
[*]
4-
max_line_length = 100
5-
indent_size = 2
3+
[version-rules.xml]
4+
max_line_length = 200
5+
6+
[*.java]
7+
# checked by google-java-format
8+
max_line_length = 200
69

710
[pom.xml]
811
indent_size = 4
12+
13+
[docs/themes/**.*]
14+
max_line_length = 400
15+
16+
[*]
17+
max_line_length = 150
18+
indent_size = 2

.github/super-linter.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ IGNORE_GITIGNORED_FILES=true
33
JAVA_FILE_NAME=google_checks.xml
44
# disable kubernetes linter - complains about resource limits, etc
55
VALIDATE_CHECKOV=false
6+
VALIDATE_CSS=false
7+
VALIDATE_CSS_PRETTIER=false
68
VALIDATE_DOCKERFILE_HADOLINT=false
79
VALIDATE_GIT_COMMITLINT=false
810
# done by maven
911
VALIDATE_GOOGLE_JAVA_FORMAT=false
1012
# times out
1113
VALIDATE_GO_MODULES=false
14+
VALIDATE_HTML=false
1215
# done by checkstyle
1316
VALIDATE_JAVA=false
1417
# contradicting with prettier
1518
VALIDATE_JAVASCRIPT_STANDARD=false
1619
# we have many duplicate code in our codebase for demo purposes
1720
VALIDATE_JSCPD=false
18-
VALIDATE_PYTHON_PYINK=false
21+
VALIDATE_PYTHON_PYLINT=false
1922

2023
# FILTER_REGEX_EXCLUDE=src/main/generated/.*|docs/themes/.*
2124

CONTRIBUTING.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ Prometheus uses GitHub to manage reviews of pull requests.
1313

1414
## Formatting
1515

16-
This repository uses [Google Java Format](https://github.com/google/google-java-format) to format the code.
16+
This repository uses [Google Java Format](https://github.com/google/google-java-format) to format
17+
the code.
1718

1819
Run `./mvnw spotless:apply` to format the code (only changed files) before committing.
1920

2021
## Running Tests
2122

2223
If you're getting errors when running tests:
2324

24-
- Make sure that the IDE uses only the "Maven Shade" dependency of "prometheus-metrics-exposition-formats" and the "prometheus-metrics-tracer\*" dependencies.
25+
- Make sure that the IDE uses only the "Maven Shade" dependency of "
26+
prometheus-metrics-exposition-formats" and the "prometheus-metrics-tracer\*" dependencies.
2527

2628
### Avoid failures while running tests
2729

@@ -30,7 +32,8 @@ If you're getting errors when running tests:
3032
- Use `-Dcheckstyle.skip=true` to skip the checkstyle check during development.
3133
- Use `-Dwarnings=-nowarn` to skip the warnings during development.
3234

33-
Combine all with `./mvnw test -DskipTests=true -Dspotless.check.skip=true -Dcoverage.skip=true -Dcheckstyle.skip=true -Dwarnings=-nowarn`.
35+
Combine all with
36+
`./mvnw test -DskipTests=true -Dspotless.check.skip=true -Dcoverage.skip=true -Dcheckstyle.skip=true -Dwarnings=-nowarn`.
3437

3538
## Updating the Protobuf Java Classes
3639

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88

99
# Contributing and community
1010

11-
See [CONTRIBUTING.md](CONTRIBUTING.md) and the [community section](http://prometheus.io/community/) of the Prometheus homepage.
11+
See [CONTRIBUTING.md](CONTRIBUTING.md) and the [community section](http://prometheus.io/community/)
12+
of the Prometheus homepage.
1213

13-
The Prometheus Java community is present on the [CNCF Slack](https://cloud-native.slack.com) on `#prometheus-java`, and we have a fortnightly community call in the [Prometheus public calendar](https://prometheus.io/community/).
14+
The Prometheus Java community is present on the [CNCF Slack](https://cloud-native.slack.com) on
15+
`#prometheus-java`, and we have a fortnightly community call in
16+
the [Prometheus public calendar](https://prometheus.io/community/).
1417

1518
# Previous Releases
1619

17-
The source code for 0.16.0 and older is on the [simpleclient](https://github.com/prometheus/client_java/tree/simpleclient) branch.
20+
The source code for 0.16.0 and older is on
21+
the [simpleclient](https://github.com/prometheus/client_java/tree/simpleclient) branch.
1822

1923
# License
2024

RELEASING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
1. Go to <https://github.com/prometheus/client_java/releases/new>
44
2. Click on "Choose a tag", enter the tag name (e.g. `v0.1.0`), and click "Create a new tag".
5-
3. Click on "Generate release notes" to auto-generate the release notes based on the commits since the last release.
5+
3. Click on "Generate release notes" to auto-generate the release notes based on the commits since
6+
the last release.
67
4. Click on "Publish release".

docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Here's how the initial `docs/` folder was set up:
5151
hugo new site docs
5252
cd docs/
5353
mkdir -p themes/hugo-geekdoc/
54-
curl -L https://github.com/thegeeklab/hugo-geekdoc/releases/download/v0.41.1/hugo-geekdoc.tar.gz | tar -xz -C themes/hugo-geekdoc/ --strip-components=1
54+
curl -L https://github.com/thegeeklab/hugo-geekdoc/releases/download/v0.41.1/hugo-geekdoc.tar.gz \
55+
| tar -xz -C themes/hugo-geekdoc/ --strip-components=1
5556
```
5657

5758
Create the initial `hugo.toml` file as described

docs/content/exporters/httpserver.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,34 @@ weight: 3
44
---
55

66
The `HTTPServer` is a standalone server for exposing a metric endpoint. A minimal example
7-
application for `HTTPServer` can be found in the [examples](https://github.com/prometheus/client_java/tree/1.0.x/examples) directory.
7+
application for `HTTPServer` can be found in
8+
the [examples](https://github.com/prometheus/client_java/tree/1.0.x/examples) directory.
89

910
```java
1011
HTTPServer server = HTTPServer.builder()
11-
.port(9400)
12-
.buildAndStart();
12+
.port(9400)
13+
.buildAndStart();
1314
```
1415

1516
By default, `HTTPServer` binds to any IP address, you can change this with
16-
[hostname()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#hostname(java.lang.String)>) or [inetAddress()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#inetAddress(java.net.InetAddress)>).
17+
[hostname()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#hostname(java.lang.String)>)
18+
or [inetAddress()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#inetAddress(java.net.InetAddress)>).
1719

1820
`HTTPServer` is configured with three endpoints:
1921

2022
- `/metrics` for Prometheus scraping.
2123
- `/-/healthy` for simple health checks.
2224
- `/` the default handler is a static HTML page.
2325

24-
The default handler can be changed with [defaultHandler()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#defaultHandler(com.sun.net.httpserver.HttpHandler)>).
26+
The default handler can be changed
27+
with [defaultHandler()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#defaultHandler(com.sun.net.httpserver.HttpHandler)>).
2528

2629
## Authentication and HTTPS
2730

28-
- [authenticator()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#authenticator(com.sun.net.httpserver.Authenticator)>) is for configuring authentication.
29-
- [httpsConfigurator()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#httpsConfigurator(com.sun.net.httpserver.HttpsConfigurator)>) is for configuring HTTPS.
31+
- [authenticator()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#authenticator(com.sun.net.httpserver.Authenticator)>)
32+
is for configuring authentication.
33+
- [httpsConfigurator()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#httpsConfigurator(com.sun.net.httpserver.HttpsConfigurator)>)
34+
is for configuring HTTPS.
3035

3136
You can find an example of authentication and SSL in the [jmx_exporter](https://github.com/prometheus/jmx_exporter).
3237

docs/content/exporters/spring.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ weight: 5
55

66
## Alternative: Use Spring's Built-in Metrics Library
77

8-
[Spring Boot](https://spring.io/projects/spring-boot) has a built-in metric library named [Micrometer](https://micrometer.io/), which supports Prometheus
8+
[Spring Boot](https://spring.io/projects/spring-boot) has a built-in metric library named
9+
[Micrometer](https://micrometer.io/), which supports Prometheus
910
exposition format and can be set up in three simple steps:
1011

1112
1. Add the `org.springframework.boot:spring-boot-starter-actuator` dependency.
@@ -25,7 +26,8 @@ Spring anyway. Maybe you want full support for all Prometheus metric types,
2526
or you want to use the new Prometheus native histograms.
2627

2728
The easiest way to use the Prometheus metrics library in Spring is to configure the
28-
[PrometheusMetricsServlet](/client_java/api/io/prometheus/metrics/exporter/servlet/jakarta/PrometheusMetricsServlet.html) to expose metrics.
29+
[PrometheusMetricsServlet](/client_java/api/io/prometheus/metrics/exporter/servlet/jakarta/PrometheusMetricsServlet.html)
30+
to expose metrics.
2931

3032
Dependencies:
3133

@@ -51,35 +53,37 @@ import org.springframework.web.bind.annotation.RestController;
5153
@RestController
5254
public class DemoApplication {
5355

54-
private static final Counter requestCount = Counter.builder()
55-
.name("requests_total")
56-
.register();
57-
58-
public static void main(String[] args) {
59-
SpringApplication.run(DemoApplication.class, args);
60-
JvmMetrics.builder().register();
61-
}
62-
63-
@GetMapping("/")
64-
public String sayHello() throws InterruptedException {
65-
requestCount.inc();
66-
return "Hello, World!\n";
67-
}
68-
69-
@Bean
70-
public ServletRegistrationBean<PrometheusMetricsServlet> createPrometheusMetricsEndpoint() {
71-
return new ServletRegistrationBean<>(new PrometheusMetricsServlet(), "/metrics/*");
72-
}
56+
private static final Counter requestCount = Counter.builder()
57+
.name("requests_total")
58+
.register();
59+
60+
public static void main(String[] args) {
61+
SpringApplication.run(DemoApplication.class, args);
62+
JvmMetrics.builder().register();
63+
}
64+
65+
@GetMapping("/")
66+
public String sayHello() throws InterruptedException {
67+
requestCount.inc();
68+
return "Hello, World!\n";
69+
}
70+
71+
@Bean
72+
public ServletRegistrationBean<PrometheusMetricsServlet> createPrometheusMetricsEndpoint() {
73+
return new ServletRegistrationBean<>(new PrometheusMetricsServlet(), "/metrics/*");
74+
}
7375
}
7476
```
7577

7678
The important part are the last three lines: They configure the
77-
[PrometheusMetricsServlet](/client_java/api/io/prometheus/metrics/exporter/servlet/jakarta/PrometheusMetricsServlet.html) to expose metrics on `/metrics`:
79+
[PrometheusMetricsServlet](/client_java/api/io/prometheus/metrics/exporter/servlet/jakarta/PrometheusMetricsServlet.html)
80+
to expose metrics on `/metrics`:
7881

7982
```java
83+
8084
@Bean
8185
public ServletRegistrationBean<PrometheusMetricsServlet> createPrometheusMetricsEndpoint() {
82-
return new ServletRegistrationBean<>(new PrometheusMetricsServlet(), "/metrics/*");
86+
return new ServletRegistrationBean<>(new PrometheusMetricsServlet(), "/metrics/*");
8387
}
8488
```
8589

docs/content/migration/simpleclient.md

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@ title: Simpleclient
33
weight: 1
44
---
55

6-
The Prometheus Java client library 1.0.0 is a complete rewrite of the underlying data model, and is not backwards compatible with releases 0.16.0 and older for a variety of reasons:
6+
The Prometheus Java client library 1.0.0 is a complete rewrite of the underlying data model, and is not backwards
7+
compatible with releases 0.16.0 and older for a variety of reasons:
78

8-
- The old data model was based on [OpenMetrics](https://openmetrics.io). Native histograms don't fit with the OpenMetrics model because they don't follow the "every sample has exactly one double value" paradigm. It was a lot cleaner to implement a dedicated `prometheus-metrics-model` than trying to fit native histograms into the existing OpenMetrics-based model.
9-
- Version 0.16.0 and older has multiple Maven modules sharing the same Java package name. This is not supported by the Java module system. To support users of Java modules, we renamed all packages and made sure no package is reused across multiple Maven modules.
9+
- The old data model was based on [OpenMetrics](https://openmetrics.io). Native histograms don't fit with the
10+
OpenMetrics model because they don't follow the "every sample has exactly one double value" paradigm. It was a lot
11+
cleaner to implement a dedicated `prometheus-metrics-model` than trying to fit native histograms into the existing
12+
OpenMetrics-based model.
13+
- Version 0.16.0 and older has multiple Maven modules sharing the same Java package name. This is not supported by the
14+
Java module system. To support users of Java modules, we renamed all packages and made sure no package is reused
15+
across multiple Maven modules.
1016

1117
## Migration using the Simpleclient Bridge
1218

13-
Good news: Users of version 0.16.0 and older do not need to refactor all their instrumentation code to get started with 1.0.0.
19+
Good news: Users of version 0.16.0 and older do not need to refactor all their instrumentation code to get started with
20+
1.0.0.
1421

1522
We provide a migration module for bridging the old simpleclient `CollectorRegistry` to the new `PrometheusRegistry`.
1623

@@ -27,10 +34,11 @@ implementation 'io.prometheus:prometheus-metrics-simpleclient-bridge:1.0.0'
2734
{{< tab "Maven" >}}
2835

2936
```xml
37+
3038
<dependency>
31-
<groupId>io.prometheus</groupId>
32-
<artifactId>prometheus-metrics-simpleclient-bridge</artifactId>
33-
<version>1.0.0</version>
39+
<groupId>io.prometheus</groupId>
40+
<artifactId>prometheus-metrics-simpleclient-bridge</artifactId>
41+
<version>1.0.0</version>
3442
</dependency>
3543
```
3644

@@ -40,20 +48,29 @@ implementation 'io.prometheus:prometheus-metrics-simpleclient-bridge:1.0.0'
4048
Then add the following to your code:
4149

4250
```java
43-
SimpleclientCollector.builder().register();
51+
SimpleclientCollector.builder().
52+
53+
register();
4454
```
4555

46-
This will make all metrics registered with simpleclient's `CollectorRegistry.defaultRegistry` available in the new `PrometheusRegistry.defaultRegistry`.
56+
This will make all metrics registered with simpleclient's `CollectorRegistry.defaultRegistry` available in the new
57+
`PrometheusRegistry.defaultRegistry`.
4758

4859
If you are using custom registries, you can specify them like this:
4960

5061
```java
5162
CollectorRegistry simpleclientRegistry = ...;
5263
PrometheusRegistry prometheusRegistry = ...;
5364

54-
SimpleclientCollector.builder()
55-
.collectorRegistry(simpleclientRegistry)
56-
.register(prometheusRegistry);
65+
SimpleclientCollector.
66+
67+
builder()
68+
.
69+
70+
collectorRegistry(simpleclientRegistry)
71+
.
72+
73+
register(prometheusRegistry);
5774
```
5875

5976
## Refactoring the Instrumentation Code
@@ -67,20 +84,26 @@ Dependencies:
6784
- `simpleclient_httpserver` -> `prometheus-metrics-exporter-httpserver`
6885
- `simpleclient_servlet_jakarta` -> `prometheus-metrics-exporter-servlet-jakarta`
6986

70-
As long as you are using high-level metric API like `Counter`, `Gauge`, `Histogram`, and `Summary` converting code to the new API is relatively straightforward. You will need to adapt the package name and apply some minor changes like using `builder()` instead of `build()` or using `labelValues()` instead of `labels()`.
87+
As long as you are using high-level metric API like `Counter`, `Gauge`, `Histogram`, and `Summary` converting code to
88+
the new API is relatively straightforward. You will need to adapt the package name and apply some minor changes like
89+
using `builder()` instead of `build()` or using `labelValues()` instead of `labels()`.
7190

7291
Example of the old 0.16.0 API:
7392

7493
```java
7594
import io.prometheus.client.Counter;
7695

7796
Counter counter = Counter.build()
78-
.name("test")
79-
.help("test counter")
80-
.labelNames("path")
81-
.register();
97+
.name("test")
98+
.help("test counter")
99+
.labelNames("path")
100+
.register();
82101

83-
counter.labels("/hello-world").inc();
102+
counter.
103+
104+
labels("/hello-world").
105+
106+
inc();
84107
```
85108

86109
Example of the new 1.0.0 API:
@@ -89,17 +112,27 @@ Example of the new 1.0.0 API:
89112
import io.prometheus.metrics.core.metrics.Counter;
90113

91114
Counter counter = Counter.builder()
92-
.name("test")
93-
.help("test counter")
94-
.labelNames("path")
95-
.register();
115+
.name("test")
116+
.help("test counter")
117+
.labelNames("path")
118+
.register();
119+
120+
counter.
96121

97-
counter.labelValues("/hello-world").inc();
122+
labelValues("/hello-world").
123+
124+
inc();
98125
```
99126

100-
Reasons why we changed the API: Changing the package names was a necessity because the previous package names were incompatible with the Java module system. However, renaming packages requires changing code anyway, so we decided to clean up some things. For example, the name `builder()` for a builder method is very common in the Java ecosystem, it's used in Spring, Lombok, and so on. So naming the method `builder()` makes the Prometheus library more aligned with the broader Java ecosystem.
127+
Reasons why we changed the API: Changing the package names was a necessity because the previous package names were
128+
incompatible with the Java module system. However, renaming packages requires changing code anyway, so we decided to
129+
clean up some things. For example, the name `builder()` for a builder method is very common in the Java ecosystem, it's
130+
used in Spring, Lombok, and so on. So naming the method `builder()` makes the Prometheus library more aligned with the
131+
broader Java ecosystem.
101132

102-
If you are using the low level `Collector` API directly, you should have a look at the new callback metric types, see [/getting-started/callbacks/](../../getting-started/callbacks/). Chances are good that the new callback metrics have an easier way to achieve what you need than the old 0.16.0 code.
133+
If you are using the low level `Collector` API directly, you should have a look at the new callback metric types,
134+
see [/getting-started/callbacks/](../../getting-started/callbacks/). Chances are good that the new callback metrics have
135+
an easier way to achieve what you need than the old 0.16.0 code.
103136

104137
## JVM Metrics
105138

@@ -113,7 +146,9 @@ With version 1.0.0 these metrics moved to the `prometheus-metrics-instrumentatio
113146
are initialized as follows:
114147

115148
```java
116-
JvmMetrics.builder().register();
149+
JvmMetrics.builder().
150+
151+
register();
117152
```
118153

119154
A full list of the available JVM metrics can be found

0 commit comments

Comments
 (0)