Skip to content

Commit 0abb9db

Browse files
committed
lint
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 174e487 commit 0abb9db

File tree

22 files changed

+881
-811
lines changed

22 files changed

+881
-811
lines changed

.editorconfig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ root = true
44
max_line_length = 100
55
indent_size = 2
66

7-
[{version-rules.xml,maven-wrapper.properties}]
7+
[{version-rules.xml,maven-wrapper.properties,checkstyle.xml,docker-compose.yaml,docker-compose.yml,Dockerfile,example_target_info.json,mise.toml,mise.lock,mvnm,mvnw.cmd,generate-protobuf.sh,super-linter.env}]
88
max_line_length = 200
99

10-
[*.java]
11-
# checked by google-java-format
12-
max_line_length = 200
10+
[{grafana-dashboard-*.json,.editorconfig}]
11+
max_line_length = 300
1312

1413
[pom.xml]
1514
max_line_length = 110

.github/super-linter.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FILTER_REGEX_EXCLUDE=mvnw|src/main/generated/.*|docs/themes/.*|keystore.pkcs12
1+
FILTER_REGEX_EXCLUDE=mvnw|src/main/generated/.*|docs/themes/.*|keystore.pkcs12|.*.java|prometheus-metrics-exporter-opentelemetry-shaded/pom.xml
22
IGNORE_GITIGNORED_FILES=true
33
JAVA_FILE_NAME=google_checks.xml
44
# disable kubernetes linter - complains about resource limits, etc

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Prometheus Community Code of Conduct
22

3-
Prometheus follows the
3+
Prometheus follows the
44
[CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).

checkstyle.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@
136136
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
137137
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
138138
<message key="ws.notFollowed"
139-
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
139+
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may
140+
only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
140141
<message key="ws.notPreceded"
141142
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
142143
</module>

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ They are generated on the fly by GitHub Actions when the docs are updated.
2121
To view locally, run the following:
2222

