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
a46f5f2d
Unverified
Commit
a46f5f2d
authored
Dec 10, 2021
by
Matthew Slipper
Committed by
GitHub
Dec 10, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1912 from mslipper/bugfix/proxyd-fixes
go/proxyd: Various fixes
parents
a91726d3
4b56ed84
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
31 deletions
+18
-31
clever-ducks-rescue.md
.changeset/clever-ducks-rescue.md
+5
-0
backend.go
go/proxyd/backend.go
+2
-2
config.go
go/proxyd/config.go
+1
-1
metrics.go
go/proxyd/metrics.go
+0
-6
server.go
go/proxyd/server.go
+10
-22
No files found.
.changeset/clever-ducks-rescue.md
0 → 100644
View file @
a46f5f2d
---
'
@eth-optimism/proxyd'
:
minor
---
Various proxyd fixes
go/proxyd/backend.go
View file @
a46f5f2d
...
...
@@ -389,7 +389,7 @@ func (b *BackendGroup) Forward(ctx context.Context, rpcReq *RPCReq) (*RPCRes, er
if
err
!=
nil
{
log
.
Error
(
"error forwarding request to backend"
,
"name"
,
b
.
Name
,
"name"
,
b
ack
.
Name
,
"req_id"
,
GetReqID
(
ctx
),
"auth"
,
GetAuthCtx
(
ctx
),
"err"
,
err
,
...
...
@@ -442,7 +442,7 @@ func (b *BackendGroup) ProxyWS(ctx context.Context, clientConn *websocket.Conn,
func
calcBackoff
(
i
int
)
time
.
Duration
{
jitter
:=
float64
(
rand
.
Int63n
(
250
))
ms
:=
math
.
Min
(
math
.
Pow
(
2
,
float64
(
i
))
*
1000
+
jitter
,
10
000
)
ms
:=
math
.
Min
(
math
.
Pow
(
2
,
float64
(
i
))
*
1000
+
jitter
,
3
000
)
return
time
.
Duration
(
ms
)
*
time
.
Millisecond
}
...
...
go/proxyd/config.go
View file @
a46f5f2d
...
...
@@ -27,7 +27,7 @@ type MetricsConfig struct {
type
BackendOptions
struct
{
ResponseTimeoutSeconds
int
`toml:"response_timeout_seconds"`
MaxResponseSizeBytes
int64
`toml:"max_response_size_bytes"`
MaxRetries
int
`toml:"
backend
_retries"`
MaxRetries
int
`toml:"
max
_retries"`
OutOfServiceSeconds
int
`toml:"out_of_service_seconds"`
}
...
...
go/proxyd/metrics.go
View file @
a46f5f2d
...
...
@@ -106,12 +106,6 @@ var (
"request_source"
,
})
httpRequestsTotal
=
promauto
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"http_requests_total"
,
Help
:
"Count of total HTTP requests."
,
})
httpResponseCodesTotal
=
promauto
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
MetricsNamespace
,
Name
:
"http_response_codes_total"
,
...
...
go/proxyd/server.go
View file @
a46f5f2d
...
...
@@ -117,7 +117,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
if
err
!=
nil
{
log
.
Info
(
"rejected request with bad rpc request"
,
"source"
,
"rpc"
,
"err"
,
err
)
RecordRPCError
(
ctx
,
BackendProxyd
,
MethodUnknown
,
err
)
writeRPCError
(
w
,
nil
,
err
)
writeRPCError
(
ctx
,
w
,
nil
,
err
)
return
}
...
...
@@ -132,7 +132,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
"method"
,
req
.
Method
,
)
RecordRPCError
(
ctx
,
BackendProxyd
,
MethodUnknown
,
ErrMethodNotWhitelisted
)
writeRPCError
(
w
,
req
.
ID
,
ErrMethodNotWhitelisted
)
writeRPCError
(
ctx
,
w
,
req
.
ID
,
ErrMethodNotWhitelisted
)
return
}
...
...
@@ -144,21 +144,11 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
"req_id"
,
GetReqID
(
ctx
),
"err"
,
err
,
)
writeRPCError
(
w
,
req
.
ID
,
err
)
writeRPCError
(
ctx
,
w
,
req
.
ID
,
err
)
return
}
enc
:=
json
.
NewEncoder
(
w
)
if
err
:=
enc
.
Encode
(
backendRes
);
err
!=
nil
{
log
.
Error
(
"error encoding response"
,
"req_id"
,
GetReqID
(
ctx
),
"err"
,
err
,
)
RecordRPCError
(
ctx
,
BackendProxyd
,
req
.
Method
,
err
)
writeRPCError
(
w
,
req
.
ID
,
err
)
return
}
writeRPCRes
(
ctx
,
w
,
backendRes
)
}
func
(
s
*
Server
)
HandleWS
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -232,20 +222,17 @@ func (s *Server) populateContext(w http.ResponseWriter, r *http.Request) context
)
}
func
writeRPCError
(
w
http
.
ResponseWriter
,
id
json
.
RawMessage
,
err
error
)
{
func
writeRPCError
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
id
json
.
RawMessage
,
err
error
)
{
var
res
*
RPCRes
if
r
,
ok
:=
err
.
(
*
RPCErr
);
ok
{
res
=
NewRPCErrorRes
(
id
,
r
)
}
else
{
res
=
NewRPCErrorRes
(
id
,
&
RPCErr
{
Code
:
JSONRPCErrorInternal
,
Message
:
"internal error"
,
})
res
=
NewRPCErrorRes
(
id
,
ErrInternal
)
}
writeRPCRes
(
w
,
res
)
writeRPCRes
(
ctx
,
w
,
res
)
}
func
writeRPCRes
(
w
http
.
ResponseWriter
,
res
*
RPCRes
)
{
func
writeRPCRes
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
res
*
RPCRes
)
{
statusCode
:=
200
if
res
.
IsError
()
&&
res
.
Error
.
HTTPErrorCode
!=
0
{
statusCode
=
res
.
Error
.
HTTPErrorCode
...
...
@@ -254,13 +241,14 @@ func writeRPCRes(w http.ResponseWriter, res *RPCRes) {
enc
:=
json
.
NewEncoder
(
w
)
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
()
}
func
instrumentedHdlr
(
h
http
.
Handler
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
httpRequestsTotal
.
Inc
()
respTimer
:=
prometheus
.
NewTimer
(
httpRequestDurationSumm
)
h
.
ServeHTTP
(
w
,
r
)
respTimer
.
ObserveDuration
()
...
...
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