Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFQ Relayer: add request status count metric #2856

Merged
merged 19 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 18 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
1 change: 1 addition & 0 deletions docs/bridge/docs/rfq/Relayer/Relayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,4 @@ The metrics exposed by the relayer are:

- `inventory_balance`: The balance of the inventory on the chain for a given `token_name` and `relayer`.
- `quote_amount`: The amount quoted for a given `token_name` and `relayer`.
- `status_count`: The distribution of non-terminal `QuoteRequestStatus` values over time.
2 changes: 1 addition & 1 deletion services/rfq/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/Flaque/filet v0.0.0-20201012163910-45f684403088
github.com/alecthomas/assert v1.0.0
github.com/brianvoe/gofakeit/v6 v6.27.0
github.com/cornelk/hashmap v1.0.8
github.com/dubonzi/otelresty v1.3.0
github.com/ethereum/go-ethereum v1.13.8
github.com/gin-gonic/gin v1.10.0
Expand Down Expand Up @@ -107,7 +108,6 @@ require (
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/containerd/continuity v0.4.2 // indirect
github.com/cornelk/hashmap v1.0.8 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
Expand Down
166 changes: 116 additions & 50 deletions services/rfq/relayer/dashboards/dashboard.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "Prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__elements": {},
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "10.1.2"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "text",
"name": "Text",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"version": ""
}
],
"annotations": {
"list": [
{
Expand All @@ -55,14 +18,14 @@
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": null,
"id": 770,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"description": "",
"gridPos": {
Expand All @@ -88,7 +51,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"description": "ETH balances of the RFQ relayer by chain.",
"fieldConfig": {
Expand Down Expand Up @@ -167,7 +130,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"editorMode": "code",
"expr": "avg(inventory_balance{token_name=\"ETH\",relayer=\"$relayer\"}) by (chain_id)",
Expand All @@ -183,7 +146,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"description": "USDC balances of the RFQ relayer by chain.",
"fieldConfig": {
Expand Down Expand Up @@ -262,7 +225,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"editorMode": "code",
"expr": "avg(inventory_balance{token_name=\"USD Coin\",relayer=\"$relayer\"}) by (chain_id)",
Expand All @@ -278,7 +241,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"description": "Displays the ETH quote amount for each origin -> destination path.",
"fieldConfig": {
Expand Down Expand Up @@ -357,7 +320,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"editorMode": "code",
"expr": "avg(quote_amount{origin_token_name=\"ETH\", dest_token_name=\"ETH\"}) by (origin_chain_id, dest_chain_id)",
Expand All @@ -373,7 +336,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"description": "Displays the USDC quote amount for each origin -> destination path.",
"fieldConfig": {
Expand Down Expand Up @@ -452,7 +415,7 @@
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"editorMode": "code",
"expr": "avg(quote_amount{origin_token_name=\"USD Coin\"} / 1e6) by (origin_chain_id, destination_chain_id)",
Expand All @@ -465,6 +428,105 @@
],
"title": "USDC Quote Sizing",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "Displays the count of any non-terminal QuoteRequestStatus values over time.",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 11,
"w": 12,
"x": 0,
"y": 23
},
"id": 9,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "builder",
"expr": "max by(status) (status_count{wallet=\"$relayer\"})",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "__auto",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Request Statuses",
"type": "timeseries"
}
],
"refresh": "",
Expand All @@ -474,10 +536,14 @@
"templating": {
"list": [
{
"current": {},
"current": {
"selected": false,
"text": "0xDD50676F81f607fD8bA7Ed3187DdF172DB174CD3",
"value": "0xDD50676F81f607fD8bA7Ed3187DdF172DB174CD3"
},
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
"uid": "prometheus"
},
"definition": "label_values(inventory_balance,relayer)",
"description": "Address of the relayer displayed in this dashboard.",
Expand Down Expand Up @@ -507,6 +573,6 @@
"timezone": "",
"title": "RFQ Relayer",
"uid": "c394e799-062f-4bfd-90d6-b94f2932575a",
"version": 17,
"version": 18,
"weekStart": ""
}
32 changes: 32 additions & 0 deletions services/rfq/relayer/reldb/base/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,35 @@
}
return status >= prevStatus
}

type statusCount struct {
Status int
Count int64
}

// GetStatusCounts gets the counts of quote requests by status.
func (s Store) GetStatusCounts(ctx context.Context, matchStatuses ...reldb.QuoteRequestStatus) (map[reldb.QuoteRequestStatus]int, error) {
inArgs := make([]int, len(matchStatuses))
for i := range matchStatuses {
inArgs[i] = int(matchStatuses[i].Int())
}

Check warning on line 152 in services/rfq/relayer/reldb/base/quote.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/reldb/base/quote.go#L148-L152

Added lines #L148 - L152 were not covered by tests

var results []statusCount
tx := s.DB().
WithContext(ctx).
Model(&RequestForQuote{}).
Select(fmt.Sprintf("%s, COUNT(*) as count", statusFieldName)).
Where(fmt.Sprintf("%s IN ?", statusFieldName), inArgs).
Group(statusFieldName).
Scan(&results)
if tx.Error != nil {
return nil, fmt.Errorf("could not get db results: %w", tx.Error)
}

Check warning on line 164 in services/rfq/relayer/reldb/base/quote.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/reldb/base/quote.go#L154-L164

Added lines #L154 - L164 were not covered by tests

statuses := make(map[reldb.QuoteRequestStatus]int)
for _, result := range results {
statuses[reldb.QuoteRequestStatus(result.Status)] = int(result.Count)
}

Check warning on line 169 in services/rfq/relayer/reldb/base/quote.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/reldb/base/quote.go#L166-L169

Added lines #L166 - L169 were not covered by tests

return statuses, nil

Check warning on line 171 in services/rfq/relayer/reldb/base/quote.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/reldb/base/quote.go#L171

Added line #L171 was not covered by tests
trajan0x marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions services/rfq/relayer/reldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type Reader interface {
GetRebalanceByID(ctx context.Context, rebalanceID string) (*Rebalance, error)
// GetDBStats gets the database stats.
GetDBStats(ctx context.Context) (*sql.DBStats, error)
// GetStatusCounts gets the counts of quote requests by status.
GetStatusCounts(ctx context.Context, matchStatuses ...QuoteRequestStatus) (map[QuoteRequestStatus]int, error)
}

// Service is the interface for the database service.
Expand Down
Loading
Loading