Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ public static boolean isSupportMetrics() {
}

public static boolean isSupportPrometheus() {
return isClassPresent("io.micrometer.prometheus.PrometheusConfig")
&& isClassPresent("io.prometheus.client.exporter.BasicAuthHttpConnectionFactory")
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove io.prometheus.client.* checking if isClassPresent("io.micrometer.prometheus.PrometheusConfig") is true?

Copy link
Contributor

Choose a reason for hiding this comment

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

The io.prometheus.client.* classes are not included when using the dubbo-observability-spring-boot-starter in Dubbo 3.3.x. The relevant dependencies are only included in the 3.2.x version of dubbo-spring-boot-observability-starter, and they belong to Prometheus Client 0.16.0, which is deprecated.

i see

&& isClassPresent("io.prometheus.client.exporter.HttpConnectionFactory")
&& isClassPresent("io.prometheus.client.exporter.PushGateway");
// Micrometer package changed in newer versions:
// io.micrometer.prometheus.* -> io.micrometer.prometheusmetrics.*
boolean micrometerPrometheusPresent = isClassPresent("io.micrometer.prometheus.PrometheusConfig")
| isClassPresent("io.micrometer.prometheusmetrics.PrometheusConfig");

// PushGateway classes are optional for exporter-only usage and differ across versions,
// so do not hard-fail prometheus support on them.
return micrometerPrometheusPresent;
}

private static boolean isClassPresent(String className) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://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 org.apache.dubbo.metrics.utils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class MetricsSupportUtilTest {

@Test
void shouldSupportMetrics() {
Assertions.assertTrue(MetricsSupportUtil.isSupportMetrics());
}

@Test
void shouldDetectPrometheusClasspathWithoutThrowing() {
Assertions.assertFalse(MetricsSupportUtil.isSupportPrometheus());
}
}
Loading