You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/migration/simpleclient.md
+52-6Lines changed: 52 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,17 @@ title: Simpleclient
3
3
weight: 1
4
4
---
5
5
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:
7
7
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.
10
10
11
-
Migrating from Simpleclient
12
-
---------------------------
11
+
Migration using the Simpleclient Bridge
12
+
---------------------------------------
13
13
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`.
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
+
importio.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
+
importio.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