Skip to content

Commit 491d226

Browse files
committed
Add more 0.16.0 migration docs
Signed-off-by: Fabian Stäber <[email protected]>
1 parent db04702 commit 491d226

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

docs/content/migration/simpleclient.md

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ title: Simpleclient
33
weight: 1
44
---
55

6-
The Prometheus Java client library 1.0.0 is a complete rewrite, and is not backwards compatible with the old `simpleclient` modules 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 compatible with releases 0.16.0 and older for a variety of reasons:
77

8-
* We rewrote the underlying data model. The `simpleclient` data model is based on [OpenMetrics](https://openmetrics.io/), which is based on the assumption that each data point has exactly one `double` value (`Collector.Sample.value` in `simpleclient`). With the new Prometheus native histograms this is no longer true. Native histograms have a complex data structure as value. This is the reason why native histograms cannot be exposed in OpenMetrics text format. The new `prometheus-metrics-model` implements the current Prometheus data model and is not based on OpenMetrics.
9-
* We refactored the package names. The simpleclient has package names that are reused by multiple Maven modules, which causes issues with the Java module system. The new `prometheus-metrics` modules each has their own package name, package names are not reused.
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.
1010

11-
Migrating from Simpleclient
12-
---------------------------
11+
Migration using the Simpleclient Bridge
12+
---------------------------------------
1313

14-
For users of previous versions of the Prometheus Java client we provide a migration module for bridging the simpleclient `CollectorRegistry` to the new `PromethesuRegistry`.
14+
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.
15+
16+
We provide a migration module for bridging the old simpleclient `CollectorRegistry` to the new `PromethesuRegistry`.
1517

1618
To use the bridge, add the following dependency:
1719

@@ -50,3 +52,47 @@ SimpleclientCollector.builder()
5052
.collectorRegistry(simpleclientRegistry)
5153
.register(prometheusRegistry);
5254
```
55+
56+
Refactoring the Instrumentation Code
57+
------------------------------------
58+
59+
If you decide to get rid of the old 0.16.0 dependencies and use 1.0.0 only, you need to refactor your code:
60+
61+
Dependencies:
62+
63+
* `simpleclient` -> `prometheus-metrics-core`
64+
* `simpleclient_hotspot` -> `prometheus-metrics-instrumentation-jvm`
65+
* `simpleclient_httpserver` -> `prometheus-metrics-exporter-httpserver`
66+
* `simpleclient_servlet_jakarta` -> `prometheus-metrics-exporter-servlet-jakarta`
67+
68+
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()`.
69+
70+
Example of the old 0.16.0 API:
71+
72+
```java
73+
import io.prometheus.client.Counter;
74+
75+
Counter counter = Counter.build()
76+
.name("test")
77+
.help("test counter")
78+
.labelNames("path")
79+
.register();
80+
81+
counter.labels("/hello-world").inc();
82+
```
83+
84+
Example of the new 1.0.0 API:
85+
86+
```java
87+
import io.prometheus.metrics.core.metrics.Counter;
88+
89+
Counter counter = Counter.builder()
90+
.name("test")
91+
.help("test counter")
92+
.labelNames("path")
93+
.register();
94+
95+
counter.labelValues("/hello-world").inc();
96+
```
97+
98+
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.

0 commit comments

Comments
 (0)