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

feat: support prometheus new client of micrometer 1.13.0 version #14269

Closed
wants to merge 13 commits into from
Closed
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 @@ -646,4 +646,6 @@ public interface CommonConstants {
String DUBBO_MANUAL_REGISTER_KEY = "dubbo.application.manual-register";

String DUBBO2_COMPACT_ENABLE = "dubbo.compact.enable";

String ZOOKEEPER_ENSEMBLE_TRACKER_KEY = "zookeeper.ensemble.tracker";
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,9 @@ public boolean isSupportMetrics() {
}

public static boolean isSupportPrometheus() {
return isClassPresent("io.micrometer.prometheus.PrometheusConfig")
&& isClassPresent("io.prometheus.client.exporter.BasicAuthHttpConnectionFactory")
&& isClassPresent("io.prometheus.client.exporter.HttpConnectionFactory")
&& isClassPresent("io.prometheus.client.exporter.PushGateway");
return isClassPresent("io.micrometer.prometheusmetrics.PrometheusConfig")
&& isClassPresent("io.micrometer.prometheusmetrics.PrometheusMeterRegistry")
&& isClassPresent("io.prometheus.metrics.exporter.pushgateway.PushGateway");
}

private static boolean isClassPresent(String className) {
Expand Down
9 changes: 4 additions & 5 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<httpclient_version>4.5.14</httpclient_version>
<httpcore_version>4.4.16</httpcore_version>
<fastjson_version>1.2.83</fastjson_version>
<fastjson2_version>2.0.49</fastjson2_version>
<fastjson2_version>2.0.51</fastjson2_version>
<zookeeper_version>3.7.0</zookeeper_version>
<curator_version>5.1.0</curator_version>
<curator_test_version>2.12.0</curator_test_version>
Expand All @@ -123,7 +123,7 @@

<micrometer-tracing.version>1.2.5</micrometer-tracing.version>
<t_digest.version>3.3</t_digest.version>
<prometheus_client.version>0.16.0</prometheus_client.version>
<prometheus_client.version>1.3.1</prometheus_client.version>
<reactive.version>1.0.4</reactive.version>
<reactor.version>3.6.6</reactor.version>
<rxjava.version>2.2.21</rxjava.version>
Expand Down Expand Up @@ -717,15 +717,14 @@
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<artifactId>prometheus-metrics-core</artifactId>
<version>${prometheus_client.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<artifactId>prometheus-metrics-exporter-pushgateway</artifactId>
Comment on lines +720 to +725
Copy link
Member

Choose a reason for hiding this comment

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

We can only make this breaking change in 3.3

<version>${prometheus_client.version}</version>
</dependency>
<!-- reactive related dependencies -->
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions dubbo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.13.0</version>
<version>3.13.1</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -74,7 +74,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.13.0</version>
<version>3.13.1</version>
<configuration>
<goalPrefix>dubbo</goalPrefix>
</configuration>
Expand Down
8 changes: 6 additions & 2 deletions dubbo-metrics/dubbo-metrics-prometheus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus-simpleclient</artifactId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<artifactId>prometheus-metrics-core</artifactId>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>prometheus-metrics-exporter-pushgateway</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.exporter.BasicAuthHttpConnectionFactory;
import io.prometheus.client.exporter.PushGateway;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import io.prometheus.metrics.exporter.pushgateway.PushGateway;
import io.prometheus.metrics.exporter.pushgateway.PushGateway.Builder;

import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_METRICS_COLLECTOR_EXCEPTION;
import static org.apache.dubbo.common.constants.MetricsConstants.PROMETHEUS_DEFAULT_JOB_NAME;
Expand Down Expand Up @@ -80,11 +80,14 @@ private void schedulePushJob() {

NamedThreadFactory threadFactory = new NamedThreadFactory("prometheus-push-job", true);
pushJobExecutor = Executors.newScheduledThreadPool(1, threadFactory);
PushGateway pushGateway = new PushGateway(baseUrl);
Builder pushGatewayBuilder = PushGateway.builder()
.address(baseUrl)
.job(job)
.registry(prometheusRegistry.getPrometheusRegistry());
if (!StringUtils.isBlank(username)) {
pushGateway.setConnectionFactory(new BasicAuthHttpConnectionFactory(username, password));
pushGatewayBuilder.basicAuth(username, password);
}

PushGateway pushGateway = pushGatewayBuilder.build();
pushJobExecutor.scheduleWithFixedDelay(
() -> push(pushGateway, job), pushInterval, pushInterval, TimeUnit.SECONDS);
}
Expand All @@ -93,7 +96,7 @@ private void schedulePushJob() {
protected void push(PushGateway pushGateway, String job) {
try {
resetIfSamplesChanged();
pushGateway.pushAdd(prometheusRegistry.getPrometheusRegistry(), job);
pushGateway.push();
Copy link
Member

Choose a reason for hiding this comment

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

Is there a document available

} catch (IOException e) {
logger.error(
COMMON_METRICS_COLLECTOR_EXCEPTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.stream.Collectors;

import com.sun.net.httpserver.HttpServer;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
Expand Down Expand Up @@ -80,13 +80,9 @@ void testJvmMetrics() {
reporter.init();

PrometheusMeterRegistry prometheusRegistry = reporter.getPrometheusRegistry();
Double d1 = prometheusRegistry.getPrometheusRegistry().getSampleValue("none_exist_metric");
Double d2 = prometheusRegistry
.getPrometheusRegistry()
.getSampleValue(
"jvm_gc_memory_promoted_bytes_total", new String[] {"application_name"}, new String[] {name});
Assertions.assertNull(d1);
Assertions.assertNull(d2);
boolean jvmMetrics = prometheusRegistry.getMeters().stream()
.anyMatch(meter -> meter.getId().getName().startsWith("jvm."));
Assertions.assertTrue(jvmMetrics);
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions dubbo-native-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.13.0</version>
<version>3.13.1</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -77,7 +77,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.13.0</version>
<version>3.13.1</version>
<configuration>
<goalPrefix>dubbo</goalPrefix>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ private ReactorServerCalls() {}
public static <T, R> void oneToOne(T request, StreamObserver<R> responseObserver, Function<Mono<T>, Mono<R>> func) {
try {
func.apply(Mono.just(request))
.switchIfEmpty(Mono.error(TriRpcStatus.NOT_FOUND.asException()))
.subscribe(
res -> {
responseObserver.onNext(res);
responseObserver.onCompleted();
},
responseObserver::onNext,
throwable -> doOnResponseHasException(throwable, responseObserver),
() -> doOnResponseHasException(TriRpcStatus.NOT_FOUND.asException(), responseObserver));
responseObserver::onCompleted);
} catch (Throwable throwable) {
doOnResponseHasException(throwable, responseObserver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public abstract class AbstractZookeeperClient<TargetDataListener, TargetChildLis
// may hang up to wait name resolution up to 10s
protected int DEFAULT_CONNECTION_TIMEOUT_MS = 30 * 1000;
protected int DEFAULT_SESSION_TIMEOUT_MS = 60 * 1000;
protected boolean DEFAULT_ENSEMBLE_TRACKER = true;

private final URL url;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import static org.apache.dubbo.common.constants.CommonConstants.SESSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.ZOOKEEPER_ENSEMBLE_TRACKER_KEY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_CONNECT_REGISTRY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_ZOOKEEPER_EXCEPTION;

Expand All @@ -74,10 +75,12 @@ public Curator5ZookeeperClient(URL url) {
try {
int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_CONNECTION_TIMEOUT_MS);
int sessionExpireMs = url.getParameter(SESSION_KEY, DEFAULT_SESSION_TIMEOUT_MS);
boolean ensembleTracker = url.getParameter(ZOOKEEPER_ENSEMBLE_TRACKER_KEY, DEFAULT_ENSEMBLE_TRACKER);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
.connectString(url.getBackupAddress())
.retryPolicy(new RetryNTimes(1, 1000))
.connectionTimeoutMs(timeout)
.ensembleTracker(ensembleTracker)
.sessionTimeoutMs(sessionExpireMs);
String userInformation = url.getUserInformation();
if (userInformation != null && userInformation.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public AccessLogFilter() {}
public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
String accessLogKey = invoker.getUrl().getParameter(Constants.ACCESS_LOG_KEY);
boolean isFixedPath = invoker.getUrl().getParameter(ACCESS_LOG_FIXED_PATH_KEY, true);
if (StringUtils.isEmpty(accessLogKey)) {
if (StringUtils.isEmpty(accessLogKey) || "false".equalsIgnoreCase(accessLogKey)) {
// Notice that disable accesslog of one service may cause the whole application to stop collecting
// accesslog.
// It's recommended to use application level configuration to enable or disable accesslog if dynamically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

import org.springframework.http.HttpHeaders;
import org.springframework.util.unit.DataSize;
import zipkin2.Call;
import zipkin2.CheckResult;
import zipkin2.codec.Encoding;
import zipkin2.reporter.BytesMessageEncoder;
import zipkin2.reporter.Call;
import zipkin2.reporter.CheckResult;
import zipkin2.reporter.ClosedSenderException;
import zipkin2.reporter.Encoding;
import zipkin2.reporter.Sender;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static class ReporterConfiguration {
@ConditionalOnMissingBean
@ConditionalOnBean(Sender.class)
AsyncReporter<Span> spanReporter(Sender sender, BytesEncoder<Span> encoder) {
return AsyncReporter.builder(sender).build(encoder);
return AsyncReporter.builder(sender).build((zipkin2.reporter.BytesEncoder<Span>) encoder);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestTemplate;
import zipkin2.Call;
import zipkin2.Callback;
import zipkin2.reporter.Call;
import zipkin2.reporter.Callback;

class ZipkinRestTemplateSender extends HttpSender {
private final String endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import zipkin2.Call;
import zipkin2.Callback;
import zipkin2.reporter.Call;
import zipkin2.reporter.Callback;

class ZipkinWebClientSender extends HttpSender {
private final String endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<properties>
<micrometer.version>1.13.0</micrometer.version>
<micrometer-tracing.version>1.2.5</micrometer-tracing.version>
<opentelemetry.version>1.34.1</opentelemetry.version>
<zipkin-reporter.version>2.17.2</zipkin-reporter.version>
<opentelemetry.version>1.38.0</opentelemetry.version>
<zipkin-reporter.version>3.4.0</zipkin-reporter.version>
<prometheus-client.version>0.16.0</prometheus-client.version>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion dubbo-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- Fix the bug of log4j refer:https://github.com/apache/logging-log4j2/pull/608 -->
<log4j2_version>2.23.1</log4j2_version>
<!-- Spring boot buddy is lower than the delivery dependency package version and can only show the defined dependency version -->
<byte-buddy.version>1.14.15</byte-buddy.version>
<byte-buddy.version>1.14.17</byte-buddy.version>
</properties>

<dependencyManagement>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@
<maven_deploy_version>2.8.2</maven_deploy_version>
<maven_compiler_version>3.13.0</maven_compiler_version>
<maven_source_version>3.3.1</maven_source_version>
<maven_javadoc_version>3.6.3</maven_javadoc_version>
<maven_javadoc_version>3.7.0</maven_javadoc_version>
<maven_jetty_version>9.4.54.v20240208</maven_jetty_version>
<maven_checkstyle_version>3.3.1</maven_checkstyle_version>
<maven_jacoco_version>0.8.12</maven_jacoco_version>
<maven_flatten_version>1.6.0</maven_flatten_version>
<maven_enforce_version>3.4.1</maven_enforce_version>
<maven_enforce_version>3.5.0</maven_enforce_version>
<maven_antrun_version>3.1.0</maven_antrun_version>
<maven_os_plugin_version>1.7.1</maven_os_plugin_version>
<maven_protobuf_plugin_version>0.6.1</maven_protobuf_plugin_version>
Expand Down Expand Up @@ -315,7 +315,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<version>3.6.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
Expand Down
Loading