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
6cfba5b1
Unverified
Commit
6cfba5b1
authored
May 25, 2023
by
mergify[bot]
Committed by
GitHub
May 25, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into op-chain-ops/fix-strict-size-check
parents
d2ef676d
e19925c9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
10 deletions
+55
-10
backend.go
proxyd/backend.go
+9
-0
metrics.go
proxyd/metrics.go
+46
-10
No files found.
proxyd/backend.go
View file @
6cfba5b1
...
...
@@ -374,6 +374,7 @@ func (b *Backend) ForwardRPC(ctx context.Context, res *RPCRes, id string, method
func
(
b
*
Backend
)
doForward
(
ctx
context
.
Context
,
rpcReqs
[]
*
RPCReq
,
isBatch
bool
)
([]
*
RPCRes
,
error
)
{
// we are concerned about network error rates, so we record 1 request independently of how many are in the batch
b
.
networkRequestsSlidingWindow
.
Incr
()
RecordBackendNetworkRequestCountSlidingWindow
(
b
,
b
.
networkRequestsSlidingWindow
.
Count
())
isSingleElementBatch
:=
len
(
rpcReqs
)
==
1
...
...
@@ -390,6 +391,7 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool
httpReq
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
"POST"
,
b
.
rpcURL
,
bytes
.
NewReader
(
body
))
if
err
!=
nil
{
b
.
networkErrorsSlidingWindow
.
Incr
()
RecordBackendNetworkErrorCountSlidingWindow
(
b
,
b
.
networkErrorsSlidingWindow
.
Count
())
return
nil
,
wrapErr
(
err
,
"error creating backend request"
)
}
...
...
@@ -411,6 +413,7 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool
httpRes
,
err
:=
b
.
client
.
DoLimited
(
httpReq
)
if
err
!=
nil
{
b
.
networkErrorsSlidingWindow
.
Incr
()
RecordBackendNetworkErrorCountSlidingWindow
(
b
,
b
.
networkErrorsSlidingWindow
.
Count
())
return
nil
,
wrapErr
(
err
,
"error in backend request"
)
}
...
...
@@ -429,6 +432,7 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool
// Alchemy returns a 400 on bad JSONs, so handle that case
if
httpRes
.
StatusCode
!=
200
&&
httpRes
.
StatusCode
!=
400
{
b
.
networkErrorsSlidingWindow
.
Incr
()
RecordBackendNetworkErrorCountSlidingWindow
(
b
,
b
.
networkErrorsSlidingWindow
.
Count
())
return
nil
,
fmt
.
Errorf
(
"response code %d"
,
httpRes
.
StatusCode
)
}
...
...
@@ -436,6 +440,7 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool
resB
,
err
:=
io
.
ReadAll
(
io
.
LimitReader
(
httpRes
.
Body
,
b
.
maxResponseSize
))
if
err
!=
nil
{
b
.
networkErrorsSlidingWindow
.
Incr
()
RecordBackendNetworkErrorCountSlidingWindow
(
b
,
b
.
networkErrorsSlidingWindow
.
Count
())
return
nil
,
wrapErr
(
err
,
"error reading response body"
)
}
...
...
@@ -453,15 +458,18 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool
// Infura may return a single JSON-RPC response if, for example, the batch contains a request for an unsupported method
if
responseIsNotBatched
(
resB
)
{
b
.
networkErrorsSlidingWindow
.
Incr
()
RecordBackendNetworkErrorCountSlidingWindow
(
b
,
b
.
networkErrorsSlidingWindow
.
Count
())
return
nil
,
ErrBackendUnexpectedJSONRPC
}
b
.
networkErrorsSlidingWindow
.
Incr
()
RecordBackendNetworkErrorCountSlidingWindow
(
b
,
b
.
networkErrorsSlidingWindow
.
Count
())
return
nil
,
ErrBackendBadResponse
}
}
if
len
(
rpcReqs
)
!=
len
(
res
)
{
b
.
networkErrorsSlidingWindow
.
Incr
()
RecordBackendNetworkErrorCountSlidingWindow
(
b
,
b
.
networkErrorsSlidingWindow
.
Count
())
return
nil
,
ErrBackendUnexpectedJSONRPC
}
...
...
@@ -474,6 +482,7 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool
}
duration
:=
time
.
Since
(
start
)
b
.
latencySlidingWindow
.
Add
(
float64
(
duration
))
RecordBackendNetworkLatencyAverageSlidingWindow
(
b
,
b
.
latencySlidingWindow
.
Avg
())
sortBatchRPCResponse
(
rpcReqs
,
res
)
return
res
,
nil
...
...
proxyd/metrics.go
View file @
6cfba5b1
...
...
@@ -309,6 +309,30 @@ var (
},
[]
string
{
"backend_name"
,
})
avgLatencyBackend
=
promauto
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"backend_avg_latency"
,
Help
:
"Average latency per backend"
,
},
[]
string
{
"backend_name"
,
})
networkErrorCountBackend
=
promauto
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"backend_net_error_count"
,
Help
:
"Network error count per backend"
,
},
[]
string
{
"backend_name"
,
})
requestCountBackend
=
promauto
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"backend_request_count"
,
Help
:
"Request count per backend"
,
},
[]
string
{
"backend_name"
,
})
)
func
RecordRedisError
(
source
string
)
{
...
...
@@ -390,30 +414,42 @@ func RecordGroupTotalCount(group *BackendGroup, count int) {
consensusGroupTotalCount
.
WithLabelValues
(
group
.
Name
)
.
Set
(
float64
(
count
))
}
func
RecordBackendLatestBlock
(
b
e
*
Backend
,
blockNumber
hexutil
.
Uint64
)
{
backendLatestBlockBackend
.
WithLabelValues
(
b
e
.
Name
)
.
Set
(
float64
(
blockNumber
))
func
RecordBackendLatestBlock
(
b
*
Backend
,
blockNumber
hexutil
.
Uint64
)
{
backendLatestBlockBackend
.
WithLabelValues
(
b
.
Name
)
.
Set
(
float64
(
blockNumber
))
}
func
RecordConsensusBackendBanned
(
b
e
*
Backend
,
banned
bool
)
{
func
RecordConsensusBackendBanned
(
b
*
Backend
,
banned
bool
)
{
v
:=
float64
(
0
)
if
banned
{
v
=
float64
(
1
)
}
consensusBannedBackends
.
WithLabelValues
(
b
e
.
Name
)
.
Set
(
v
)
consensusBannedBackends
.
WithLabelValues
(
b
.
Name
)
.
Set
(
v
)
}
func
RecordConsensusBackendPeerCount
(
b
e
*
Backend
,
peerCount
uint64
)
{
consensusPeerCountBackend
.
WithLabelValues
(
b
e
.
Name
)
.
Set
(
float64
(
peerCount
))
func
RecordConsensusBackendPeerCount
(
b
*
Backend
,
peerCount
uint64
)
{
consensusPeerCountBackend
.
WithLabelValues
(
b
.
Name
)
.
Set
(
float64
(
peerCount
))
}
func
RecordConsensusBackendInSync
(
b
e
*
Backend
,
inSync
bool
)
{
func
RecordConsensusBackendInSync
(
b
*
Backend
,
inSync
bool
)
{
v
:=
float64
(
0
)
if
inSync
{
v
=
float64
(
1
)
}
consensusInSyncBackend
.
WithLabelValues
(
be
.
Name
)
.
Set
(
v
)
consensusInSyncBackend
.
WithLabelValues
(
b
.
Name
)
.
Set
(
v
)
}
func
RecordConsensusBackendUpdateDelay
(
b
*
Backend
,
delay
time
.
Duration
)
{
consensusUpdateDelayBackend
.
WithLabelValues
(
b
.
Name
)
.
Set
(
float64
(
delay
.
Milliseconds
()))
}
func
RecordBackendNetworkLatencyAverageSlidingWindow
(
b
*
Backend
,
avgLatency
float64
)
{
avgLatencyBackend
.
WithLabelValues
(
b
.
Name
)
.
Set
(
avgLatency
)
}
func
RecordBackendNetworkRequestCountSlidingWindow
(
b
*
Backend
,
count
uint
)
{
requestCountBackend
.
WithLabelValues
(
b
.
Name
)
.
Set
(
float64
(
count
))
}
func
Record
ConsensusBackendUpdateDelay
(
be
*
Backend
,
delay
time
.
Duration
)
{
consensusUpdateDelayBackend
.
WithLabelValues
(
be
.
Name
)
.
Set
(
float64
(
delay
.
Milliseconds
()
))
func
Record
BackendNetworkErrorCountSlidingWindow
(
b
*
Backend
,
count
uint
)
{
networkErrorCountBackend
.
WithLabelValues
(
b
.
Name
)
.
Set
(
float64
(
count
))
}
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