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

Refact seri #755

Merged
merged 75 commits into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
ddfad7f
consul service discovery
Aug 4, 2020
e0d492d
consul service discovery
Aug 4, 2020
0520f48
consul service discovery (not test yet)
Aug 6, 2020
34f5d8a
consul ttl check
Aug 7, 2020
5716195
consul service discovery unit test
Aug 7, 2020
d0d1e3d
test panic error
Aug 8, 2020
322fae2
unit test TestConsulServiceDiscovery_Destroy repaired
Aug 8, 2020
47bab04
unit test repaired
Aug 8, 2020
e321256
clean code
Aug 8, 2020
f3c63b5
add log
Aug 9, 2020
2693201
remove hc-log
Aug 9, 2020
0ddcd72
unit test error repaired
Aug 10, 2020
0f839ff
use pointer type *MockEventDispatcher
Aug 11, 2020
5965e74
Merge remote-tracking branch 'origin/develop' into develop
Aug 11, 2020
8040566
optimized code for consul service discovery
Aug 13, 2020
77eb76e
Merge remote-tracking branch 'origin/develop' into develop
Aug 13, 2020
fdc4f7c
optimized
Aug 17, 2020
e238478
optimized
Aug 17, 2020
d5dfaf9
suit consul
Aug 29, 2020
c135d03
Merge remote-tracking branch 'origin/develop' into develop
Aug 29, 2020
4e2ac21
optimize code and adapt to other unit test
Aug 29, 2020
55dfc25
fix bug
Aug 29, 2020
9a644a6
etcdv3 lease
Aug 31, 2020
ce86820
add file service discovery config file
cityiron Aug 31, 2020
5ff6870
delete unused code
Sep 2, 2020
ebf3cc6
concurrency problem fixed
Sep 4, 2020
04d7ac9
Merge remote-tracking branch 'origin/develop' into develop
Sep 5, 2020
262bf06
Merge remote-tracking branch 'origin/develop' into develop
Sep 5, 2020
678f505
file system service discovery perfect
cityiron Sep 6, 2020
112e1a9
TestNewFileSystemServiceDiscoveryAndDestroy add prepareData()
cityiron Sep 6, 2020
eed3a47
Merge branch 'develop' of https://github.com/apache/dubbo-go into dev…
Sep 7, 2020
f3ce3a3
Merge branch 'develop' into feature/file_service_discovery
cityiron Sep 7, 2020
3ecffc7
update config_center file test
cityiron Sep 7, 2020
934ad5c
remove callback add
cityiron Sep 7, 2020
a94ead8
sort import and change dynamic_configuration.go#RemoveConfig comment
cityiron Sep 7, 2020
d210989
revert modifications on this pr,thus submitted this modification on…
Sep 8, 2020
78611fd
fix impl_test mockDataListener use
cityiron Sep 8, 2020
a8782ae
delete the method 'Init' of interface ServiceDiscovery
Sep 8, 2020
b8a20bd
delete unused code
Sep 9, 2020
b3aab08
delete unused code
Sep 9, 2020
fa65371
format else and length
cityiron Sep 9, 2020
2fa6522
optimized some code
Sep 9, 2020
2297303
registry string from constant
cityiron Sep 10, 2020
f818c7e
delete not used map
cityiron Sep 10, 2020
d294b14
Ftr: add sentinel-golang(https://github.com/alibaba/sentinel-golang) …
louyuting Sep 10, 2020
668764a
refine sentinel-go filter
louyuting Sep 11, 2020
6a4eb87
refine imports
louyuting Sep 11, 2020
ec2110c
refine logger
louyuting Sep 11, 2020
77e59d1
fix concurrency problems
Sep 12, 2020
24e8293
use rwlock
Sep 12, 2020
282a8ad
Merge pull request #732 from DogBaoBao/feature/file_service_discovery
AlexStocks Sep 12, 2020
b52639d
ci: Perfect reminder information.
sdttttt Sep 12, 2020
8df776e
ci: Switch to test environment.
sdttttt Sep 12, 2020
f94ba81
fix: Notify message.
sdttttt Sep 12, 2020
494bcd6
Update go.yml
sdttttt Sep 12, 2020
2d896fe
fix: workflow syntax problom.
sdttttt Sep 12, 2020
40bd33f
Update go.yml
sdttttt Sep 12, 2020
1ae651c
Update go.yml
sdttttt Sep 12, 2020
ab5f5c6
Update go.yml
sdttttt Sep 12, 2020
503489e
fix: workflow syntex problom....
sdttttt Sep 12, 2020
f3852ca
ci: Enhance reminder message.
sdttttt Sep 12, 2020
b4a14da
Update go.yml
sdttttt Sep 12, 2020
71d8434
Update go.yml
sdttttt Sep 12, 2020
12dbd7f
ci: Fix syntax and Add comments.
sdttttt Sep 12, 2020
631562b
Update go.yml
sdttttt Sep 13, 2020
bff0898
Update go.yml
sdttttt Sep 13, 2020
7662982
refactor repeated code
Sep 13, 2020
e84a2cf
Merge pull request #753 from sdttttt/sdttttt-patch-1
AlexStocks Sep 13, 2020
57601bc
Merge pull request #748 from louyuting/feature/sentinel-integration
AlexStocks Sep 13, 2020
02b0a82
refactor code
Sep 13, 2020
bc43a00
refactor code
Sep 13, 2020
fc15617
refactor code
Sep 13, 2020
69b77b6
Merge pull request #701 from zhangshen023/develop
AlexStocks Sep 13, 2020
e18e1ab
rename file:O go.yml -> github-actions.yml
AlexStocks Sep 13, 2020
48d746f
feat: resolve go.mod conflict
Sep 13, 2020
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
Prev Previous commit
Next Next commit
consul ttl check
  • Loading branch information
zhangshen023 committed Aug 7, 2020
commit 34f5d8a2d72e06c7a1debb1273c18bdca7bd0aaf
40 changes: 34 additions & 6 deletions registry/consul/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
CHECK_PASS_INTERVAL = "consul-check-pass-interval"
// default time-to-live in millisecond
DEFAULT_CHECK_PASS_INTERVAL = 16000
UERY_TAG = "consul_query_tag"
QUERY_TAG = "consul_query_tag"
ACL_TOKEN = "acl-token"
// default deregister critical server after
DEFAULT_DEREGISTER_TIME = "20s"
Expand Down Expand Up @@ -117,6 +117,7 @@ func newConsulServiceDiscovery(name string) (registry.ServiceDiscovery, error) {
address: remoteConfig.Address,
descriptor: descriptor,
PageSize: pageSize,
ttl: make(map[string]chan struct{}),
}, nil
}

