Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
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
exchain
nebula
Commits
06c196d6
Commit
06c196d6
authored
Aug 21, 2023
by
Arman Mazdaee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-heartbeat: Update golang-lru to v2
parent
3658b171
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
5 deletions
+4
-5
metrics.go
op-heartbeat/metrics.go
+4
-5
No files found.
op-heartbeat/metrics.go
View file @
06c196d6
...
@@ -6,7 +6,7 @@ import (
...
@@ -6,7 +6,7 @@ import (
"sync/atomic"
"sync/atomic"
"time"
"time"
lru
"github.com/hashicorp/golang-lru"
lru
"github.com/hashicorp/golang-lru
/v2
"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promauto"
...
@@ -31,7 +31,7 @@ type metrics struct {
...
@@ -31,7 +31,7 @@ type metrics struct {
// Groups heartbeats per unique IP, version and chain ID combination.
// Groups heartbeats per unique IP, version and chain ID combination.
// string(IP ++ version ++ chainID) -> *heartbeatEntry
// string(IP ++ version ++ chainID) -> *heartbeatEntry
heartbeatUsers
*
lru
.
Cache
heartbeatUsers
*
lru
.
Cache
[
string
,
*
heartbeatEntry
]
}
}
type
heartbeatEntry
struct
{
type
heartbeatEntry
struct
{
...
@@ -42,7 +42,7 @@ type heartbeatEntry struct {
...
@@ -42,7 +42,7 @@ type heartbeatEntry struct {
}
}
func
NewMetrics
(
r
*
prometheus
.
Registry
)
Metrics
{
func
NewMetrics
(
r
*
prometheus
.
Registry
)
Metrics
{
lruCache
,
_
:=
lru
.
New
(
UsersCacheSize
)
lruCache
,
_
:=
lru
.
New
[
string
,
*
heartbeatEntry
]
(
UsersCacheSize
)
m
:=
&
metrics
{
m
:=
&
metrics
{
heartbeats
:
promauto
.
With
(
r
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
heartbeats
:
promauto
.
With
(
r
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
MetricsNamespace
,
Namespace
:
MetricsNamespace
,
...
@@ -89,7 +89,7 @@ func (m *metrics) RecordHeartbeat(payload heartbeat.Payload, ip string) {
...
@@ -89,7 +89,7 @@ func (m *metrics) RecordHeartbeat(payload heartbeat.Payload, ip string) {
key
:=
fmt
.
Sprintf
(
"%s;%s;%s"
,
ip
,
version
,
chainID
)
key
:=
fmt
.
Sprintf
(
"%s;%s;%s"
,
ip
,
version
,
chainID
)
now
:=
time
.
Now
()
now
:=
time
.
Now
()
previous
,
ok
,
_
:=
m
.
heartbeatUsers
.
PeekOrAdd
(
key
,
&
heartbeatEntry
{
Time
:
now
,
Count
:
1
})
entry
,
ok
,
_
:=
m
.
heartbeatUsers
.
PeekOrAdd
(
key
,
&
heartbeatEntry
{
Time
:
now
,
Count
:
1
})
if
!
ok
{
if
!
ok
{
// if it's a new entry, observe it and exit.
// if it's a new entry, observe it and exit.
m
.
sameIP
.
WithLabelValues
(
chainID
,
version
)
.
Observe
(
1
)
m
.
sameIP
.
WithLabelValues
(
chainID
,
version
)
.
Observe
(
1
)
...
@@ -97,7 +97,6 @@ func (m *metrics) RecordHeartbeat(payload heartbeat.Payload, ip string) {
...
@@ -97,7 +97,6 @@ func (m *metrics) RecordHeartbeat(payload heartbeat.Payload, ip string) {
return
return
}
}
entry
:=
previous
.
(
*
heartbeatEntry
)
if
now
.
Sub
(
entry
.
Time
)
<
MinHeartbeatInterval
{
if
now
.
Sub
(
entry
.
Time
)
<
MinHeartbeatInterval
{
// if the span is still going, then add it up
// if the span is still going, then add it up
atomic
.
AddUint64
(
&
entry
.
Count
,
1
)
atomic
.
AddUint64
(
&
entry
.
Count
,
1
)
...
...
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