Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions metrics/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ var (
statusBadRequest = metrics.NewCounter(`http_requests_total{status="400"}`)
statusNotFound = metrics.NewCounter(`http_requests_total{status="404"}`)
statusInternalServerError = metrics.NewCounter(`http_requests_total{status="500"}`)
UrlParamUsage = metrics.NewCounter(`http_requests_params{name="url"}`)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exposed publicly for the test.

)

func StatusOKInc() { statusOK.Inc() }
func StatusBadRequestInc() { statusBadRequest.Inc() }
func StatusNotFoundInc() { statusNotFound.Inc() }
func StatusInternalServerErrorInc() { statusInternalServerError.Inc() }
func UrlParamUsageInc() { UrlParamUsage.Inc() }
1 change: 1 addition & 0 deletions server/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (r *RpcRequestHandler) process() {
// e.g. https://rpc.flashbots.net?url=http://RPC-ENDPOINT.COM
customProxyUrl, ok := r.req.URL.Query()["url"]
if ok && len(customProxyUrl[0]) > 1 {
metrics.UrlParamUsageInc()
r.defaultProxyUrl = customProxyUrl[0]
r.logger.Info("[process] Using custom url", "url", r.defaultProxyUrl)
}
Expand Down
14 changes: 14 additions & 0 deletions server/request_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/flashbots/rpc-endpoint/metrics"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -92,3 +93,16 @@ func TestGetEffectiveParametersHeaderNoPreset(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "fallback-user", params.originId)
}

func TestRpcRequestHandler_UrlParam(t *testing.T) {
wrec := httptest.NewRecorder()
req := httptest.NewRequest("POST", "/?url=http://mock.url", nil)

metrics.UrlParamUsage.Set(0)

var rw http.ResponseWriter = wrec
rh := NewRpcRequestHandler(log.New(), &rw, req, "", 0, nil, "", nil, nil, nil, nil, nil, nil)
rh.process()

require.Equal(t, uint64(1), metrics.UrlParamUsage.Get())
}