Skip to content
Permalink
Browse files
Add healthcheck to provider (#264)
  • Loading branch information
kylixs committed Jan 21, 2021
1 parent 5429dd7 commit f07d7c6c84604f91ad4be9b8cf81b7adf33a1e8e
Show file tree
Hide file tree
Showing 39 changed files with 604 additions and 986 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -27,6 +27,9 @@ services:
- zookeeper.address=zookeeper
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20880
checkLog: "dubbo service started"
depends_on:
- zookeeper

@@ -38,8 +41,12 @@ services:
- zookeeper.address=zookeeper
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20881
checkLog: "dubbo service started"
depends_on:
- zookeeper
- dubbo-samples-chain-backend

dubbo-samples-chain-front:
type: test
@@ -33,6 +33,9 @@ services:
waitPortsBeforeRun:
- zookeeper1:2181
- zookeeper2:2181
checkPorts:
- 20880
checkLog: "dubbo service started"
depends_on:
- zookeeper1
- zookeeper2
@@ -32,6 +32,7 @@ services:
waitTimeout: 100
checkPorts:
- 20880
checkLog: "dubbo service started"
depends_on:
- apollo-db
- apollo-quick-start
@@ -39,6 +39,9 @@ services:
- config-center:2181
- zookeeper1:2181
- zookeeper2:2181
checkPorts:
- 20880
checkLog: "dubbo service started"
depends_on:
- config-center
- zookeeper1
@@ -27,6 +27,9 @@ services:
- consul.port=8500
waitPortsBeforeRun:
- consul:8500
checkPorts:
- 20880
checkLog: "dubbo service started"
depends_on:
- consul

@@ -28,6 +28,9 @@ services:
- dubbo.port=20880
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20880
checkLog: "dubbo service started"
depends_on:
- zookeeper

@@ -41,6 +44,9 @@ services:
- dubbo.port=20881
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20881
checkLog: "dubbo service started"
depends_on:
- zookeeper

@@ -28,7 +28,7 @@ configs:
- addresses: ["0.0.0.0:20880"]
side: provider
parameters:
weight: 1000
weight: 100
- addresses: ["0.0.0.0:20881"]
side: provider
parameters:
@@ -43,7 +43,9 @@ public void test20880() throws Exception {
ZKTools.generateAppLevelOverride(100, 0);
Thread.sleep(5000);
for (int i = 0; i < 10; i++) {
Assert.assertTrue(demoService.sayHello("world").contains("20880"));
String result = demoService.sayHello("world");
System.out.println(result);
Assert.assertTrue(result.contains("20880"));
}
}

@@ -52,7 +54,9 @@ public void test20881() throws Exception {
ZKTools.generateAppLevelOverride(0, 100);
Thread.sleep(5000);
for (int i = 0; i < 10; i++) {
Assert.assertTrue(demoService.sayHello("world").contains("20881"));
String result = demoService.sayHello("world");
System.out.println(result);
Assert.assertTrue(result.contains("20881"));
}
}
}
@@ -28,6 +28,9 @@ services:
- dubbo.port=20880
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20880
checkLog: "dubbo service started"
depends_on:
- zookeeper

@@ -41,6 +44,9 @@ services:
- dubbo.port=20881
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20881
checkLog: "dubbo service started"
depends_on:
- zookeeper

@@ -28,6 +28,9 @@ services:
- dubbo.port=20880
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20880
checkLog: "dubbo service started"
depends_on:
- zookeeper

@@ -41,6 +44,9 @@ services:
- dubbo.port=20881
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20881
checkLog: "dubbo service started"
depends_on:
- zookeeper

@@ -27,6 +27,9 @@ services:
- zookeeper.address=zookeeper
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20880
checkLog: "dubbo service started"
depends_on:
- zookeeper

@@ -38,6 +41,9 @@ services:
- zookeeper.address=zookeeper
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20881
checkLog: "dubbo service started"
depends_on:
- zookeeper

@@ -14,10 +14,46 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from: app-external-zookeeper.yml
services:
zookeeper:
image: zookeeper:latest

