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
025a3c0d
Commit
025a3c0d
authored
Jan 09, 2022
by
inphi
Committed by
Murphy Law
Jan 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/proxy: Add request/response RPC metrics
parent
89eab8f7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
4 deletions
+66
-4
chilled-mayflies-push.md
.changeset/chilled-mayflies-push.md
+5
-0
metrics.go
go/proxyd/metrics.go
+32
-2
server.go
go/proxyd/server.go
+29
-2
No files found.
.changeset/chilled-mayflies-push.md
0 → 100644
View file @
025a3c0d
---
'
@eth-optimism/proxyd'
:
minor
---
Add request/response payload size metrics to proxyd
go/proxyd/metrics.go
View file @
025a3c0d
...
...
@@ -2,10 +2,11 @@ package proxyd
import
(
"context"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"strconv"
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const
(
...
...
@@ -20,6 +21,8 @@ const (
MethodUnknown
=
"unknown"
)
var
PayloadSizeBuckets
=
[]
float64
{
10
,
50
,
100
,
500
,
1000
,
5000
,
10000
,
100000
,
1000000
}
var
(
rpcRequestsTotal
=
promauto
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
MetricsNamespace
,
...
...
@@ -139,6 +142,25 @@ var (
"source"
,
})
requestPayloadSizesGauge
=
promauto
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"request_payload_sizes"
,
Help
:
"Gauge of client request payload sizes."
,
Buckets
:
PayloadSizeBuckets
,
},
[]
string
{
"auth"
,
"method_name"
,
})
responsePayloadSizesGauge
=
promauto
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"response_payload_sizes"
,
Help
:
"Gauge of client response payload sizes."
,
Buckets
:
PayloadSizeBuckets
,
},
[]
string
{
"auth"
,
})
rpcSpecialErrors
=
[]
string
{
"nonce too low"
,
"gas price too high"
,
...
...
@@ -185,3 +207,11 @@ func MaybeRecordSpecialRPCError(ctx context.Context, backendName, method string,
}
}
}
func
RecordRequestPayloadSize
(
ctx
context
.
Context
,
method
string
,
payloadSize
int
)
{
requestPayloadSizesGauge
.
WithLabelValues
(
GetAuthCtx
(
ctx
),
method
)
.
Observe
(
float64
(
payloadSize
))
}
func
RecordResponsePayloadSize
(
ctx
context
.
Context
,
payloadSize
int
)
{
responsePayloadSizesGauge
.
WithLabelValues
(
GetAuthCtx
(
ctx
))
.
Observe
(
float64
(
payloadSize
))
}
go/proxyd/server.go
View file @
025a3c0d
...
...
@@ -116,13 +116,15 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
"user_agent"
,
r
.
Header
.
Get
(
"user-agent"
),
)
req
,
err
:=
ParseRPCReq
(
io
.
LimitReader
(
r
.
Body
,
s
.
maxBodySize
))
bodyReader
:=
&
recordLenReader
{
Reader
:
io
.
LimitReader
(
r
.
Body
,
s
.
maxBodySize
)}
req
,
err
:=
ParseRPCReq
(
bodyReader
)
if
err
!=
nil
{
log
.
Info
(
"rejected request with bad rpc request"
,
"source"
,
"rpc"
,
"err"
,
err
)
RecordRPCError
(
ctx
,
BackendProxyd
,
MethodUnknown
,
err
)
writeRPCError
(
ctx
,
w
,
nil
,
err
)
return
}
RecordRequestPayloadSize
(
ctx
,
req
.
Method
,
bodyReader
.
Len
)
group
:=
s
.
rpcMethodMappings
[
req
.
Method
]
if
group
==
""
{
...
...
@@ -249,14 +251,17 @@ func writeRPCRes(ctx context.Context, w http.ResponseWriter, res *RPCRes) {
if
res
.
IsError
()
&&
res
.
Error
.
HTTPErrorCode
!=
0
{
statusCode
=
res
.
Error
.
HTTPErrorCode
}
w
.
WriteHeader
(
statusCode
)
enc
:=
json
.
NewEncoder
(
w
)
ww
:=
&
recordLenWriter
{
Writer
:
w
}
enc
:=
json
.
NewEncoder
(
ww
)
if
err
:=
enc
.
Encode
(
res
);
err
!=
nil
{
log
.
Error
(
"error writing rpc response"
,
"err"
,
err
)
RecordRPCError
(
ctx
,
BackendProxyd
,
MethodUnknown
,
err
)
return
}
httpResponseCodesTotal
.
WithLabelValues
(
strconv
.
Itoa
(
statusCode
))
.
Inc
()
RecordResponsePayloadSize
(
ctx
,
ww
.
Len
)
}
func
instrumentedHdlr
(
h
http
.
Handler
)
http
.
HandlerFunc
{
...
...
@@ -291,3 +296,25 @@ func GetXForwardedFor(ctx context.Context) string {
}
return
xff
}
type
recordLenReader
struct
{
io
.
Reader
Len
int
}
func
(
r
*
recordLenReader
)
Read
(
p
[]
byte
)
(
n
int
,
err
error
)
{
n
,
err
=
r
.
Reader
.
Read
(
p
)
r
.
Len
+=
n
return
}
type
recordLenWriter
struct
{
io
.
Writer
Len
int
}
func
(
w
*
recordLenWriter
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
n
,
err
=
w
.
Writer
.
Write
(
p
)
w
.
Len
+=
n
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