Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
comms
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xx network
comms
Commits
f27edc05
Commit
f27edc05
authored
Oct 5, 2021
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added ability to ping host and return timestamp
parent
3659069a
No related branches found
No related tags found
2 merge requests
!18
Release
,
!14
Hotfix/ping
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
connect/host.go
+5
-28
5 additions, 28 deletions
connect/host.go
connect/hostParams.go
+4
-0
4 additions, 0 deletions
connect/hostParams.go
with
9 additions
and
28 deletions
connect/host.go
+
5
−
28
View file @
f27edc05
...
...
@@ -217,34 +217,12 @@ func (h *Host) conditionalDisconnect(count uint64) {
}
// Returns whether or not the Host is able to be contacted
// by attempting to dial a tcp connection
func
(
h
*
Host
)
IsOnline
()
bool
{
addr
:=
h
.
GetAddress
()
timeout
:=
5
*
time
.
Second
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
addr
,
timeout
)
if
err
!=
nil
{
// If we cannot connect, mark the connection as failed
jww
.
DEBUG
.
Printf
(
"Failed to verify connectivity for address %s"
,
addr
)
return
false
}
// Attempt to close the connection
if
conn
!=
nil
{
errClose
:=
conn
.
Close
()
if
errClose
!=
nil
{
jww
.
DEBUG
.
Printf
(
"Failed to close connection for address %s"
,
addr
)
}
}
return
true
}
// Returns whether or not the Host is able to be contacted
// within the given timeout by attempting to dial a tcp connection
// and returns how long it took
func
(
h
*
Host
)
IsOnlineVerbose
(
timeout
time
.
Duration
)
(
time
.
Duration
,
bool
)
{
// before the timeout by attempting to dial a tcp connection
// Returns how long the ping took, and whether it was successful
func
(
h
*
Host
)
IsOnline
()
(
time
.
Duration
,
bool
)
{
addr
:=
h
.
GetAddress
()
start
:=
time
.
Now
()
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
addr
,
t
imeout
)
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
addr
,
h
.
params
.
PingT
imeout
)
if
err
!=
nil
{
// If we cannot connect, mark the connection as failed
jww
.
DEBUG
.
Printf
(
"Failed to verify connectivity for address %s"
,
addr
)
...
...
@@ -254,8 +232,7 @@ func (h *Host) IsOnlineVerbose(timeout time.Duration) (time.Duration, bool) {
if
conn
!=
nil
{
errClose
:=
conn
.
Close
()
if
errClose
!=
nil
{
jww
.
DEBUG
.
Printf
(
"Failed to close connection for address %s"
,
addr
)
jww
.
DEBUG
.
Printf
(
"Failed to close connection for address %s"
,
addr
)
}
}
return
time
.
Since
(
start
),
true
...
...
This diff is collapsed.
Click to expand it.
connect/hostParams.go
+
4
−
0
View file @
f27edc05
...
...
@@ -29,6 +29,9 @@ type HostParams struct {
// Message sending timeout
SendTimeout
time
.
Duration
// Online ping timeout
PingTimeout
time
.
Duration
// If set, metric handling will be enabled on this host
EnableMetrics
bool
...
...
@@ -49,6 +52,7 @@ func GetDefaultHostParams() HostParams {
NumSendsBeforeCoolOff
:
3
,
CoolOffTimeout
:
60
*
time
.
Second
,
SendTimeout
:
2
*
time
.
Minute
,
PingTimeout
:
5
*
time
.
Second
,
EnableMetrics
:
false
,
ExcludeMetricErrors
:
make
([]
string
,
0
),
KaClientOpts
:
keepalive
.
ClientParameters
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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