Expand All @@ -135,12 +136,13 @@ type consulServiceDiscovery struct {
tag string
tags []string
address string
ttl map[string]chan struct{}
}

func (csd consulServiceDiscovery) Initialize(registryURL common.URL) error {
func (csd *consulServiceDiscovery) Initialize(registryURL common.URL) error {
csd.serviceUrl = registryURL
csd.checkPassInterval = registryURL.GetParamInt(CHECK_PASS_INTERVAL, DEFAULT_CHECK_PASS_INTERVAL)
csd.tag = registryURL.GetParam(UERY_TAG, "")
csd.tag = registryURL.GetParam(QUERY_TAG, "")
csd.tags = strings.Split(registryURL.GetParam("tags", ""), ",")
aclToken := registryURL.GetParam(ACL_TOKEN, "")
config := &consul.Config{Address: csd.address, Token: aclToken}
Expand All @@ -160,15 +162,42 @@ func (csd consulServiceDiscovery) Destroy() error {
return nil
}

func (csd consulServiceDiscovery) Register(instance registry.ServiceInstance) error {
func (csd *consulServiceDiscovery) Register(instance registry.ServiceInstance) error {
ins, _ := csd.buildRegisterInstance(instance)
err := csd.consulClient.Agent().ServiceRegister(ins)
if err != nil {
return perrors.WithMessage(err, "consul could not register the instance. "+instance.GetServiceName())
}

csd.registerTtl(instance)

return nil

}
func (csd *consulServiceDiscovery) registerTtl(instance registry.ServiceInstance) error {

checkID := buildID(instance)

stopChan := make(chan struct{})
csd.ttl[buildID(instance)] = stopChan

period := time.Duration(csd.checkPassInterval/8) * time.Millisecond
timer := time.NewTimer(period)
go func() {
for {
select {
case <-timer.C:
timer.Reset(period)
csd.consulClient.Agent().PassTTL(checkID, "")
break
case <-stopChan:
logger.Info("ttl %s for service %s is stopped", checkID, instance.GetServiceName())
return
}
}
}()
return nil
}

func (csd consulServiceDiscovery) Update(instance registry.ServiceInstance) error {
ins, err := csd.buildRegisterInstance(instance)
Expand Down Expand Up @@ -205,7 +234,6 @@ func (csd consulServiceDiscovery) GetInstances(serviceName string) []registry.Se
waitTime := csd.serviceUrl.GetParamInt(WATCH_TIMEOUT, DEFAULT_WATCH_TIMEOUT) / 1000
instances, _, err := csd.consulClient.Health().Service(serviceName, csd.tag, true, &consul.QueryOptions{
WaitTime: time.Duration(waitTime),
WaitIndex: -1,
})
if err != nil {
return nil
Expand Down Expand Up @@ -388,7 +416,7 @@ func (csd consulServiceDiscovery) buildCheck(instance registry.ServiceInstance)
func buildID(instance registry.ServiceInstance) string {

metaBytes, _ := json.Marshal(instance.GetMetadata())
id := fmt.Sprintf("id:%s,serviceName:%s,host:%s,port:%d,enable:%b,healthy:%b,meta:%s", instance.GetId(), instance.GetServiceName(),
id := fmt.Sprintf("id:%s,serviceName:%s,host:%s,port:%d,enable:%t,healthy:%t,meta:%s", instance.GetId(), instance.GetServiceName(),
instance.GetHost(), instance.GetPort(), instance.IsEnable(), instance.IsHealthy(), metaBytes)
Md5Inst := md5.New()
Md5Inst.Write([]byte(id))
Expand Down
37 changes: 21 additions & 16 deletions registry/consul/service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package consul

import (
"fmt"
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/remoting/consul"
"math/rand"
"strconv"
"testing"
Expand All @@ -39,8 +41,11 @@ import (
)

var (
testName = "test"
registryURL = common.URL{
testName = "test"
consulCheckPassInterval = 17000
consulDeregisterCriticalServiceAfter = "20s"
consulWatchTimeout = 60000
registryURL = common.URL{
Path: "",
Username: "",
Password: "",
Expand All @@ -65,7 +70,7 @@ func TestConsulServiceDiscovery_newConsulServiceDiscovery(t *testing.T) {
assert.NotNil(t, err)

config.GetBaseConfig().Remotes["mock"] = &config.RemoteConfig{
Address: "", // TODO
Address: "localhost:8081",
}

res, err := newConsulServiceDiscovery(name)
Expand All @@ -86,6 +91,10 @@ func TestConsulServiceDiscovery_Destroy(t *testing.T) {
}

func TestConsulServiceDiscovery_CRUD(t *testing.T) {
// start consul agent
consulAgent := consul.NewConsulAgent(t, registryPort)
defer consulAgent.Shutdown()

prepareData()
extension.SetEventDispatcher("mock", func() observer.EventDispatcher {
return &dispatcher.MockEventDispatcher{}
Expand All @@ -102,9 +111,9 @@ func TestConsulServiceDiscovery_CRUD(t *testing.T) {

err = serviceDiscovery.Initialize(registryUrl)
assert.Nil(t, err)
// clean data for local test

err = serviceDiscovery.Unregister(instance)
assert.Nil(t, err)
assert.NotNil(t, err)

err = serviceDiscovery.Register(instance)
assert.Nil(t, err)
Expand Down Expand Up @@ -158,28 +167,24 @@ func prepareData() {
}

config.GetBaseConfig().Remotes[testName] = &config.RemoteConfig{
Address: "", // TODO
TimeoutStr: "10s",
Address: fmt.Sprintf("%s:%d", registryHost, registryPort),
}
}
func prepareService() (registry.ServiceInstance, common.URL) {
serviceName := "service-name" + strconv.Itoa(rand.Intn(10000))
id := "id"
host := "host"
port := 123

registryUrl, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
registryUrl, _ := common.NewURL(protocol + "://" + providerHost + ":" + strconv.Itoa(providerPort) + "/" + service + "?anyhost=true&" +
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=1556509797245&consul-check-pass-interval=17000&consul-deregister-critical-service-after=20s&" +
"consul-watch-timeout=60000")
"side=provider&timeout=3000&timestamp=1556509797245&consul-check-pass-interval=" + strconv.Itoa(consulCheckPassInterval) + "&consul-deregister-critical-service-after=" + consulDeregisterCriticalServiceAfter + "&" +
"consul-watch-timeout=" + strconv.Itoa(consulWatchTimeout))

return &registry.DefaultServiceInstance{
Id: id,
ServiceName: serviceName,
Host: host,
Port: port,
ServiceName: service,
Host: registryHost,
Port: registryPort,
Enable: true,
Healthy: true,
Metadata: nil,
Expand Down