props:
project_name: dubbo-samples-monitor
main_class: org.apache.dubbo.samples.monitor.BasicProvider
dubbo_port: 20880
dubbo-provider:
type: app
basedir: .
mainClass: org.apache.dubbo.samples.monitor.BasicProvider
systemProps:
- zookeeper.address=zookeeper
- zookeeper.port=2181
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20880
checkLog: "dubbo service started"

dubbo-monitor:
type: app
basedir: .
mainClass: org.apache.dubbo.samples.monitor.BasicMonitor
systemProps:
- zookeeper.address=zookeeper
- zookeeper.port=2181
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20881
checkLog: "dubbo service started"

monitor-test:
type: test
basedir: .
tests:
- "**/*IT.class"
systemProps:
- zookeeper.address=zookeeper
- zookeeper.port=2181
waitPortsBeforeRun:
- zookeeper:2181
depends_on:
- dubbo-provider
- dubbo-monitor
@@ -29,7 +29,7 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
<dubbo.version>2.7.7</dubbo.version>
<dubbo.version>2.7.8</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
@@ -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.samples.monitor;

import org.apache.dubbo.samples.monitor.api.DemoService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.CountDownLatch;

public class BasicMonitor {

public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-monitor.xml");
context.start();

System.out.println("dubbo service started");
new CountDownLatch(1).await();
}
}
@@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.dubbo.samples.monitor;
package org.apache.dubbo.samples.monitor.impl;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.monitor.MonitorService;
@@ -0,0 +1,35 @@
<?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="demo-monitor"/>

<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>

<dubbo:protocol name="dubbo" port="20881"/>

<dubbo:service interface="org.apache.dubbo.monitor.MonitorService" ref="monitorService" filter="-monitor"/>

<bean id="monitorService" class="org.apache.dubbo.samples.monitor.impl.MonitorServiceImpl" />
</beans>
@@ -46,31 +46,18 @@ public class MonitorServiceIT {
@Autowired
private DemoService demoService;

@Before
public void setUp() throws Exception {
ServiceConfig<MonitorService> service = new ServiceConfig<>();
// FIXME: has to set application name to "demo-consumer"
service.setApplication(new ApplicationConfig("demo-consumer"));
service.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
// MonitorConfig monitorConfig = new MonitorConfig();
// monitorConfig.setProtocol("registry");
// monitorConfig.setInterval("100");
// service.setMonitor(monitorConfig);
service.setInterface(MonitorService.class);
service.setFilter("-monitor");
service.setRef(new MonitorServiceImpl());
service.export();
}

@Test
public void test() throws Exception {
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 5; i++) {
demoService.sayHello("world");
Thread.sleep(50);
Thread.sleep(500);
}

//wait for monitor data post
Thread.sleep(1000);

ReferenceConfig<MonitorService> reference = new ReferenceConfig<>();
reference.setApplication(new ApplicationConfig("demo-consumer"));
reference.setApplication(new ApplicationConfig("demo-monitor"));
reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
reference.setInterface(MonitorService.class);
reference.setFilter("-monitor");
@@ -79,6 +66,7 @@ public void test() throws Exception {

boolean countProvider = false;
boolean countConsumer = false;
System.out.println("monitor stats: "+stats.size());
for (URL stat : stats) {
Assert.assertEquals("count", stat.getProtocol());
Assert.assertEquals("org.apache.dubbo.samples.monitor.api.DemoService/sayHello", stat.getPath());
@@ -29,7 +29,7 @@

<dubbo:protocol name="dubbo" port="20880"/>

<bean id="monitorService" class="org.apache.dubbo.samples.monitor.MonitorServiceImpl"/>
<bean id="monitorService" class="org.apache.dubbo.samples.monitor.impl.MonitorServiceImpl"/>

<dubbo:service interface="org.apache.dubbo.monitor.MonitorService" ref="monitorService"/>
</beans>
@@ -19,6 +19,9 @@ services:
type: app
basedir: .
mainClass: org.apache.dubbo.samples.multi.registry.MultiRegistryProvider
checkPorts:
- 20880
checkLog: "dubbo service started"

dubbo-samples-multi-registry-test:
type: test

0 comments on commit f07d7c6

Please sign in to comment.