diff --git a/metrics/http.go b/metrics/http.go index 26d0c40..d0e4563 100644 --- a/metrics/http.go +++ b/metrics/http.go @@ -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"}`) ) func StatusOKInc() { statusOK.Inc() } func StatusBadRequestInc() { statusBadRequest.Inc() } func StatusNotFoundInc() { statusNotFound.Inc() } func StatusInternalServerErrorInc() { statusInternalServerError.Inc() } +func UrlParamUsageInc() { UrlParamUsage.Inc() } diff --git a/server/request_handler.go b/server/request_handler.go index 1ebd5ac..2cb994c 100644 --- a/server/request_handler.go +++ b/server/request_handler.go @@ -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) } diff --git a/server/request_handler_test.go b/server/request_handler_test.go index cfdf2e5..d454194 100644 --- a/server/request_handler_test.go +++ b/server/request_handler_test.go @@ -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" ) @@ -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()) +}