2323
```shell
24-
# note that the 'compile' in the following command is necessary for
24+
# note that the 'compile' in the following command is necessary for
2525
# Javadoc to detect the module structure
2626
./mvnw clean compile javadoc:javadoc javadoc:aggregate
2727
rm -r ./docs/static/api

docs/content/getting-started/metric-types.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ most important options:
112112
- `classicBuckets(...)`: Set the classic bucket boundaries. Default buckets are `.005`, `.01`,
113113
`.025`, `.05`, `.1`, `.25`, `.5`, `1`, `2.5`, `5`, `and 10`. The default bucket boundaries are
114114
designed for measuring request durations in seconds.
115-
- `nativeMaxNumberOfBuckets()`: Upper limit for the number of native histogram buckets. Default is 160. When the maximum is reached, the native histogram automatically reduces resolution to stay
116-
below the limit.
115+
- `nativeMaxNumberOfBuckets()`: Upper limit for the number of native histogram buckets.
116+
Default is 160. When the maximum is reached, the native histogram automatically
117+
reduces resolution to stay below the limit.
117118

118119
See Javadoc
119120
for [Histogram.Builder](/client_java/api/io/prometheus/metrics/core/metrics/Histogram.Builder.html)

examples/example-exemplars-tail-sampling/README.md

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
## Background: What are Exemplars?
44

5-
Each Prometheus time series may contain Exemplars. Exemplars are additional metadata attached to a Prometheus time
5+
Each Prometheus time series may contain Exemplars. Exemplars are additional metadata attached to a
6+
Prometheus time
67
series.
78
Exemplars are often used to reference trace IDs when distributed tracing is used.
8-
The following shows an example of a histogram in OpenMetrics text format where each non-empty bucket has an Exemplar:
9+
The following shows an example of a histogram in OpenMetrics text format where each non-empty bucket
10+
has an Exemplar:
11+
12+
<!-- editorconfig-checker-disable -->
913

1014
```text
1115
# TYPE request_duration_seconds histogram
@@ -27,23 +31,27 @@ request_duration_seconds_count{http_status="200"} 11243
2731
request_duration_seconds_sum{http_status="200"} 2843.3178731140015
2832
```
2933

34+
<!-- editorconfig-checker-enable -->
35+
3036
In Grafana Exemplars can be visualized as little green dots. The following shows an example of the
31-
95th [quantile](https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile) for the histogram
32-
above.
37+
95th [quantile](https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile)
38+
for the histogram above.
3339

34-
![Screenshot of a Latency Graph with Exemplars](https://github.com/prometheus/client_java/assets/330535/68aada3d-f55b-4a7b-90be-222481f0ec79)
40+
![Screenshot of a Latency Graph with Exemplars](https://github.com/prometheus/client_java/assets/330535/68aada3d-f55b-4a7b-90be-222481f0ec79) <!-- editorconfig-checker-disable-line -->
3541

3642
If you move the mouse over an Exemplar, an overlay pops up with a link to a tracing tool
3743
like [Tempo](https://github.com/grafana/tempo).
3844

3945
## Automatic Exemplar Generation
4046

41-
The Prometheus Java client library automatically detects OpenTelemetry tracing. The library automatically produces
47+
The Prometheus Java client library automatically detects OpenTelemetry tracing. The library
48+
automatically produces
4249
Exemplars with OpenTelemetry trace IDs if applicable.
4350

4451
## Sampling
4552

46-
Distributed tracing produces a lot of data, and it is quite common to apply a sampling strategy to reduce the number of
53+
Distributed tracing produces a lot of data, and it is quite common to apply a sampling strategy to
54+
reduce the number of
4755
traces.
4856

4957
There are two ways how to do this:
@@ -52,15 +60,21 @@ There are two ways how to do this:
5260
2. _Tail-based sampling_ is performed by an external infrastructure component like
5361
the [OpenTelemetry collector](https://opentelemetry.io/docs/collector/).
5462

55-
When generating Exemplars, the Prometheus Java client libray must make sure that the Exemplar points to a trace that is
56-
actually sampled. Otherwise, Exemplar's trace ID will not be available in the monitoring backend, i.e. the Exemplar will
63+
When generating Exemplars, the Prometheus Java client libray must make sure that the Exemplar points
64+
to a trace that is
65+
actually sampled. Otherwise, Exemplar's trace ID will not be available in the monitoring backend,
66+
i.e. the Exemplar will
5767
link to a non-existing trace ID.
5868

59-
With _head-based sampling_ this works out-of-the-box: The Prometheus client library calls OpenTelemetry's
60-
`Span.current().getSpanContext().isSampled()` function and selects Exemplars only if the current Span is sampled.
69+
With _head-based sampling_ this works out-of-the-box: The Prometheus client library calls
70+
OpenTelemetry's
71+
`Span.current().getSpanContext().isSampled()` function and selects Exemplars only if the current
72+
Span is sampled.
6173

62-
With _tail-based sampling_ there is a trick: The Prometheus client library adds an attribute `exemplar="true"` to each
63-
Span that is used as an Exemplar. The remainder of this readme shows how you can configure the `tail_sampling` processor
74+
With _tail-based sampling_ there is a trick: The Prometheus client library adds an attribute
75+
`exemplar="true"` to each
76+
Span that is used as an Exemplar. The remainder of this readme shows how you can configure the
77+
`tail_sampling` processor
6478
of the OpenTelemetry collector to sample Spans marked with `exemplar="true"`.
6579

6680
## Build the Example
@@ -71,50 +85,61 @@ The example is built as part of the `client_java` parent project with
7185
./mvnw package
7286
```
7387

74-
This should generate two Java services `.../example-greeting-service/target/example-greeting-service.jar` and
88+
This should generate two Java services
89+
`.../example-greeting-service/target/example-greeting-service.jar` and
7590
`.../example-hello-world-app/target/example-hello-world-app.jar`.
7691

7792
## Run the Example
7893

7994
The `docker-compose` file will run the example with the following containers:
8095

