This is an automated email from the ASF dual-hosted git repository.

albumenj 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 a6a6216c Fix metrics test (#721)
a6a6216c is described below

commit a6a6216cdd268652d42a7815e1c628157baffc43
Author: Albumen Kevin <[email protected]>
AuthorDate: Fri Feb 3 22:07:13 2023 +0800

    Fix metrics test (#721)
---
 .../case-configuration.yml                         |  44 +++-
 .../case-versions.conf                             |   2 +-
 .../dubbo-samples-metrics-spring-boot/pom.xml      |  13 +-
 .../metrics/springboot/EmbeddedZooKeeper.java      | 256 ---------------------
 .../metrics/springboot/api/DemoService.java        |  12 -
 .../metrics/springboot/{model => api}/Result.java  |   2 +-
 .../MetricsConsumer.java}                          |  39 ++--
 .../{impl => provider}/DemoServiceImpl.java        |  44 +---
 .../User.java => provider/MetricsProvider.java}    |  38 +--
 .../main/resources/application-consumer.properties |  18 ++
 .../main/resources/application-provider.properties |  18 ++
 .../src/main/resources/application.properties      |   9 -
 .../main/resources/spring/dubbo-demo-context.xml   |  44 ----
 .../metrics/prometheus/ProviderMetricsIT.java      |  31 +--
 14 files changed, 143 insertions(+), 427 deletions(-)

diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/case-configuration.yml 
b/4-governance/dubbo-samples-metrics-spring-boot/case-configuration.yml
index 0ad86889..988ef707 100644
--- a/4-governance/dubbo-samples-metrics-spring-boot/case-configuration.yml
+++ b/4-governance/dubbo-samples-metrics-spring-boot/case-configuration.yml
@@ -14,11 +14,43 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from: app-builtin-zookeeper.yml
+services:
+  zookeeper:
+    image: zookeeper:latest
 
-props:
-  project_name: dubbo-samples-metrics-spring-boot
-  main_class: org.apache.dubbo.samples.metrics.springboot.MetricsApplication
-  zookeeper_port: 2181
-  dubbo_port: 20880
+  provider:
+    type: app
+    basedir: .
+    mainClass: 
org.apache.dubbo.samples.metrics.springboot.provider.MetricsProvider
+    systemProps:
+      - zookeeper.address=zookeeper
+    waitPortsBeforeRun:
+      - zookeeper:2181
+    checkLog: "dubbo service started"
+    depends_on:
+      - zookeeper
 
+  consumer:
+    type: app
+    basedir: .
+    mainClass: 
org.apache.dubbo.samples.metrics.springboot.consumer.MetricsConsumer
+    systemProps:
+      - zookeeper.address=zookeeper
+    waitPortsBeforeRun:
+      - zookeeper:2181
+    checkLog: "dubbo service started"
+    depends_on:
+      - provider
+      - zookeeper
+
+  test:
+    type: test
+    basedir: .
+    tests:
+      - "**/*IT.class"
+    systemProps:
+      - provider=provider
+      - consumer=consumer
+    depends_on:
+      - provider
+      - consumer
diff --git a/4-governance/dubbo-samples-metrics-spring-boot/case-versions.conf 
b/4-governance/dubbo-samples-metrics-spring-boot/case-versions.conf
index a370983f..b6156542 100644
--- a/4-governance/dubbo-samples-metrics-spring-boot/case-versions.conf
+++ b/4-governance/dubbo-samples-metrics-spring-boot/case-versions.conf
@@ -21,5 +21,5 @@
 
 # Spring app
 dubbo.version=[ >=3.2.0 ]
-spring.version=4.*, 5.*
+spring.version=5.*
 java.version= [<= 11]
diff --git a/4-governance/dubbo-samples-metrics-spring-boot/pom.xml 
b/4-governance/dubbo-samples-metrics-spring-boot/pom.xml
index c136f60f..5e907831 100644
--- a/4-governance/dubbo-samples-metrics-spring-boot/pom.xml
+++ b/4-governance/dubbo-samples-metrics-spring-boot/pom.xml
@@ -36,7 +36,7 @@
     <properties>
         <source.level>1.8</source.level>
         <target.level>1.8</target.level>
