This is an automated email from the ASF dual-hosted git repository.
zrlw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git
The following commit(s) were added to refs/heads/master by this push:
new 92c923e6a Fix metrics prometheus consumer to generate metrics data as
soone as possible (#1251)
92c923e6a is described below
commit 92c923e6af4dae5c1365605a61c5e59036505f88
Author: zrlw <[email protected]>
AuthorDate: Sat Aug 30 14:11:48 2025 +0800
Fix metrics prometheus consumer to generate metrics data as soone as
possible (#1251)
* calling dubbo services immediately to generate metrics data as soon as
possible
* remove zookeeper service from case configuration as the provider has an
embedded zookeeper
* fix consumer dubbo application name
* fix content format of provider xml
---
.../case-configuration.yml | 5 +----
.../prometheus/consumer/MetricsConsumer.java | 19 ++++++++++---------
.../src/main/resources/dubbo-demo-consumer.xml | 21 +++++++++++++--------
.../src/main/resources/dubbo-demo-provider.xml | 19 ++++++++++++-------
4 files changed, 36 insertions(+), 28 deletions(-)
diff --git
a/4-governance/dubbo-samples-metrics-prometheus/case-configuration.yml
b/4-governance/dubbo-samples-metrics-prometheus/case-configuration.yml
index d02d8fa73..feccf43c0 100644
--- a/4-governance/dubbo-samples-metrics-prometheus/case-configuration.yml
+++ b/4-governance/dubbo-samples-metrics-prometheus/case-configuration.yml
@@ -15,9 +15,6 @@
# limitations under the License.
services:
- zookeeper:
- image: zookeeper:latest
-
metrics-prometheus-provider:
type: app
basedir: dubbo-samples-metrics-prometheus-provider
@@ -37,4 +34,4 @@ services:
- metrics-prometheus-provider:2181
- metrics-prometheus-provider:20880
depends_on:
- - metrics-prometheus-provider
\ No newline at end of file
+ - metrics-prometheus-provider
diff --git
a/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-consumer/src/main/java/org/apache/dubbo/samples/metrics/prometheus/consumer/MetricsConsumer.java
b/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-consumer/src/main/java/org/apache/dubbo/samples/metrics/prometheus/consumer/MetricsConsumer.java
index 01cd03e3e..212437e28 100644
---
a/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-consumer/src/main/java/org/apache/dubbo/samples/metrics/prometheus/consumer/MetricsConsumer.java
+++
b/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-consumer/src/main/java/org/apache/dubbo/samples/metrics/prometheus/consumer/MetricsConsumer.java
@@ -34,27 +34,28 @@ public class MetricsConsumer {
DemoService demoService = ctx.getBean(DemoService.class);
DemoService2 demoService2 = ctx.getBean(DemoService2.class);
while (true) {
+ // Calling dubbo services immediately to generate metrics data as
soon as possible.
+ logger.info(demoService.sayHello("Dubbo").getMsg());
try {
- Thread.sleep(1000);
- } catch (Exception e) {
- logger.error("sleep failed: ", e);
- }
- System.out.println(demoService.sayHello("Dubbo").getMsg());
- try {
-
System.out.println(demoService.randomResponseTime("Dubbo").getMsg());
+ logger.info(demoService.randomResponseTime("Dubbo").getMsg());
} catch (Exception e) {
logger.error("randomResponseTime failed: ", e);
}
try {
-
System.out.println(demoService.runTimeException("Dubbo").getMsg());
+ logger.info(demoService.runTimeException("Dubbo").getMsg());
} catch (Exception e) {
logger.error("runTimeException failed: ", e);
}
try {
-
System.out.println(demoService.timeLimitedMethod("Dubbo").getMsg());
+ logger.info(demoService.timeLimitedMethod("Dubbo").getMsg());
} catch (Exception e) {
logger.error("timeLimitedMethod failed: ", e);
}
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+ logger.error("sleep failed: ", e);
+ }
}
}
diff --git
a/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-consumer/src/main/resources/dubbo-demo-consumer.xml
b/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-consumer/src/main/resources/dubbo-demo-consumer.xml
index fe3de8369..299678f3c 100644
---
a/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-consumer/src/main/resources/dubbo-demo-consumer.xml
+++
b/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-consumer/src/main/resources/dubbo-demo-consumer.xml
@@ -18,13 +18,17 @@
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
- xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
+ xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://dubbo.apache.org/schema/dubbo
+ http://dubbo.apache.org/schema/dubbo/dubbo.xsd
+ http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder/>
- <dubbo:application name="metrics-provider" qos-enable="true"
qos-port="20889" qos-accept-foreign-ip="false"
- qos-accept-foreign-ip-whitelist="
192.168.1.169,47.96.183.43,192.168.1.9,121.199.25.64"/>
+ <dubbo:application name="metrics-consumer" qos-enable="true"
qos-port="20889" qos-accept-foreign-ip="false"
+
qos-accept-foreign-ip-whitelist="192.168.1.169,47.96.183.43,192.168.1.9,121.199.25.64"/>
<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
<dubbo:config-center
address="zookeeper://${zookeeper.address:127.0.0.1}:2181" />
@@ -35,8 +39,9 @@
<dubbo:aggregation enabled="true"/>
</dubbo:metrics>
- <dubbo:reference
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService"
id="demoService" check="false"/>
+ <dubbo:reference
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService"
+ id="demoService" check="false"/>
-
- <dubbo:reference
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService2"
id="demoService2" check="false"/>
+ <dubbo:reference
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService2"
+ id="demoService2" check="false"/>
</beans>
diff --git
a/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-provider/src/main/resources/dubbo-demo-provider.xml
b/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-provider/src/main/resources/dubbo-demo-provider.xml
index 12a5cd905..bb0d6225c 100644
---
a/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-provider/src/main/resources/dubbo-demo-provider.xml
+++
b/4-governance/dubbo-samples-metrics-prometheus/dubbo-samples-metrics-prometheus-provider/src/main/resources/dubbo-demo-provider.xml
@@ -18,13 +18,18 @@
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
- xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
+ xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://dubbo.apache.org/schema/dubbo
+ http://dubbo.apache.org/schema/dubbo/dubbo.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder/>
<dubbo:application name="metrics-provider" qos-enable="true"
qos-port="20888" qos-accept-foreign-ip="false"
- qos-accept-foreign-ip-whitelist="
192.168.1.169,47.96.183.43,192.168.1.9,121.199.25.64"
+
qos-accept-foreign-ip-whitelist="192.168.1.169,47.96.183.43,192.168.1.9,121.199.25.64"
metadata-type="remote"/>
<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
@@ -37,9 +42,9 @@
</dubbo:metrics>
<bean id="demoService"
class="org.apache.dubbo.samples.metrics.prometheus.provider.impl.DemoServiceImpl"/>
- <dubbo:service
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService"
ref="demoService"/>
+ <dubbo:service
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService"
ref="demoService"/>
- <bean id="demoService2"
class="org.apache.dubbo.samples.metrics.prometheus.provider.impl.DemoServiceImpl2"/>
- <dubbo:service
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService2"
ref="demoService2"/>
+ <bean id="demoService2"
class="org.apache.dubbo.samples.metrics.prometheus.provider.impl.DemoServiceImpl2"/>
+ <dubbo:service
interface="org.apache.dubbo.samples.metrics.prometheus.api.DemoService2"
ref="demoService2"/>
</beans>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]