Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
74c38902
Commit
74c38902
authored
Jan 29, 2019
by
Janoš Guljaš
Committed by
Anton Evangelatov
Jan 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/protocols: fix possible metrics loss in AccountingMetrics (#18956)
parent
a0ac3b6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
reporter.go
p2p/protocols/reporter.go
+15
-0
No files found.
p2p/protocols/reporter.go
View file @
74c38902
...
...
@@ -36,6 +36,13 @@ type AccountingMetrics struct {
//for a graceful cleanup
func
(
am
*
AccountingMetrics
)
Close
()
{
close
(
am
.
reporter
.
quit
)
// wait for reporter loop to finish saving metrics
// before reporter database is closed
select
{
case
<-
time
.
After
(
10
*
time
.
Second
)
:
log
.
Error
(
"accounting metrics reporter timeout"
)
case
<-
am
.
reporter
.
done
:
}
am
.
reporter
.
db
.
Close
()
}
...
...
@@ -46,6 +53,7 @@ type reporter struct {
interval
time
.
Duration
//duration at which the reporter will persist metrics
db
*
leveldb
.
DB
//the actual DB
quit
chan
struct
{}
//quit the reporter loop
done
chan
struct
{}
//signal that reporter loop is done
}
//NewMetricsDB creates a new LevelDB instance used to persist metrics defined
...
...
@@ -92,6 +100,7 @@ func NewAccountingMetrics(r metrics.Registry, d time.Duration, path string) *Acc
interval
:
d
,
db
:
db
,
quit
:
make
(
chan
struct
{}),
done
:
make
(
chan
struct
{}),
}
//run the go routine
...
...
@@ -106,6 +115,9 @@ func NewAccountingMetrics(r metrics.Registry, d time.Duration, path string) *Acc
//run is the goroutine which periodically sends the metrics to the configured LevelDB
func
(
r
*
reporter
)
run
()
{
// signal that the reporter loop is done
defer
close
(
r
.
done
)
intervalTicker
:=
time
.
NewTicker
(
r
.
interval
)
for
{
...
...
@@ -121,6 +133,9 @@ func (r *reporter) run() {
}
case
<-
r
.
quit
:
//graceful shutdown
if
err
:=
r
.
save
();
err
!=
nil
{
log
.
Error
(
"unable to send metrics to LevelDB"
,
"err"
,
err
)
}
return
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment