Skip to content

Commit 44aadd1

Browse files
authored
Add more metrics (#35)
## πŸ“ Summary <!--- A general summary of your changes --> ## β›± Motivation and Context <!--- Why is this change required? What problem does it solve? --> ## πŸ“š References <!-- Any interesting external links to documentation, articles, tweets which add value to the PR --> --- ## βœ… I have run these commands * [ ] `make lint` * [ ] `make test` * [ ] `go mod tidy`
1 parent 8b4c721 commit 44aadd1

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

β€Žgo.modβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/VictoriaMetrics/metrics v1.35.1
99
github.com/cenkalti/backoff v2.2.1+incompatible
1010
github.com/ethereum/go-ethereum v1.15.5
11-
github.com/flashbots/go-utils v0.10.0
11+
github.com/flashbots/go-utils v0.10.1-0.20250416132112-39233b64a8c5
1212
github.com/google/uuid v1.6.0
1313
github.com/hashicorp/golang-lru/v2 v2.0.7
1414
github.com/stretchr/testify v1.10.0

β€Žgo.sumβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cn
3434
github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
3535
github.com/flashbots/go-utils v0.10.0 h1:75XWewRO5GIhdLn8+vqdzzuoqJh+j8wN54A++Id7W0Y=
3636
github.com/flashbots/go-utils v0.10.0/go.mod h1:i4xxEB6sHDFfNWEIfh+rP6nx3LxynEn8AOZa05EYgwA=
37+
github.com/flashbots/go-utils v0.10.1-0.20250416132112-39233b64a8c5 h1:oEfjmk2NQ/FtX+1h1Rx4PMpJtbNAa6T/l6otbUmzZp8=
38+
github.com/flashbots/go-utils v0.10.1-0.20250416132112-39233b64a8c5/go.mod h1:i4xxEB6sHDFfNWEIfh+rP6nx3LxynEn8AOZa05EYgwA=
3739
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
3840
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
3941
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=

β€Žproxy/metrics.goβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package proxy
22

33
import (
44
"fmt"
5+
"time"
56

67
"github.com/VictoriaMetrics/metrics"
78
)
@@ -28,6 +29,8 @@ const (
2829
shareQueuePeerStallingErrorsLabel = `orderflow_proxy_share_queue_peer_stalling_errors{peer="%s"}`
2930
shareQueuePeerRPCErrorsLabel = `orderflow_proxy_share_queue_peer_rpc_errors{peer="%s"}`
3031
shareQueuePeerRPCDurationLabel = `orderflow_proxy_share_queue_peer_rpc_duration_milliseconds{peer="%s"}`
32+
33+
requestDurationLabel = `orderflow_proxy_api_request_processing_duration_milliseconds{method="%s",server_name="%s",step="%s"}`
3134
)
3235

3336
func incAPIIncomingRequestsByPeer(peer string) {
@@ -58,3 +61,9 @@ func timeShareQueuePeerRPCDuration(peer string, duration int64) {
5861
l := fmt.Sprintf(shareQueuePeerRPCDurationLabel, peer)
5962
metrics.GetOrCreateSummary(l).Update(float64(duration))
6063
}
64+
65+
func incRequestDurationStep(duration time.Duration, method, serverName, step string) {
66+
millis := float64(duration.Microseconds()) / 1000.0
67+
l := fmt.Sprintf(requestDurationLabel, method, serverName, step)
68+
metrics.GetOrCreateSummary(l).Update(millis)
69+
}

β€Žproxy/receiver_api.goβ€Ž

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (prx *ReceiverProxy) ValidateSigner(ctx context.Context, req *ParsedRequest
120120
}
121121

122122
func (prx *ReceiverProxy) EthSendBundle(ctx context.Context, ethSendBundle rpctypes.EthSendBundleArgs, systemEndpoint bool) error {
123+
startAt := time.Now()
123124
parsedRequest := ParsedRequest{
124125
systemEndpoint: systemEndpoint,
125126
ethSendBundle: &ethSendBundle,
@@ -141,6 +142,9 @@ func (prx *ReceiverProxy) EthSendBundle(ctx context.Context, ethSendBundle rpcty
141142
return err
142143
}
143144

145+
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "validation")
146+
startAt = time.Now()
147+
144148
// For direct orderflow we extract signing address from header
145149
// We also default to v2 bundle version if it's not set
146150
if !systemEndpoint {
@@ -169,6 +173,8 @@ func (prx *ReceiverProxy) EthSendBundle(ctx context.Context, ethSendBundle rpcty
169173
uniqueKey := ethSendBundle.UniqueKey()
170174
parsedRequest.requestArgUniqueKey = &uniqueKey
171175

176+
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "add_fields")
177+
172178
return prx.HandleParsedRequest(ctx, parsedRequest)
173179
}
174180

@@ -181,6 +187,7 @@ func (prx *ReceiverProxy) EthSendBundleUser(ctx context.Context, ethSendBundle r
181187
}
182188

183189
func (prx *ReceiverProxy) MevSendBundle(ctx context.Context, mevSendBundle rpctypes.MevSendBundleArgs, systemEndpoint bool) error {
190+
startAt := time.Now()
184191
parsedRequest := ParsedRequest{
185192
systemEndpoint: systemEndpoint,
186193
mevSendBundle: &mevSendBundle,
@@ -197,6 +204,9 @@ func (prx *ReceiverProxy) MevSendBundle(ctx context.Context, mevSendBundle rpcty
197204
return err
198205
}
199206

207+
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "validation")
208+
startAt = time.Now()
209+
200210
if !systemEndpoint {
201211
mevSendBundle.Metadata = &rpctypes.MevBundleMetadata{
202212
Signer: &parsedRequest.signer,
@@ -231,6 +241,8 @@ func (prx *ReceiverProxy) MevSendBundle(ctx context.Context, mevSendBundle rpcty
231241
uniqueKey := mevSendBundle.UniqueKey()
232242
parsedRequest.requestArgUniqueKey = &uniqueKey
233243

244+
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "add_fields")
245+
234246
return prx.HandleParsedRequest(ctx, parsedRequest)
235247
}
236248

@@ -347,6 +359,7 @@ type ParsedRequest struct {
347359
}
348360

349361
func (prx *ReceiverProxy) HandleParsedRequest(ctx context.Context, parsedRequest ParsedRequest) error {
362+
startAt := time.Now()
350363
ctx, cancel := context.WithTimeout(ctx, handleParsedRequestTimeout)
351364
defer cancel()
352365

@@ -362,25 +375,39 @@ func (prx *ReceiverProxy) HandleParsedRequest(ctx context.Context, parsedRequest
362375
}
363376
prx.requestUniqueKeysRLU.Add(*parsedRequest.requestArgUniqueKey, struct{}{})
364377
}
378+
379+
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "validation")
380+
startAt = time.Now()
381+
365382
if !parsedRequest.systemEndpoint {
366383
err := prx.userAPIRateLimiter.Wait(ctx)
367384
if err != nil {
368385
incAPIUserRateLimits()
369386
return errors.Join(errRateLimiting, err)
370387
}
371388
}
389+
390+
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "rate_limiting")
391+
startAt = time.Now()
392+
372393
select {
373394
case <-ctx.Done():
374395
prx.Log.Error("Shared queue is stalling")
375396
case prx.shareQueue <- &parsedRequest:
376397
}
398+
399+
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "share_queue")
400+
startAt = time.Now()
401+
377402
if !parsedRequest.systemEndpoint {
378403
select {
379404
case <-ctx.Done():
380405
prx.Log.Error("Archive queue is stalling")
381406
case prx.archiveQueue <- &parsedRequest:
382407
}
383408
}
409+
410+
incRequestDurationStep(time.Since(startAt), parsedRequest.method, "", "archive_queue")
384411
return nil
385412
}
386413

0 commit comments

Comments
Β (0)