81-
- `hello-world-app`: Java service described above, with the OpenTelemetry Java instrumentation agent attached for
96+
- `hello-world-app`: Java service described above, with the OpenTelemetry Java instrumentation agent
97+
attached for
8298
distrubted tracing.
83-
- `greeting-service`: Java service described above, with the OpenTelemetry Java instrumentation agent attached for
99+
- `greeting-service`: Java service described above, with the OpenTelemetry Java instrumentation
100+
agent attached for
84101
distrubted tracing.
85-
- `collector`: OpenTelemetry collector for receiving the distributed traces, performing _tail sampling_, and forwarding
102+
- `collector`: OpenTelemetry collector for receiving the distributed traces, performing _tail
103+
sampling_, and forwarding
86104
them to `tempo`.
87-
- `prometheus`: Prometheus server scraping metrics from `hello-world-app`, `greeting-service`, and `tempo`.
105+
- `prometheus`: Prometheus server scraping metrics from `hello-world-app`, `greeting-service`, and
106+
`tempo`.
88107
- `tempo`: Trace database.
89-
- `grafana`: Has `prometheus` and `tempo` configured as data sources, and is configured with an example dashboard with
108+
- `grafana`: Has `prometheus` and `tempo` configured as data sources, and is configured with an
109+
example dashboard with
90110
Exemplars enabled.
91-
- `k6`: The [k6](https://k6.io/) load test tool for generating 50 requests / second on the Java services.
111+
- `k6`: The [k6](https://k6.io/) load test tool for generating 50 requests / second on the Java
112+
services.
92113

93-
With the Java services described above available in the `target/` directories, you can run the example with:
114+
With the Java services described above available in the `target/` directories, you can run the
115+
example with:
94116

95117
```shell
96118
cd example-exemplars-tail-sampling
97119
docker-compose up
98120
```
99121

100-
Grafana will run on [http://localhost:3000](ttp://localhost:3000). The default user is _admin_ with password _admin_.
122+
Grafana will run on [http://localhost:3000](ttp://localhost:3000). The default user is _admin_ with
123+
password _admin_.
101124

102125
## Example Dashboard
103126

104127
The example dashboard shows 50 requests / second for the Java serices:
105128

106-
![Screenshot showing the request rate on the Java services](https://github.com/prometheus/client_java/assets/330535/9f8dc92e-c9aa-40b6-8fda-a0f7e98560ba)
129+
![Screenshot showing the request rate on the Java services](https://github.com/prometheus/client_java/assets/330535/9f8dc92e-c9aa-40b6-8fda-a0f7e98560ba) <!-- editorconfig-checker-disable-line -->
107130

108131
The Tempo metrics show that only ~5 traces / second are received:
109132

110-
![Screenshot showing the number of traces per second received by Tempo](https://github.com/prometheus/client_java/assets/330535/5e439ac5-3c5c-4d40-a4cd-6737c2c82dfd)
133+
![Screenshot showing the number of traces per second received by Tempo](https://github.com/prometheus/client_java/assets/330535/5e439ac5-3c5c-4d40-a4cd-6737c2c82dfd) <!-- editorconfig-checker-disable-line -->
111134

112-
The reason is that the OpenTelemetry collector is configured to sample only 10% of the traces. Yet, all Exemplars in the
135+
The reason is that the OpenTelemetry collector is configured to sample only 10% of the traces. Yet,
136+
all Exemplars in the
113137
latency graph point to traces that actually made it to Tempo.
114138

115139
## OpenTelemetry Collector Config
116140

117-
The OpenTelemetry collector is configured to keep all Spans with the attribute `exemplar="true"`. Probabilistic sampling
141+
The OpenTelemetry collector is configured to keep all Spans with the attribute `exemplar="true"`.
142+
Probabilistic sampling
118143
applies only to the remainder of the Spans.
119144

120145
```yaml
@@ -133,17 +158,22 @@ processors:
133158
]
134159
```
135160

136-
The Prometheus Java client library automatically sets the `exemplar="true"` attribute for each Span that is used as an
161+
The Prometheus Java client library automatically sets the `exemplar="true"` attribute for each Span
162+
that is used as an
137163
Exemplar.
138164

139-
The Exemplar sampler of the Prometheus Java client library is rate-limited, the `DEFAULT_MIN_RETENTION_PERIOD_SECONDS`
165+
The Exemplar sampler of the Prometheus Java client library is rate-limited, the
166+
`DEFAULT_MIN_RETENTION_PERIOD_SECONDS`
140167
is 7s.
141168
So only one Span per 7 seconds per time series will be marked with `exemplar="true"`.
142169

143170
## Conclusion
144171

145-
The Prometheus Java client library automatically generates Exemplars if OpenTelemetry tracing is detected.
146-
In order to make that work with _tail-based sampling_, the Prometheus Java client library adds an attribute
172+
The Prometheus Java client library automatically generates Exemplars if OpenTelemetry tracing is
173+
detected.
174+
In order to make that work with _tail-based sampling_, the Prometheus Java client library adds an
175+
attribute
147176
`exemplar="true"` to each Span that's used as an Exemplar.
148-
The `tail_sampling` processor in the OpenTelemetry collector can be configured to always sample Spans marked as
177+
The `tail_sampling` processor in the OpenTelemetry collector can be configured to always sample
178+
Spans marked as
149179
`exemplar="true"`.

examples/example-exemplars-tail-sampling/example-greeting-service/pom.xml

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,72 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
5+
<modelVersion>4.0.0</modelVersion>
66

7-
<parent>
8-
<groupId>io.prometheus</groupId>
9-
<artifactId>example-exemplars-tail-sampling</artifactId>
10-
<version>1.4.0-SNAPSHOT</version>
11-
</parent>
7+
<parent>
8+
<groupId>io.prometheus</groupId>
9+
<artifactId>example-exemplars-tail-sampling</artifactId>
10+
<version>1.4.0-SNAPSHOT</version>
11+
</parent>
1212

13-
<artifactId>example-greeting-service</artifactId>
13+
<artifactId>example-greeting-service</artifactId>
1414

15-
<name>Example - OpenTelemetry Exemplars - Greeting Service</name>
16-
<description>
17-
Part of a distributed "Hello, World" REST service to show Exemplars with OpenTelemetry's distributed tracing
18-
</description>
15+
<name>Example - OpenTelemetry Exemplars - Greeting Service</name>
16+
<description>
17+
Part of a distributed "Hello, World" REST service to show Exemplars with OpenTelemetry's distributed
18+
tracing
19+
</description>
1920

20-
<properties>
21-
<java.version>17</java.version>
22-
</properties>
21+
<properties>
22+
<java.version>17</java.version>
23+
</properties>
2324

24-
<dependencies>
25-
<dependency>
26-
<groupId>io.prometheus</groupId>
27-
<artifactId>prometheus-metrics-core</artifactId>
28-
<version>${project.version}</version>
29-
</dependency>
30-
<dependency>
31-
<groupId>io.prometheus</groupId>
32-
<artifactId>prometheus-metrics-instrumentation-jvm</artifactId>
33-
<version>${project.version}</version>
34-
</dependency>
35-
<dependency>
36-
<groupId>io.prometheus</groupId>
37-
<artifactId>prometheus-metrics-exporter-servlet-jakarta</artifactId>
38-
<version>${project.version}</version>
39-
</dependency>
40-
<dependency>
41-
<groupId>org.apache.tomcat.embed</groupId>
42-
<artifactId>tomcat-embed-core</artifactId>
43-
<version>11.0.6</version>
44-
</dependency>
45-
</dependencies>
25+
<dependencies>
26+
<dependency>
27+
<groupId>io.prometheus</groupId>
28+
<artifactId>prometheus-metrics-core</artifactId>
29+
<version>${project.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.prometheus</groupId>
33+
<artifactId>prometheus-metrics-instrumentation-jvm</artifactId>
34+
<version>${project.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.prometheus</groupId>
38+
<artifactId>prometheus-metrics-exporter-servlet-jakarta</artifactId>
39+
<version>${project.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.tomcat.embed</groupId>
43+
<artifactId>tomcat-embed-core</artifactId>
44+
<version>11.0.6</version>
45+
</dependency>
46+
</dependencies>
4647

47-
<build>
48-
<finalName>${project.artifactId}</finalName>
49-
<plugins>
50-
<plugin>
51-
<groupId>org.apache.maven.plugins</groupId>
52-
<artifactId>maven-shade-plugin</artifactId>
53-
<executions>
54-
<execution>
55-
<phase>package</phase>
56-
<goals>
57-
<goal>shade</goal>
58-
</goals>
59-
<configuration>
60-
<transformers>
61-
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
62-
<mainClass>io.prometheus.metrics.examples.otel.exemplars.greeting.Main</mainClass>
63-
</transformer>
64-
</transformers>
65-
</configuration>
66-
</execution>
67-
</executions>
68-
</plugin>
69-
</plugins>
70-
</build>
48+
<build>
49+
<finalName>${project.artifactId}</finalName>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-shade-plugin</artifactId>
54+
<executions>
55+
<execution>
56+
<phase>package</phase>
57+
<goals>
58+
<goal>shade</goal>
59+
</goals>
60+
<configuration>
61+
<transformers>
62+
<transformer
63+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
64+
<mainClass>io.prometheus.metrics.examples.otel.exemplars.greeting.Main</mainClass>
65+
</transformer>
66+
</transformers>
67+
</configuration>
68+
</execution>
69+
</executions>
70+
</plugin>
71+
</plugins>
72+
</build>
7173
</project>

0 commit comments

Comments
 (0)