-        <dubbo.version>3.2.0-beta.4-SNAPSHOT</dubbo.version>
+        <dubbo.version>3.2.0-beta.5-SNAPSHOT</dubbo.version>
         <junit.version>4.13.1</junit.version>
         <spring.version>5.3.18</spring.version>
         <httpclient.version>4.5.13</httpclient.version>
@@ -148,6 +148,17 @@
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-observation</artifactId>
+            <version>1.10.3</version>
+        </dependency>
+
 
         <dependency>
             <groupId>com.alibaba</groupId>
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/EmbeddedZooKeeper.java
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/EmbeddedZooKeeper.java
deleted file mode 100644
index 794311fe..00000000
--- 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/EmbeddedZooKeeper.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright 2014 the original author or authors.
- *
- * 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
- *
- * 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.samples.metrics.springboot;
-
-import org.apache.zookeeper.server.ServerConfig;
-import org.apache.zookeeper.server.ZooKeeperServerMain;
-import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.SmartLifecycle;
-import org.springframework.util.ErrorHandler;
-import org.springframework.util.SocketUtils;
-
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.Properties;
-import java.util.UUID;
-
-/**
- * from: 
https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
- *
- * Helper class to start an embedded instance of standalone (non clustered) 
ZooKeeper.
- *
- * NOTE: at least an external standalone server (if not an ensemble) are 
recommended, even for
- * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
- *
- * @author Patrick Peralta
- * @author Mark Fisher
- * @author David Turanski
- */
-public class EmbeddedZooKeeper implements SmartLifecycle {
-
-    /**
-     * Logger.
-     */
-    private static final Logger logger = 
LoggerFactory.getLogger(EmbeddedZooKeeper.class);
-
-    /**
-     * ZooKeeper client port. This will be determined dynamically upon startup.
-     */
-    private final int clientPort;
-
-    /**
-     * Whether to auto-start. Default is true.
-     */
-    private boolean autoStartup = true;
-
-    /**
-     * Lifecycle phase. Default is 0.
-     */
-    private int phase = 0;
-
-    /**
-     * Thread for running the ZooKeeper server.
-     */
-    private volatile Thread zkServerThread;
-
-    /**
-     * ZooKeeper server.
-     */
-    private volatile ZooKeeperServerMain zkServer;
-
-    /**
-     * {@link ErrorHandler} to be invoked if an Exception is thrown from the 
ZooKeeper server thread.
-     */
-    private ErrorHandler errorHandler;
-
-    private boolean daemon = true;
-
-    /**
-     * Construct an EmbeddedZooKeeper with a random port.
-     */
-    public EmbeddedZooKeeper() {
-        clientPort = SocketUtils.findAvailableTcpPort();
-    }
-
-    /**
-     * Construct an EmbeddedZooKeeper with the provided port.
-     *
-     * @param clientPort  port for ZooKeeper server to bind to
-     */
-    public EmbeddedZooKeeper(int clientPort, boolean daemon) {
-        this.clientPort = clientPort;
-        this.daemon = daemon;
-    }
-
-    /**
-     * Returns the port that clients should use to connect to this embedded 
server.
-     *
-     * @return dynamically determined client port
-     */
-    public int getClientPort() {
-        return this.clientPort;
-    }
-
-    /**
-     * Specify whether to start automatically. Default is true.
-     *
-     * @param autoStartup whether to start automatically
-     */
-    public void setAutoStartup(boolean autoStartup) {
-        this.autoStartup = autoStartup;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isAutoStartup() {
-        return this.autoStartup;
-    }
-
-    /**
-     * Specify the lifecycle phase for the embedded server.
-     *
-     * @param phase the lifecycle phase
-     */
-    public void setPhase(int phase) {
-        this.phase = phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int getPhase() {
-        return this.phase;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean isRunning() {
-        return (zkServerThread != null);
-    }
-
-    /**
-     * Start the ZooKeeper server in a background thread.
-     * <p>
-     * Register an error handler via {@link #setErrorHandler} in order to 
handle
-     * any exceptions thrown during startup or execution.
-     */
-    @Override
-    public synchronized void start() {
-        if (zkServerThread == null) {
-            zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper 
Server Starter");
-            zkServerThread.setDaemon(daemon);
-            zkServerThread.start();
-        }
-    }
-
-    /**
-     * Shutdown the ZooKeeper server.
-     */
-    @Override
-    public synchronized void stop() {
-        if (zkServerThread != null) {
-            // The shutdown method is protected...thus this hack to invoke it.
-            // This will log an exception on shutdown; see
-            // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for 
details.
-            try {
-                Method shutdown = 
ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
-                shutdown.setAccessible(true);
-                shutdown.invoke(zkServer);
-            }
-
-            catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-
-            // It is expected that the thread will exit after
-            // the server is shutdown; this will block until
-            // the shutdown is complete.
-            try {
-                zkServerThread.join(5000);
-                zkServerThread = null;
-            }
-            catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-                logger.warn("Interrupted while waiting for embedded ZooKeeper 
to exit");
-                // abandoning zk thread
-                zkServerThread = null;
-            }
-        }
-    }
-
-    /**
-     * Stop the server if running and invoke the callback when complete.
-     */
-    @Override
-    public void stop(Runnable callback) {
-        stop();
-        callback.run();
-    }
-
-    /**
-     * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown 
from the ZooKeeper server thread. If none
-     * is provided, only error-level logging will occur.
-     *
-     * @param errorHandler the {@link ErrorHandler} to be invoked
-     */
-    public void setErrorHandler(ErrorHandler errorHandler) {
-        this.errorHandler = errorHandler;
-    }
-
-    /**
-     * Runnable implementation that starts the ZooKeeper server.
-     */
-    private class ServerRunnable implements Runnable {
-
-        @Override
-        public void run() {
-            try {
-                Properties properties = new Properties();
-                File file = new File(System.getProperty("java.io.tmpdir")
-                    + File.separator + UUID.randomUUID());
-                file.deleteOnExit();
-                properties.setProperty("dataDir", file.getAbsolutePath());
-                properties.setProperty("clientPort", 
String.valueOf(clientPort));
-
-                QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
-                quorumPeerConfig.parseProperties(properties);
-
-                zkServer = new ZooKeeperServerMain();
-                ServerConfig configuration = new ServerConfig();
-                configuration.readFrom(quorumPeerConfig);
-
-                zkServer.runFromConfig(configuration);
-            }
-            catch (Exception e) {
-                if (errorHandler != null) {
-                    errorHandler.handleError(e);
-                }
-                else {
-                    logger.error("Exception running embedded ZooKeeper", e);
-                }
-            }
-        }
-    }
-
-}
-
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/api/DemoService.java
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/api/DemoService.java
index 45ea059e..eecc5e89 100644
--- 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/api/DemoService.java
+++ 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/api/DemoService.java
@@ -33,19 +33,7 @@
 
 package org.apache.dubbo.samples.metrics.springboot.api;
 
-import org.apache.dubbo.samples.metrics.springboot.model.Result;
-import org.apache.dubbo.samples.metrics.springboot.model.User;
-
-import java.util.concurrent.CompletableFuture;
-
 public interface DemoService {
-    CompletableFuture<Integer> sayHello();
 
     Result sayHello(String name);
-
-    Result sayHello(Long id, String name);
-
-    Result sayHello(User user);
-
-    String stringArray(String[] bytes);
 }
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/model/Result.java
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/api/Result.java
similarity index 97%
rename from 
4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/model/Result.java
rename to 
4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/api/Result.java
index 749f9984..960530a0 100644
--- 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/model/Result.java
+++ 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/api/Result.java
@@ -31,7 +31,7 @@
  * limitations under the License.
  */
 
-package org.apache.dubbo.samples.metrics.springboot.model;
+package org.apache.dubbo.samples.metrics.springboot.api;
 
 import java.io.Serializable;
 
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/MetricsApplication.java
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/consumer/MetricsConsumer.java
similarity index 67%
rename from 
4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/MetricsApplication.java
rename to 
4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/consumer/MetricsConsumer.java
index d99a5245..6ef925a1 100644
--- 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/MetricsApplication.java
+++ 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/consumer/MetricsConsumer.java
@@ -31,41 +31,42 @@
  * limitations under the License.
  */
 
-package org.apache.dubbo.samples.metrics.springboot;
+package org.apache.dubbo.samples.metrics.springboot.consumer;
 
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
 import org.apache.dubbo.samples.metrics.springboot.api.DemoService;
-import org.apache.dubbo.samples.metrics.springboot.model.Result;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.dubbo.samples.metrics.springboot.api.Result;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.ImportResource;
 
 
-@SpringBootApplication(scanBasePackages = { "org.apache.dubbo"})
-@EnableDubbo(scanBasePackages = "org.apache.dubbo")
-@ImportResource("classpath*:spring/dubbo-demo-*.xml")
-public class MetricsApplication implements CommandLineRunner {
+@SpringBootApplication
+@EnableDubbo
+public class MetricsConsumer implements CommandLineRunner {
 
     @DubboReference
     private DemoService demoService;
 
-    public static void main(String[] args) throws Exception {
-        new EmbeddedZooKeeper(2181, false).start();
-        SpringApplication.run(MetricsApplication.class, args);
+    public static void main(String[] args) {
+        System.setProperty("spring.profiles.active", "consumer");
+        SpringApplication.run(MetricsConsumer.class, args);
+        System.out.println("dubbo service started");
     }
+
     @Override
     public void run(String... args) throws Exception {
-        while (true) {
-            try {
-                Thread.sleep(3000);
-                Result hello = demoService.sayHello("world");
-                System.out.println(hello.getMsg());
-            } catch (InterruptedException e) {
-                e.printStackTrace();
+        new Thread(()->{
+            while (true) {
+                try {
+                    Thread.sleep(1000);
+                    Result hello = demoService.sayHello("world");
+                    System.out.println(hello.getMsg());
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
             }
-        }
+        }).start();
     }
 }
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/impl/DemoServiceImpl.java
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/provider/DemoServiceImpl.java
similarity index 66%
rename from 
4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/impl/DemoServiceImpl.java
rename to 
4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/provider/DemoServiceImpl.java
index dff63abe..0c626ffe 100644
--- 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/impl/DemoServiceImpl.java
+++ 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/provider/DemoServiceImpl.java
@@ -31,58 +31,30 @@
  * limitations under the License.
  */
 
-package org.apache.dubbo.samples.metrics.springboot.impl;
+package org.apache.dubbo.samples.metrics.springboot.provider;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
-
-import com.alibaba.dubbo.rpc.RpcContext;
+import org.apache.dubbo.config.annotation.DubboService;
 import org.apache.dubbo.samples.metrics.springboot.api.DemoService;
-import org.apache.dubbo.samples.metrics.springboot.model.Result;
-import org.apache.dubbo.samples.metrics.springboot.model.User;
+import org.apache.dubbo.samples.metrics.springboot.api.Result;
 
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.concurrent.CompletableFuture;
+import com.alibaba.dubbo.rpc.RpcContext;
 
+@DubboService
 public class DemoServiceImpl implements DemoService {
 
     public static final Logger logger = 
LoggerFactory.getLogger(DemoServiceImpl.class);
 
     private String name = "Han MeiMei";
 
-    @Override
-    public CompletableFuture<Integer> sayHello() {
-        return CompletableFuture.completedFuture(2122);
-    }
-
-
-
     @Override
     public Result sayHello(String localName) {
         logger.info("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) 
+ "] Hello " + name + ", request from consumer: " + RpcContext
                 .getContext().getRemoteAddress());
         return new Result(name, "Hello " + localName + ", response from 
provider: " + RpcContext.getContext().getLocalAddress());
     }
-
-    @Override
-    public Result sayHello(final Long id, final String name) {
-        return sayHello(new User(id, name));
-    }
-
-    @Override
-    public Result sayHello(final User user) {
-        String localName = user.getUsername();
-        Long id = user.getId();
-        logger.info("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) 
+ "] Hello " + name + ", request from consumer: " + RpcContext
-                .getContext().getRemoteAddress());
-        return new Result(name, "Hello " + id + " " + localName +
-//                " " + "bytes: " + user.getBytes().toString() +
-                ", response from provider: " + 
RpcContext.getContext().getLocalAddress());
-    }
-
-    @Override
-    public String stringArray(String[] bytes) {
-        return bytes.toString();
-    }
 }
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/model/User.java
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/provider/MetricsProvider.java
similarity index 70%
rename from 
4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/model/User.java
rename to 
4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/provider/MetricsProvider.java
index 0b7de6bd..16389434 100644
--- 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/model/User.java
+++ 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/java/org/apache/dubbo/samples/metrics/springboot/provider/MetricsProvider.java
@@ -31,36 +31,20 @@
  * limitations under the License.
  */
 
-package org.apache.dubbo.samples.metrics.springboot.model;
+package org.apache.dubbo.samples.metrics.springboot.provider;
 
-import java.io.Serializable;
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
 
-public class User implements Serializable {
-    private Long id;
-    private String username;
 
-    public User() {
-    }
-
-    public User(final Long id, final String username) {
-        this.id = id;
-        this.username = username;
-    }
-
-    public Long getId() {
-        return id;
-    }
+@SpringBootApplication
+@EnableDubbo
+public class MetricsProvider {
 
-    public void setId(final Long id) {
-        this.id = id;
+    public static void main(String[] args) {
+        System.setProperty("spring.profiles.active", "provider");
+        SpringApplication.run(MetricsProvider.class, args);
+        System.out.println("dubbo service started");
     }
-
-    public String getUsername() {
-        return username;
-    }
-
-    public void setUsername(final String username) {
-        this.username = username;
-    }
-
 }
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/application-consumer.properties
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/application-consumer.properties
new file mode 100644
index 00000000..48c2990a
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/application-consumer.properties
@@ -0,0 +1,18 @@
+management.metrics.tags.application=dubbo-samples-metrics-spring-boot
+management.server.port=18091
+management.endpoints.web.base-path=/management
+management.endpoints.web.exposure.include=info,health,env,prometheus
+spring.main.allow-circular-references=true
+management.endpoint.metrics.enabled=true
+management.endpoint.prometheus.enabled=true
+management.metrics.export.prometheus.enabled=true
+server.port=18090
+
+dubbo.application.name=metrics-consumer
+dubbo.metrics.protocol=promethus
+dubbo.metrics.port=20899
+dubbo.metrics.enable-jvm-metrics=true
+dubbo.metrics.aggregation.enabled=true
+dubbo.metrics.prometheus-exporter.enabled=true
+dubbo.metrics.prometheus-exporter.metrics-port=20898
+dubbo.registry.address=zookeeper://${zookeeper.address:127.0.0.1}:2181
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/application-provider.properties
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/application-provider.properties
new file mode 100644
index 00000000..2fa2ff90
--- /dev/null
+++ 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/application-provider.properties
@@ -0,0 +1,18 @@
+management.metrics.tags.application=dubbo-samples-metrics-spring-boot
+management.server.port=18081
+management.endpoints.web.base-path=/management
+management.endpoints.web.exposure.include=info,health,env,prometheus
+spring.main.allow-circular-references=true
+management.endpoint.metrics.enabled=true
+management.endpoint.prometheus.enabled=true
+management.metrics.export.prometheus.enabled=true
+server.port=18080
+
+dubbo.application.name=metrics-provider
+dubbo.metrics.protocol=promethus
+dubbo.metrics.port=20889
+dubbo.metrics.enable-jvm-metrics=true
+dubbo.metrics.aggregation.enabled=true
+dubbo.metrics.prometheus-exporter.enabled=true
+dubbo.metrics.prometheus-exporter.metrics-port=20888
+dubbo.registry.address=zookeeper://${zookeeper.address:127.0.0.1}:2181
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/application.properties
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/application.properties
deleted file mode 100644
index 2341861b..00000000
--- 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/application.properties
+++ /dev/null
@@ -1,9 +0,0 @@
-management.metrics.tags.application=dubbo-samples-metrics-spring-boot
-management.server.port=8081
-management.endpoints.web.base-path=/management
-management.endpoints.web.exposure.include=info,health,env,prometheus
-spring.main.allow-circular-references=true
-management.endpoint.metrics.enabled=true
-management.endpoint.prometheus.enabled=true
-management.metrics.export.prometheus.enabled=true
-server.port=8080
\ No newline at end of file
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/spring/dubbo-demo-context.xml
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/spring/dubbo-demo-context.xml
deleted file mode 100644
index 89427129..00000000
--- 
a/4-governance/dubbo-samples-metrics-spring-boot/src/main/resources/spring/dubbo-demo-context.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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.
-  -->
-
-<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";>
-    <context:property-placeholder/>
-
-    <dubbo:application name="metrics-provider"/>
-
-    <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
-    <dubbo:config-center 
address="zookeeper://${zookeeper.address:127.0.0.1}:2181" />
-    <dubbo:metadata-report 
address="zookeeper://${zookeeper.address:127.0.0.1}:2181" />
-
-
-    <dubbo:metrics protocol="prometheus" enable-jvm-metrics="true">
-        <dubbo:aggregation enabled="true"/>
-        <dubbo:prometheus-exporter enabled="false"  metrics-port="20888"/>
-    </dubbo:metrics>
-
-    <bean id="demoService" 
class="org.apache.dubbo.samples.metrics.springboot.impl.DemoServiceImpl"/>
-
-    <dubbo:service 
interface="org.apache.dubbo.samples.metrics.springboot.api.DemoService" 
ref="demoService"/>
-
-<!--    <dubbo:reference id="demoService" check="false" 
interface="org.apache.dubbo.samples.metrics.springboot.api.DemoService"/>-->
-
-</beans>
diff --git 
a/4-governance/dubbo-samples-metrics-spring-boot/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ProviderMetricsIT.java
 
b/4-governance/dubbo-samples-metrics-spring-boot/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ProviderMetricsIT.java
index 1ae3e390..56a5a06e 100644
--- 
a/4-governance/dubbo-samples-metrics-spring-boot/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ProviderMetricsIT.java
+++ 
b/4-governance/dubbo-samples-metrics-spring-boot/src/test/java/org/apache/dubbo/samples/metrics/prometheus/ProviderMetricsIT.java
@@ -17,33 +17,34 @@
 
 package org.apache.dubbo.samples.metrics.prometheus;
 
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.stream.Collectors;
+
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.junit.Assert;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.test.context.junit4.SpringRunner;
 
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.stream.Collectors;
-@RunWith(SpringRunner.class)
-@SpringBootTest(classes = 
{org.apache.dubbo.samples.metrics.springboot.MetricsApplication.class})
 public class ProviderMetricsIT {
 
-    private final String port = "8081";
-
     @Test
     public void test() throws Exception {
         try (CloseableHttpClient client = HttpClients.createDefault()) {
-            HttpGet request = new HttpGet("http://localhost:"; + port + 
"/management/prometheus");
+            HttpGet request = new HttpGet("http://"; + 
System.getProperty("provider", "localhost") + ":18081/management/prometheus");
+            CloseableHttpResponse response = client.execute(request);
+            InputStream inputStream = response.getEntity().getContent();
+            String text = new BufferedReader(new 
InputStreamReader(inputStream, 
StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
+            
Assert.assertTrue(text.contains("jvm_gc_memory_promoted_bytes_total"));
+        } catch (Exception e) {
+            Assert.fail(e.getMessage());
+        }
+        try (CloseableHttpClient client = HttpClients.createDefault()) {
+            HttpGet request = new HttpGet("http://"; + 
System.getProperty("consumer", "localhost") + ":18091/management/prometheus");
             CloseableHttpResponse response = client.execute(request);
             InputStream inputStream = response.getEntity().getContent();
             String text = new BufferedReader(new 
InputStreamReader(inputStream, 
StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to