Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
262bf065
Commit
262bf065
authored
4 years ago
by
zhangshen023
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/develop' into develop
parents
04d7ac99
ebf3cc64
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
registry/consul/service_discovery.go
+12
-11
12 additions, 11 deletions
registry/consul/service_discovery.go
with
12 additions
and
11 deletions
registry/consul/service_discovery.go
+
12
−
11
View file @
262bf065
...
...
@@ -74,7 +74,6 @@ func newConsulServiceDiscovery(name string) (registry.ServiceDiscovery, error) {
return
&
consulServiceDiscovery
{
address
:
remoteConfig
.
Address
,
descriptor
:
descriptor
,
ttl
:
make
(
map
[
string
]
chan
struct
{}),
},
nil
}
...
...
@@ -90,7 +89,7 @@ type consulServiceDiscovery struct {
tag
string
tags
[]
string
address
string
ttl
map
[
string
]
chan
struct
{}
ttl
sync
.
Map
*
consul
.
Config
}
...
...
@@ -115,10 +114,11 @@ func (csd *consulServiceDiscovery) String() string {
func
(
csd
*
consulServiceDiscovery
)
Destroy
()
error
{
csd
.
consulClient
=
nil
for
_
,
t
:=
range
csd
.
ttl
{
close
(
t
)
}
csd
.
ttl
=
nil
csd
.
ttl
.
Range
(
func
(
key
,
t
interface
{})
bool
{
close
(
t
.
(
chan
struct
{}))
csd
.
ttl
.
Delete
(
key
)
return
true
})
return
nil
}
...
...
@@ -137,7 +137,7 @@ func (csd *consulServiceDiscovery) registerTtl(instance registry.ServiceInstance
checkID
:=
buildID
(
instance
)
stopChan
:=
make
(
chan
struct
{})
csd
.
ttl
[
buildID
(
instance
)
]
=
stopChan
csd
.
ttl
.
LoadOrStore
(
buildID
(
instance
)
,
stopChan
)
period
:=
time
.
Duration
(
csd
.
checkPassInterval
/
8
)
*
time
.
Millisecond
timer
:=
time
.
NewTimer
(
period
)
...
...
@@ -177,13 +177,14 @@ func (csd *consulServiceDiscovery) Unregister(instance registry.ServiceInstance)
logger
.
Errorf
(
"unregister service instance %s,error: %v"
,
instance
.
GetId
(),
err
)
return
err
}
stopChanel
,
ok
:=
csd
.
ttl
[
buildID
(
instance
)]
stopChanel
,
ok
:=
csd
.
ttl
.
Load
(
buildID
(
instance
))
if
!
ok
{
logger
.
Warnf
(
"ttl for service instance %s didn't exist"
,
instance
.
GetId
())
return
nil
}
close
(
stopChanel
)
delete
(
csd
.
ttl
,
buildID
(
instance
))
close
(
stopChanel
.
(
chan
struct
{})
)
csd
.
ttl
.
Delete
(
buildID
(
instance
))
return
nil
}
...
...
@@ -404,7 +405,7 @@ func (csd *consulServiceDiscovery) buildRegisterInstance(instance registry.Servi
func
(
csd
*
consulServiceDiscovery
)
buildCheck
(
instance
registry
.
ServiceInstance
)
consul
.
AgentServiceCheck
{
deregister
,
ok
:=
instance
.
GetMetadata
()[
constant
.
DEREGISTER_AFTER
]
if
!
ok
||
deregister
==
""
{
if
!
ok
||
len
(
deregister
)
==
0
{
deregister
=
constant
.
DEFAULT_DEREGISTER_TIME
}
return
consul
.
AgentServiceCheck
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment