Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
substrate
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ddorgan
substrate
Commits
142deea9
Commit
142deea9
authored
6 years ago
by
Gav
Browse files
Options
Downloads
Patches
Plain Diff
Ping in telemetry
parent
e29c87de
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/telemetry/src/lib.rs
+12
-21
12 additions, 21 deletions
substrate/telemetry/src/lib.rs
with
12 additions
and
21 deletions
substrate/telemetry/src/lib.rs
+
12
−
21
View file @
142deea9
...
...
@@ -80,34 +80,25 @@ struct TelemetryWriter {
last_time
:
Option
<
time
::
Instant
>
,
}
/// Every two minutes we reconnect to the telemetry server otherwise we don't get notified
/// of a flakey connection that has been dropped and needs to be reconnected. We can remove
/// this once we introduce a keepalive ping/pong.
const
RECONNECT_PERIOD
:
u64
=
120
;
const
PING_PERIOD
:
u64
=
20
;
impl
TelemetryWriter
{
fn
ensure_connected
(
&
mut
self
)
{
let
mut
client
=
self
.out
.lock
();
let
controlled_disconnect
=
if
let
Some
(
t
)
=
self
.last_time
{
if
t
.elapsed
()
.as_secs
()
>
RECONNECT_PERIOD
&&
client
.is_some
()
{
trace!
(
target
:
"telemetry"
,
"Performing controlled drop of the telemetry connection."
);
let
_
=
client
.as_mut
()
.and_then
(|
socket
|
socket
.send_message
(
&
ws
::
Message
::
text
(
"{
\"
msg
\"
:
\"
system.reconnect
\"
}"
))
.ok
()
);
*
client
=
None
;
true
}
else
{
false
if
let
Some
(
t
)
=
self
.last_time
{
if
t
.elapsed
()
.as_secs
()
>
PING_PERIOD
{
trace!
(
target
:
"telemetry"
,
"Pinging..."
);
if
client
.as_mut
()
.and_then
(|
socket
|
socket
.send_message
(
&
ws
::
Message
::
ping
(
vec!
[]))
.ok
()
)
.is_none
()
{
*
client
=
None
;
}
}
}
else
{
false
};
}
let
just_connected
=
if
client
.is_none
()
{
if
!
controlled_disconnect
{
info!
(
target
:
"telemetry"
,
"Connection dropped unexpectedly. Reconnecting to telemetry server..."
);
}
info!
(
target
:
"telemetry"
,
"Connection dropped unexpectedly. Reconnecting to telemetry server..."
);
*
client
=
ws
::
ClientBuilder
::
new
(
&
self
.config.url
)
.ok
()
.and_then
(|
mut
x
|
x
.connect
(
None
)
.ok
());
client
.is_some
()
}
else
{
...
...
@@ -115,7 +106,7 @@ impl TelemetryWriter {
};
drop
(
client
);
if
just_connected
&&
!
controlled_disconnect
{
if
just_connected
{
self
.last_time
=
Some
(
time
::
Instant
::
now
());
info!
(
"Reconnected to telemetry server: {}"
,
self
.config.url
);
(
self
.config.on_connect
)();
...
...
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