You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/11/29 12:41:11 UTC
[dubbo] branch 3.2 updated: dubbo metrics to springboot endpoints (#10997)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.2 by this push:
new b23cfa8c07 dubbo metrics to springboot endpoints (#10997)
b23cfa8c07 is described below
commit b23cfa8c07994c9d2759364fd2178a82f6eae3eb
Author: songxiaosheng <81...@users.noreply.github.com>
AuthorDate: Tue Nov 29 20:41:03 2022 +0800
dubbo metrics to springboot endpoints (#10997)
---
.../dubbo/metrics/AbstractMetricsReporter.java | 6 +++
.../org/apache/dubbo/metrics/DubboMetrics.java | 34 ++++++++++++++++
.../dubbo-spring-boot-actuator/pom.xml | 5 +++
.../DubboMetricsAutoConfiguration.java | 44 +++++++++++++++++++++
.../boot/actuate/mertics/DubboMetricsBinder.java | 46 ++++++++++++++++++++++
.../src/main/resources/META-INF/spring.factories | 3 +-
6 files changed, 137 insertions(+), 1 deletion(-)
diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/AbstractMetricsReporter.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/AbstractMetricsReporter.java
index 2b384c33b0..a164afda4d 100644
--- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/AbstractMetricsReporter.java
+++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/AbstractMetricsReporter.java
@@ -89,6 +89,12 @@ public abstract class AbstractMetricsReporter implements MetricsReporter {
protected void addMeterRegistry(MeterRegistry registry) {
compositeRegistry.add(registry);
}
+ private void addDubboMeterRegistry(){
+ MeterRegistry globalRegistry = DubboMetrics.globalRegistry;
+ if(globalRegistry != null){
+ compositeRegistry.add(globalRegistry);
+ }
+ }
protected ApplicationModel getApplicationModel() {
return applicationModel;
diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/DubboMetrics.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/DubboMetrics.java
new file mode 100644
index 0000000000..d11a4f55a1
--- /dev/null
+++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/DubboMetrics.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.binder.MeterBinder;
+
+
+public class DubboMetrics implements MeterBinder {
+
+ protected static volatile MeterRegistry globalRegistry = null;
+ @Override
+ public void bindTo(MeterRegistry registry) {
+ this.globalRegistry = registry;
+ }
+
+ public void destroy() {
+ }
+}
+
diff --git a/dubbo-spring-boot/dubbo-spring-boot-actuator/pom.xml b/dubbo-spring-boot/dubbo-spring-boot-actuator/pom.xml
index 9246831edf..d9af335d4d 100644
--- a/dubbo-spring-boot/dubbo-spring-boot-actuator/pom.xml
+++ b/dubbo-spring-boot/dubbo-spring-boot-actuator/pom.xml
@@ -145,6 +145,11 @@
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-metrics-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
diff --git a/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboMetricsAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboMetricsAutoConfiguration.java
new file mode 100644
index 0000000000..b8c825f1d2
--- /dev/null
+++ b/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboMetricsAutoConfiguration.java
@@ -0,0 +1,44 @@
+/*
+ * 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.spring.boot.actuate.autoconfigure;
+
+import io.micrometer.core.instrument.MeterRegistry;
+import org.apache.dubbo.metrics.DubboMetrics;
+import org.apache.dubbo.spring.boot.actuate.mertics.DubboMetricsBinder;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+
+
+@Configuration(
+ proxyBeanMethods = false
+)
+@ConditionalOnWebApplication
+@ConditionalOnClass({DubboMetrics.class})
+public class DubboMetricsAutoConfiguration {
+ @Bean
+ @ConditionalOnBean({MeterRegistry.class})
+ @ConditionalOnMissingBean({DubboMetrics.class, DubboMetricsBinder.class})
+ public DubboMetricsBinder tomcatMetricsBinder(MeterRegistry meterRegistry) {
+ return new DubboMetricsBinder(meterRegistry);
+ }
+}
diff --git a/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/mertics/DubboMetricsBinder.java b/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/mertics/DubboMetricsBinder.java
new file mode 100644
index 0000000000..5ea4644540
--- /dev/null
+++ b/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/mertics/DubboMetricsBinder.java
@@ -0,0 +1,46 @@
+/*
+ * 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.spring.boot.actuate.mertics;
+
+import org.apache.dubbo.metrics.DubboMetrics;
+import io.micrometer.core.instrument.MeterRegistry;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
+import org.springframework.context.ApplicationListener;
+
+
+public class DubboMetricsBinder implements ApplicationListener<ApplicationStartedEvent>, DisposableBean {
+ private final MeterRegistry meterRegistry;
+ private volatile DubboMetrics dubboMetrics;
+
+ public DubboMetricsBinder(MeterRegistry meterRegistry) {
+ this.meterRegistry = meterRegistry;
+ }
+
+
+ @Override
+ public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {
+ dubboMetrics = new DubboMetrics();
+ dubboMetrics.bindTo(meterRegistry);
+ }
+
+ @Override
+ public void destroy() throws Exception {
+ dubboMetrics.destroy();
+ }
+}
diff --git a/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/resources/META-INF/spring.factories b/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/resources/META-INF/spring.factories
index 53a1bb0d0d..959f1a96ab 100644
--- a/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/resources/META-INF/spring.factories
+++ b/dubbo-spring-boot/dubbo-spring-boot-actuator/src/main/resources/META-INF/spring.factories
@@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAnnotationAutoConfiguration
\ No newline at end of file
+org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAnnotationAutoConfiguration,\
+org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboMetricsAutoConfiguration