Skip to content

Commit

Permalink
chore(solver/app): instrument inbox processed offset (#2665)
Browse files Browse the repository at this point in the history
Add metric tracking latest req offset processed by status. 

issue: none
  • Loading branch information
corverroos authored Dec 10, 2024
1 parent 276f54a commit 0e80a0f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion solver/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func startEventStreams(
outboxContracts := make(map[uint64]*bindings.SolveOutbox)
for _, chain := range outboxChains {
name := network.ChainName(chain)
log.Debug(ctx, "Using outbox contract", "chain", name, "address", addrs.SolveInbox.Hex())
log.Debug(ctx, "Using outbox contract", "chain", name, "address", addrs.SolveOutbox.Hex())

backend, err := backends.Backend(chain)
if err != nil {
Expand All @@ -232,6 +232,7 @@ func startEventStreams(
Fulfill: newFulfiller(network.ID, outboxContracts, backends, solverAddr, addrs.SolveOutbox),
Claim: newClaimer(inboxContracts, backends, solverAddr),
SetCursor: cursorSetter,
ChainName: network.ChainName,
}

for _, chain := range inboxChains {
Expand Down
9 changes: 4 additions & 5 deletions solver/app/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

import (
"context"
"encoding/hex"
"encoding/binary"

"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/ethclient/ethbackend"
Expand Down Expand Up @@ -33,8 +33,7 @@ func detectContractChains(ctx context.Context, network netconf.Network, backends
return resp, nil
}

// fmtReqID returns the least-significant 7 hex chars of the provided request ID.
// ReqIDs are monotonically incrementing numbers, not hashes.
func fmtReqID(reqID [32]byte) string {
return hex.EncodeToString(reqID[:])[64-7:]
// reqIDOffset returns the req ID as a uint64 offset (monotonically incrementing number).
func reqIDOffset(reqID [32]byte) uint64 {
return binary.BigEndian.Uint64(reqID[32-8:])
}
15 changes: 15 additions & 0 deletions solver/app/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
statusOffset = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "solver",
Subsystem: "processor",
Name: "status_offset",
Help: "Last inbox offset processed by chain and status",
}, []string{"chain", "status"})
)
2 changes: 2 additions & 0 deletions solver/app/procdeps.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type procDeps struct {
Reject func(ctx context.Context, chainID uint64, req bindings.SolveRequest, reason rejectReason) error
Fulfill func(ctx context.Context, chainID uint64, req bindings.SolveRequest) error
Claim func(ctx context.Context, chainID uint64, req bindings.SolveRequest) error

ChainName func(chainID uint64) string
}

func newClaimer(
Expand Down
5 changes: 3 additions & 2 deletions solver/app/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ func newEventProcessor(deps procDeps, chainID uint64) xchain.EventLogsCallback {
return errors.Wrap(err, "parse id")
}

ctx := log.WithCtx(ctx, "status", statusString(event.Status), "req_id", fmtReqID(reqID))

offset := reqIDOffset(reqID)
statusOffset.WithLabelValues(deps.ChainName(chainID), statusString(event.Status)).Set(float64(offset))
ctx := log.WithCtx(ctx, "status", statusString(event.Status), "req_id", offset)
log.Debug(ctx, "Processing event")

req, _, err := deps.GetRequest(ctx, chainID, reqID)
Expand Down
1 change: 1 addition & 0 deletions solver/app/processor_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func TestEventProcessor(t *testing.T) {

return nil
},
ChainName: func(uint64) string { return "" },
}

processor := newEventProcessor(deps, chainID)
Expand Down

0 comments on commit 0e80a0f

Please sign in to comment.