A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://prometheus.github.io/client_java/migration/simpleclient/ below:

Simpleclient | client_java

Simpleclient

The Prometheus Java client library 1.0.0 is a complete rewrite of the underlying data model, and is not backward compatible with releases 0.16.0 and older for a variety of reasons:

Migration using the Simpleclient Bridge

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.

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

To use the bridge, add the following dependency:

Gradle
implementation 'io.prometheus:prometheus-metrics-simpleclient-bridge:1.0.0'
Maven

<dependency>
  <groupId>io.prometheus</groupId>
  <artifactId>prometheus-metrics-simpleclient-bridge</artifactId>
  <version>1.0.0</version>
</dependency>

Then add the following to your code:

SimpleclientCollector.builder().register();

This will make all metrics registered with simpleclient’s CollectorRegistry.defaultRegistry available in the new PrometheusRegistry.defaultRegistry.

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

CollectorRegistry simpleclientRegistry = ...;
PrometheusRegistry prometheusRegistry = ...;

SimpleclientCollector.builder()
  .collectorRegistry(simpleclientRegistry)
  .register(prometheusRegistry);
Refactoring the Instrumentation Code

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:

Dependencies:

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().

Example of the old 0.16.0 API:

import io.prometheus.client.Counter;

Counter counter = Counter.build()
  .name("test")
  .help("test counter")
  .labelNames("path")
  .register();

counter.labels("/hello-world").inc();

Example of the new 1.0.0 API:

import io.prometheus.metrics.core.metrics.Counter;

Counter counter = Counter.builder()
  .name("test")
  .help("test counter")
  .labelNames("path")
  .register();

counter.labelValues("/hello-world").inc();

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.

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/. Chances are good that the new callback metrics have an easier way to achieve what you need than the old 0.16.0 code.

Version 0.16.0 provided the simpleclient_hotspot module for exposing built-in JVM metrics:

DefaultExports.initialize();

With version 1.0.0 these metrics moved to the prometheus-metrics-instrumentation-jvm module and are initialized as follows:

JvmMetrics.builder().register();

A full list of the available JVM metrics can be found on /instrumentation/jvm.

Most JVM metric names remained the same, except for a few cases where the old 0.16.0 metric names were not compliant with the OpenMetrics specification. OpenMetrics requires the unit to be a suffix, so we renamed metrics where the unit was in the middle of the metric name and moved the unit to the end of the metric name. The following metric names changed:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4