Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
f101d38b
Commit
f101d38b
authored
Mar 22, 2022
by
Matthew Slipper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/teleportr: Add balance metrics
parent
d4de0cf3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
24 deletions
+58
-24
eighty-squids-impress.md
.changeset/eighty-squids-impress.md
+5
-0
driver.go
go/teleportr/drivers/disburser/driver.go
+33
-20
metrics.go
go/teleportr/drivers/disburser/metrics.go
+20
-4
No files found.
.changeset/eighty-squids-impress.md
0 → 100644
View file @
f101d38b
---
'
@eth-optimism/teleportr'
:
patch
---
Add metrics for balances
go/teleportr/drivers/disburser/driver.go
View file @
f101d38b
...
@@ -139,6 +139,9 @@ func (d *Driver) ClearPendingTx(
...
@@ -139,6 +139,9 @@ func (d *Driver) ClearPendingTx(
func
(
d
*
Driver
)
GetBatchBlockRange
(
func
(
d
*
Driver
)
GetBatchBlockRange
(
ctx
context
.
Context
)
(
*
big
.
Int
,
*
big
.
Int
,
error
)
{
ctx
context
.
Context
)
(
*
big
.
Int
,
*
big
.
Int
,
error
)
{
// Update balance metrics on each iteration.
d
.
updateBalanceMetrics
(
ctx
)
// Clear the current deposit IDs from any prior iteration.
// Clear the current deposit IDs from any prior iteration.
d
.
currentDepositIDs
=
nil
d
.
currentDepositIDs
=
nil
...
@@ -317,7 +320,7 @@ func (d *Driver) SendTransaction(
...
@@ -317,7 +320,7 @@ func (d *Driver) SendTransaction(
txHash
:=
tx
.
Hash
()
txHash
:=
tx
.
Hash
()
startID
:=
d
.
currentDepositIDs
[
0
]
startID
:=
d
.
currentDepositIDs
[
0
]
endID
:=
d
.
currentDepositIDs
[
len
(
d
.
currentDepositIDs
)
-
1
]
+
1
endID
:=
d
.
currentDepositIDs
[
len
(
d
.
currentDepositIDs
)
-
1
]
+
1
// Record the pending transaction hash so that we can recover if we crash
// Record the pending transaction hash so that we can recover if we crash
// after publishing.
// after publishing.
...
@@ -430,10 +433,10 @@ func (d *Driver) processPendingTxs(ctx context.Context) error {
...
@@ -430,10 +433,10 @@ func (d *Driver) processPendingTxs(ctx context.Context) error {
"blockTimestamp"
,
blockTimestamp
)
"blockTimestamp"
,
blockTimestamp
)
}
}
d
.
metrics
.
SuccessfulDisbursements
.
Set
(
float64
(
successfulDisbursements
))
d
.
metrics
.
SuccessfulDisbursements
.
Add
(
float64
(
successfulDisbursements
))
d
.
metrics
.
FailedDisbursements
.
Set
(
float64
(
failedDisbursements
))
d
.
metrics
.
FailedDisbursements
.
Add
(
float64
(
failedDisbursements
))
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodUpsertDisbursement
)
.
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodUpsertDisbursement
)
.
Set
(
float64
(
failedUpserts
)
)
Inc
(
)
// We have completed our post-processing once all of the disbursements are
// We have completed our post-processing once all of the disbursements are
// written without failures.
// written without failures.
...
@@ -620,7 +623,7 @@ func (d *Driver) logDatabaseContractMismatch(
...
@@ -620,7 +623,7 @@ func (d *Driver) logDatabaseContractMismatch(
log
.
Warn
(
"Recorded disbursements behind contract"
,
log
.
Warn
(
"Recorded disbursements behind contract"
,
"last_disbursement_id"
,
*
lastDisbursementID
,
"last_disbursement_id"
,
*
lastDisbursementID
,
"contract_next_id"
,
contractNextID
)
"contract_next_id"
,
contractNextID
)
d
.
metrics
.
DepositIDMismatch
.
Set
(
1.0
)
d
.
metrics
.
DepositIDMismatch
.
Inc
(
)
// The last recorded disbursement is ahead of what the contract believes.
// The last recorded disbursement is ahead of what the contract believes.
// This should NEVER happen unless the sequencer blows up and loses
// This should NEVER happen unless the sequencer blows up and loses
...
@@ -643,7 +646,7 @@ func (d *Driver) logDatabaseContractMismatch(
...
@@ -643,7 +646,7 @@ func (d *Driver) logDatabaseContractMismatch(
log
.
Warn
(
"Recorded disbursements behind contract"
,
log
.
Warn
(
"Recorded disbursements behind contract"
,
"last_disbursement_id"
,
nil
,
"last_disbursement_id"
,
nil
,
"contract_next_id"
,
contractNextID
)
"contract_next_id"
,
contractNextID
)
d
.
metrics
.
DepositIDMismatch
.
Set
(
1.0
)
d
.
metrics
.
DepositIDMismatch
.
Inc
(
)
// Database and contract indicate we have not done a disbursement.
// Database and contract indicate we have not done a disbursement.
default
:
default
:
...
@@ -654,10 +657,9 @@ func (d *Driver) logDatabaseContractMismatch(
...
@@ -654,10 +657,9 @@ func (d *Driver) logDatabaseContractMismatch(
func
(
d
*
Driver
)
upsertDeposits
(
deposits
[]
db
.
Deposit
,
end
uint64
)
error
{
func
(
d
*
Driver
)
upsertDeposits
(
deposits
[]
db
.
Deposit
,
end
uint64
)
error
{
err
:=
d
.
cfg
.
Database
.
UpsertDeposits
(
deposits
,
end
)
err
:=
d
.
cfg
.
Database
.
UpsertDeposits
(
deposits
,
end
)
if
err
!=
nil
{
if
err
!=
nil
{
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodUpsertDeposits
)
.
Set
(
1.0
)
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodUpsertDeposits
)
.
Inc
(
)
return
err
return
err
}
}
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodUpsertDeposits
)
.
Set
(
0.0
)
return
nil
return
nil
}
}
...
@@ -666,59 +668,70 @@ func (d *Driver) confirmedDeposits(blockNumber uint64) ([]db.Deposit, error) {
...
@@ -666,59 +668,70 @@ func (d *Driver) confirmedDeposits(blockNumber uint64) ([]db.Deposit, error) {
blockNumber
,
d
.
cfg
.
NumConfirmations
,
blockNumber
,
d
.
cfg
.
NumConfirmations
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodConfirmedDeposits
)
.
Set
(
1.0
)
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodConfirmedDeposits
)
.
Inc
(
)
return
nil
,
err
return
nil
,
err
}
}
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodConfirmedDeposits
)
.
Set
(
0.0
)
return
confirmedDeposits
,
nil
return
confirmedDeposits
,
nil
}
}
func
(
d
*
Driver
)
lastProcessedBlock
()
(
*
uint64
,
error
)
{
func
(
d
*
Driver
)
lastProcessedBlock
()
(
*
uint64
,
error
)
{
lastProcessedBlock
,
err
:=
d
.
cfg
.
Database
.
LastProcessedBlock
()
lastProcessedBlock
,
err
:=
d
.
cfg
.
Database
.
LastProcessedBlock
()
if
err
!=
nil
{
if
err
!=
nil
{
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodLastProcessedBlock
)
.
Set
(
1.0
)
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodLastProcessedBlock
)
.
Inc
(
)
return
nil
,
err
return
nil
,
err
}
}
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodLastProcessedBlock
)
.
Set
(
0.0
)
return
lastProcessedBlock
,
nil
return
lastProcessedBlock
,
nil
}
}
func
(
d
*
Driver
)
upsertPendingTx
(
pendingTx
db
.
PendingTx
)
error
{
func
(
d
*
Driver
)
upsertPendingTx
(
pendingTx
db
.
PendingTx
)
error
{
err
:=
d
.
cfg
.
Database
.
UpsertPendingTx
(
pendingTx
)
err
:=
d
.
cfg
.
Database
.
UpsertPendingTx
(
pendingTx
)
if
err
!=
nil
{
if
err
!=
nil
{
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodUpsertPendingTx
)
.
Set
(
1.0
)
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodUpsertPendingTx
)
.
Inc
(
)
return
err
return
err
}
}
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodUpsertPendingTx
)
.
Set
(
0.0
)
return
nil
return
nil
}
}
func
(
d
*
Driver
)
listPendingTxs
()
([]
db
.
PendingTx
,
error
)
{
func
(
d
*
Driver
)
listPendingTxs
()
([]
db
.
PendingTx
,
error
)
{
pendingTxs
,
err
:=
d
.
cfg
.
Database
.
ListPendingTxs
()
pendingTxs
,
err
:=
d
.
cfg
.
Database
.
ListPendingTxs
()
if
err
!=
nil
{
if
err
!=
nil
{
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodListPendingTxs
)
.
Set
(
1.0
)
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodListPendingTxs
)
.
Inc
(
)
return
nil
,
err
return
nil
,
err
}
}
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodListPendingTxs
)
.
Set
(
0.0
)
return
pendingTxs
,
nil
return
pendingTxs
,
nil
}
}
func
(
d
*
Driver
)
latestDisbursementID
()
(
*
uint64
,
error
)
{
func
(
d
*
Driver
)
latestDisbursementID
()
(
*
uint64
,
error
)
{
lastDisbursementID
,
err
:=
d
.
cfg
.
Database
.
LatestDisbursementID
()
lastDisbursementID
,
err
:=
d
.
cfg
.
Database
.
LatestDisbursementID
()
if
err
!=
nil
{
if
err
!=
nil
{
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodLatestDisbursementID
)
.
Set
(
1.0
)
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodLatestDisbursementID
)
.
Inc
(
)
return
nil
,
err
return
nil
,
err
}
}
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodLatestDisbursementID
)
.
Set
(
0.0
)
return
lastDisbursementID
,
nil
return
lastDisbursementID
,
nil
}
}
func
(
d
*
Driver
)
deletePendingTx
(
startID
,
endID
uint64
)
error
{
func
(
d
*
Driver
)
deletePendingTx
(
startID
,
endID
uint64
)
error
{
err
:=
d
.
cfg
.
Database
.
DeletePendingTx
(
startID
,
endID
)
err
:=
d
.
cfg
.
Database
.
DeletePendingTx
(
startID
,
endID
)
if
err
!=
nil
{
if
err
!=
nil
{
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodDeletePendingTx
)
.
Set
(
1.0
)
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodDeletePendingTx
)
.
Inc
(
)
return
err
return
err
}
}
d
.
metrics
.
FailedDatabaseMethods
.
With
(
DBMethodDeletePendingTx
)
.
Set
(
0.0
)
return
nil
return
nil
}
}
func
(
d
*
Driver
)
updateBalanceMetrics
(
ctx
context
.
Context
)
{
disburserBal
,
err
:=
d
.
cfg
.
L2Client
.
BalanceAt
(
ctx
,
d
.
walletAddr
,
nil
)
if
err
!=
nil
{
log
.
Error
(
"Error getting disburser wallet balance"
,
"err"
,
err
)
disburserBal
=
big
.
NewInt
(
0
)
}
depositBal
,
err
:=
d
.
cfg
.
L1Client
.
BalanceAt
(
ctx
,
d
.
cfg
.
DepositAddr
,
nil
)
if
err
!=
nil
{
log
.
Error
(
"Error getting deposit contract balance"
,
"err"
,
err
)
depositBal
=
big
.
NewInt
(
0
)
}
d
.
metrics
.
DisburserBalance
.
Set
(
float64
(
disburserBal
.
Uint64
()))
d
.
metrics
.
DepositContractBalance
.
Set
(
float64
(
depositBal
.
Uint64
()))
}
go/teleportr/drivers/disburser/metrics.go
View file @
f101d38b
...
@@ -41,7 +41,7 @@ type Metrics struct {
...
@@ -41,7 +41,7 @@ type Metrics struct {
// FailedDatabaseMethods tracks the number of database failures for each
// FailedDatabaseMethods tracks the number of database failures for each
// known database method.
// known database method.
FailedDatabaseMethods
*
prometheus
.
Gauge
Vec
FailedDatabaseMethods
*
prometheus
.
Counter
Vec
// DepositIDMismatch tracks whether or not our database is in sync with the
// DepositIDMismatch tracks whether or not our database is in sync with the
// disrburser contract. 1 means in sync, 0 means out of sync.
// disrburser contract. 1 means in sync, 0 means out of sync.
...
@@ -53,11 +53,11 @@ type Metrics struct {
...
@@ -53,11 +53,11 @@ type Metrics struct {
// SuccessfulDisbursements tracks the number of disbursements that emit a
// SuccessfulDisbursements tracks the number of disbursements that emit a
// success event from a given tx.
// success event from a given tx.
SuccessfulDisbursements
prometheus
.
Gauge
SuccessfulDisbursements
prometheus
.
Counter
// FailedDisbursements tracks the number of disbursements that emit a failed
// FailedDisbursements tracks the number of disbursements that emit a failed
// event from a given tx.
// event from a given tx.
FailedDisbursements
prometheus
.
Gauge
FailedDisbursements
prometheus
.
Counter
// PostgresLastDisbursedID tracks the latest disbursement id in postgres.
// PostgresLastDisbursedID tracks the latest disbursement id in postgres.
PostgresLastDisbursedID
prometheus
.
Gauge
PostgresLastDisbursedID
prometheus
.
Gauge
...
@@ -65,6 +65,12 @@ type Metrics struct {
...
@@ -65,6 +65,12 @@ type Metrics struct {
// ContractNextDisbursementID tracks the next disbursement id expected by
// ContractNextDisbursementID tracks the next disbursement id expected by
// the disburser contract.
// the disburser contract.
ContractNextDisbursementID
prometheus
.
Gauge
ContractNextDisbursementID
prometheus
.
Gauge
// DisburserBalance tracks Teleportr's disburser account balance.
DisburserBalance
prometheus
.
Gauge
// DepositContractBalance tracks Teleportr's deposit contract balance.
DepositContractBalance
prometheus
.
Gauge
}
}
// NewMetrics initializes a new, extended metrics object.
// NewMetrics initializes a new, extended metrics object.
...
@@ -72,7 +78,7 @@ func NewMetrics(subsystem string) *Metrics {
...
@@ -72,7 +78,7 @@ func NewMetrics(subsystem string) *Metrics {
base
:=
metrics
.
NewBase
(
subsystem
,
""
)
base
:=
metrics
.
NewBase
(
subsystem
,
""
)
return
&
Metrics
{
return
&
Metrics
{
Base
:
base
,
Base
:
base
,
FailedDatabaseMethods
:
promauto
.
New
GaugeVec
(
prometheus
.
Gauge
Opts
{
FailedDatabaseMethods
:
promauto
.
New
CounterVec
(
prometheus
.
Counter
Opts
{
Name
:
"failed_database_operations"
,
Name
:
"failed_database_operations"
,
Help
:
"Tracks the number of database failures"
,
Help
:
"Tracks the number of database failures"
,
Subsystem
:
base
.
SubsystemName
(),
Subsystem
:
base
.
SubsystemName
(),
...
@@ -111,5 +117,15 @@ func NewMetrics(subsystem string) *Metrics {
...
@@ -111,5 +117,15 @@ func NewMetrics(subsystem string) *Metrics {
Help
:
"Next disbursement id expected by the disburser contract"
,
Help
:
"Next disbursement id expected by the disburser contract"
,
Subsystem
:
base
.
SubsystemName
(),
Subsystem
:
base
.
SubsystemName
(),
}),
}),
DisburserBalance
:
promauto
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"disburser_balance"
,
Help
:
"Balance in Wei of Teleportr's disburser wallet"
,
Subsystem
:
base
.
SubsystemName
(),
}),
DepositContractBalance
:
promauto
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"deposit_contract_balance"
,
Help
:
"Balance in Wei of Teleportr's deposit contract"
,
Subsystem
:
base
.
SubsystemName
(),
}),
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment