Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Prometheus 1.x #4846

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/benchmarks-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies {
jmh project(':micrometer-registry-prometheus')

jmh libs.dropwizardMetricsCore5
jmh libs.prometheusClient
jmh libs.prometheusMetrics

jmh 'io.dropwizard.metrics:metrics-core'
jmh 'com.google.guava:guava'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ public void tearDown(Blackhole hole) {
@State(Scope.Benchmark)
public static class PrometheusState {

io.prometheus.client.Counter counter;
io.prometheus.metrics.core.metrics.Counter counter;

io.prometheus.client.Counter counterWithTags;
io.prometheus.metrics.core.metrics.Counter counterWithTags;

@Setup(Level.Trial)
public void setup() {
counter = io.prometheus.client.Counter.build().name("counter").help("A counter").create();
counterWithTags = io.prometheus.client.Counter.build()
counter = io.prometheus.metrics.core.metrics.Counter.builder().name("counter").help("A counter").register();
counterWithTags = io.prometheus.metrics.core.metrics.Counter.builder()
.name("counter")
.help("Counter with two tags declared")
.labelNames("key1", "key2")
Expand Down Expand Up @@ -172,7 +172,7 @@ public void prometheusCounter(PrometheusState state) {

@Benchmark
public void prometheusCounterWithTags(PrometheusState state) {
state.counterWithTags.labels("value1", "value2").inc();
state.counterWithTags.labelValues("value1", "value2").inc();
}

public static void main(String[] args) throws RunnerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
import io.micrometer.core.instrument.distribution.PercentileHistogramBuckets;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.CollectorRegistry;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import io.prometheus.metrics.model.registry.PrometheusRegistry;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
Expand Down Expand Up @@ -108,7 +108,7 @@ public static class MicrometerState {

@Setup(Level.Iteration)
public void setup() {
registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, new CollectorRegistry(), Clock.SYSTEM);
registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, new PrometheusRegistry(), Clock.SYSTEM);
summary = DistributionSummary.builder("summary").publishPercentileHistogram().register(registry);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ public void tearDown(Blackhole hole) {
@State(Scope.Benchmark)
public static class PrometheusState {

io.prometheus.client.Histogram histogram;
io.prometheus.metrics.core.metrics.Histogram histogram;

@Setup(Level.Trial)
public void setup() {
Expand All @@ -152,9 +152,11 @@ public void setup() {
.maximumExpectedValue(Double.POSITIVE_INFINITY)
.percentilesHistogram(true)
.build()));
histogram = io.prometheus.client.Histogram.build("histogram", "A histogram")
.buckets(micrometerBuckets)
.create();
histogram = io.prometheus.metrics.core.metrics.Histogram.builder()
.name("histogram")
.help("A histogram")
.classicUpperBounds(micrometerBuckets)
.register();
}

@TearDown(Level.Iteration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ subprojects {

check.dependsOn("testModules")

if (!(project.name in ['micrometer-jakarta9', 'micrometer-java11', 'micrometer-jetty12'])) { // add projects here that do not exist in the previous minor so should be excluded from japicmp
if (!(project.name in ['micrometer-registry-prometheus', 'micrometer-registry-prometheus-simpleclient', 'micrometer-jakarta9', 'micrometer-java11', 'micrometer-jetty12'])) { // add projects here that do not exist in the previous minor so should be excluded from japicmp
apply plugin: 'me.champeau.gradle.japicmp'
apply plugin: 'de.undercouch.download'

Expand Down
7 changes: 5 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def VERSIONS = [
libs.grpcTestingProto,
libs.grpcKotlinStub,
libs.gmetric4j,
libs.prometheusClient,
libs.prometheusPushgateway,
libs.prometheusMetrics,
libs.prometheusMetricsExpositionFormats,
libs.prometheusMetricsTracerCommon,
libs.prometheusSimpleClient,
libs.prometheusSimpleClientPushgateway,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be dealt with separate from this PR.
I think with the version catalog, we should move away from putting dependencies in here to be managed globally, especially when they're not transitive dependencies. I've been slowly removing them from here when doing related changes to dependencies that don't need to be here. We should use the version catalog reference in each build.gradle file instead, and then there's no need for them to be here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be able to remove things other than the PLATFORM_BOMS and the guava hacks from this file if we use the catalog references everywhere.
I created an issue for this: #4849

libs.restAssured,
libs.retrofit2,
libs.jakarta.jmsApi,
Expand Down
10 changes: 7 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ newrelic-api = "5.14.0"
# Kotlin 1.7 sample will fail from OkHttp 4.12.0 due to okio dependency being a Kotlin 1.9 module
okhttp = "4.11.0"
postgre = "42.7.2"
prometheus = "0.16.0"
prometheus = "1.1.0"
prometheusSimpleClient = "0.16.0"
reactor = "2022.0.16"
rest-assured = "5.4.0"
signalfx = "1.0.39"
Expand Down Expand Up @@ -185,8 +186,11 @@ okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
openTelemetry-proto = { module = "io.opentelemetry.proto:opentelemetry-proto", version = "1.1.0-alpha" }
osgiJunit5 = "org.osgi:org.osgi.test.junit5:1.2.1"
postgre = { module = "org.postgresql:postgresql", version.ref = "postgre" }
prometheusClient = { module = "io.prometheus:simpleclient_common", version.ref = "prometheus" }
prometheusPushgateway = { module = "io.prometheus:simpleclient_pushgateway", version.ref = "prometheus" }
prometheusMetrics = { module = "io.prometheus:prometheus-metrics-core", version.ref = "prometheus" }
prometheusMetricsExpositionFormats = { module = "io.prometheus:prometheus-metrics-exposition-formats", version.ref = "prometheus" }
prometheusMetricsTracerCommon = { module = "io.prometheus:prometheus-metrics-tracer-common", version.ref = "prometheus" }
prometheusSimpleClient = { module = "io.prometheus:simpleclient_common", version.ref = "prometheusSimpleClient" }
prometheusSimpleClientPushgateway = { module = "io.prometheus:simpleclient_pushgateway", version.ref = "prometheusSimpleClient" }
reactorBom = { module = "io.projectreactor:reactor-bom", version.ref = "reactor" }
restAssured = { module = "io.rest-assured:rest-assured", version.ref = "rest-assured" }
retrofit2 = { module = "com.squareup.retrofit2:retrofit", version = "2.9.0" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
description = 'MeterRegistry implementation for Prometheus using io.prometheus:simpleclient_common. This module is deprecated in favor of io.micrometer:micrometer-registry-prometheus that uses io.prometheus:prometheus-metrics-core.'

dependencies {
api project(':micrometer-core')

api 'io.prometheus:simpleclient_common'

testImplementation project(':micrometer-test')
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
/**
* Histogram flavors.
*
* @deprecated since 1.13.0, unfortunately there is no replacement right now since the new
* Prometheus client does not support custom histogram bucket names.
* @author Jon Schneider
* @since 1.4.0
*/
@Deprecated
public enum HistogramFlavor {

Prometheus, VictoriaMetrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
/**
* Configuration for {@link PrometheusMeterRegistry}.
*
* @deprecated since 1.13.0, use the class with the same name from
* io.micrometer:micrometer-registry-prometheus instead:
* {@code io.micrometer.prometheusmetrics.PrometheusConfig}.
* @author Jon Schneider
*/
@Deprecated
public interface PrometheusConfig extends MeterRegistryConfig {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
/**
* {@link Counter} for Prometheus.
*
* @deprecated since 1.13.0, use the class with the same name from
* io.micrometer:micrometer-registry-prometheus instead:
* {@code io.micrometer.prometheusmetrics.PrometheusCounter}.
* @author Jon Schneider
* @author Jonatan Ivanov
*/
@Deprecated
public class PrometheusCounter extends AbstractMeter implements Counter {

private final DoubleAdder count = new DoubleAdder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
/**
* {@link DistributionSummary} for Prometheus.
*
* @deprecated since 1.13.0, use the class with the same name from
* io.micrometer:micrometer-registry-prometheus instead:
* {@code io.micrometer.prometheusmetrics.PrometheusDistributionSummary}.
* @author Jon Schneider
* @author Jonatan Ivanov
*/
@Deprecated
public class PrometheusDistributionSummary extends AbstractDistributionSummary {

private static final CountAtBucket[] EMPTY_HISTOGRAM = new CountAtBucket[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2017 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.prometheus;

/**
* @deprecated since 1.13.0, use the class with the same name from
* io.micrometer:micrometer-registry-prometheus instead:
* {@code io.micrometer.prometheusmetrics.PrometheusDurationNamingConvention}.
*/
@Deprecated
public class PrometheusDurationNamingConvention extends PrometheusNamingConvention {

public PrometheusDurationNamingConvention() {
super("_duration");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@
/**
* {@link MeterRegistry} for Prometheus.
*
* @deprecated since 1.13.0, use the class with the same name from
* io.micrometer:micrometer-registry-prometheus instead:
* {@code io.micrometer.prometheusmetrics.PrometheusMeterRegistry}.
* @author Jon Schneider
* @author Johnny Lim
* @author Jonatan Ivanov
*/
@Deprecated
public class PrometheusMeterRegistry extends MeterRegistry {

private final PrometheusConfig prometheusConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
* See https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels for a
* specification of the constraints on metric names and labels
*
* @deprecated since 1.13.0, use the class with the same name from
* io.micrometer:micrometer-registry-prometheus instead:
* {@code io.micrometer.prometheusmetrics.PrometheusNamingConvention}.
* @author Jon Schneider
*/
@Deprecated
public class PrometheusNamingConvention implements NamingConvention {

private static final Pattern nameChars = Pattern.compile("[^a-zA-Z0-9_:]");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2017 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micrometer.prometheus;

import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.config.MeterFilter;

import java.util.HashMap;
import java.util.Map;

/**
* Converts known meter names from Micrometer's preferred name to Prometheus' preferred
* name.
*
* @deprecated since 1.13.0, use the class with the same name from
* io.micrometer:micrometer-registry-prometheus instead:
* {@code io.micrometer.prometheusmetrics.PrometheusRenameFilter}.
* @author Tommy Ludwig
*/
@Deprecated
public class PrometheusRenameFilter implements MeterFilter {

private static final Map<String, String> MICROMETER_TO_PROMETHEUS_NAMES = new HashMap<>();

static {
MICROMETER_TO_PROMETHEUS_NAMES.put("process.files.open", "process.open.fds");
MICROMETER_TO_PROMETHEUS_NAMES.put("process.files.max", "process.max.fds");
}

@Override
public Meter.Id map(Meter.Id id) {
String convertedName = MICROMETER_TO_PROMETHEUS_NAMES.get(id.getName());
return convertedName == null ? id : id.withName(convertedName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
/**
* {@link Timer} for Prometheus.
*
* @deprecated since 1.13.0, use the class with the same name from
* io.micrometer:micrometer-registry-prometheus instead:
* {@code io.micrometer.prometheusmetrics.PrometheusTimer}.
* @author Jon Schneider
* @author Jonatan Ivanov
*/
@Deprecated
public class PrometheusTimer extends AbstractTimer {

private static final CountAtBucket[] EMPTY_HISTOGRAM = new CountAtBucket[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2017 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Deprecated since 1.13.0, use io.micrometer:micrometer-registry-prometheus instead, the
* new package name is {@code io.micrometer.prometheusmetrics}.
*/
@NonNullApi
@NonNullFields
@Deprecated
package io.micrometer.prometheus;

import io.micrometer.common.lang.NonNullApi;
import io.micrometer.common.lang.NonNullFields;
11 changes: 10 additions & 1 deletion implementations/micrometer-registry-prometheus/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
description = 'MeterRegistry implementation for Prometheus using io.prometheus:prometheus-metrics-core. If you have compatibility issues with this module, you can go back to io.micrometer:micrometer-registry-prometheus-simpleclient that uses io.prometheus:simpleclient_common'

dependencies {
api project(':micrometer-core')

api 'io.prometheus:simpleclient_common'
api('io.prometheus:prometheus-metrics-core') {
// We don't need this nor some of its dependencies:
// io.prometheus:prometheus-metrics-tracer-otel
// io.prometheus:prometheus-metrics-tracer-otel-agent
exclude(group: 'io.prometheus', module: 'prometheus-metrics-tracer-initializer')
}
implementation 'io.prometheus:prometheus-metrics-exposition-formats'

testImplementation 'io.prometheus:prometheus-metrics-tracer-common'
testImplementation project(':micrometer-test')
}
Loading