Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
vicotor
mybee
Commits
136d9f2c
Unverified
Commit
136d9f2c
authored
Aug 19, 2021
by
acud
Committed by
GitHub
Aug 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: allow dirty metrics shutdown (#2428)
parent
5912f5bd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
5 deletions
+13
-5
metrics.go
pkg/topology/kademlia/internal/metrics/metrics.go
+8
-3
metrics_test.go
pkg/topology/kademlia/internal/metrics/metrics_test.go
+2
-1
kademlia.go
pkg/topology/kademlia/kademlia.go
+3
-1
No files found.
pkg/topology/kademlia/internal/metrics/metrics.go
View file @
136d9f2c
...
...
@@ -7,6 +7,7 @@
package
metrics
import
(
"context"
"fmt"
"sync"
"time"
...
...
@@ -341,15 +342,19 @@ func (c *Collector) Flush(addresses ...swarm.Address) error {
return
mErr
}
// Finalize logs out all ongoing peer sessions
// and flushes all in-memory metrics counters.
func
(
c
*
Collector
)
Finalize
(
t
time
.
Time
)
error
{
// Finalize tries to logs out all ongoing peer sessions.
func
(
c
*
Collector
)
Finalize
(
ctx
context
.
Context
,
t
time
.
Time
)
error
{
var
(
mErr
error
batch
=
new
(
leveldb
.
Batch
)
)
c
.
counters
.
Range
(
func
(
_
,
val
interface
{})
bool
{
select
{
case
<-
ctx
.
Done
()
:
return
false
default
:
}
cs
:=
val
.
(
*
Counters
)
PeerLogOut
(
t
)(
cs
)
if
err
:=
cs
.
flush
(
c
.
db
,
batch
);
err
!=
nil
{
...
...
pkg/topology/kademlia/internal/metrics/metrics_test.go
View file @
136d9f2c
...
...
@@ -5,6 +5,7 @@
package
metrics_test
import
(
"context"
"testing"
"time"
...
...
@@ -125,7 +126,7 @@ func TestPeerMetricsCollector(t *testing.T) {
// Finalize.
mc
.
Record
(
addr
,
metrics
.
PeerLogIn
(
t1
,
metrics
.
PeerConnectionDirectionInbound
))
if
err
:=
mc
.
Finalize
(
t3
);
err
!=
nil
{
if
err
:=
mc
.
Finalize
(
context
.
Background
(),
t3
);
err
!=
nil
{
t
.
Fatalf
(
"Finalize(%s): unexpected error: %v"
,
t3
,
err
)
}
if
have
,
want
:=
len
(
mc
.
Snapshot
(
t2
,
addr
)),
0
;
have
!=
want
{
...
...
pkg/topology/kademlia/kademlia.go
View file @
136d9f2c
...
...
@@ -1336,9 +1336,11 @@ func (k *Kad) Close() error {
case
<-
time
.
After
(
5
*
time
.
Second
)
:
k
.
logger
.
Warning
(
"kademlia manage loop did not shut down properly"
)
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
defer
cancel
()
k
.
logger
.
Info
(
"kademlia persisting peer metrics"
)
if
err
:=
k
.
collector
.
Finalize
(
time
.
Now
());
err
!=
nil
{
if
err
:=
k
.
collector
.
Finalize
(
ctx
,
time
.
Now
());
err
!=
nil
{
k
.
logger
.
Debugf
(
"kademlia: unable to finalize open sessions: %v"
,
err
)
}
...
...
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