Commit 12dbd81b authored by Annie Ke's avatar Annie Ke Committed by GitHub

feat[batch-submitter]: add metrics (#722)

* add ethBalance gauge

* add rest of bs metrics

* add changeset
parent ae1ac05d
---
'@eth-optimism/batch-submitter': patch
---
add key metrics to batch submitter
......@@ -31,16 +31,17 @@
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/common-ts": "^0.0.1",
"@eth-optimism/contracts": "^0.2.8",
"@eth-optimism/core-utils": "^0.3.2",
"@eth-optimism/common-ts": "^0.0.1",
"@eth-optimism/ynatm": "^0.2.2",
"@ethersproject/abstract-provider": "^5.0.5",
"@ethersproject/providers": "^5.0.14",
"bluebird": "^3.7.2",
"dotenv": "^8.2.0",
"ethers": "5.0.0",
"old-contracts": "npm:@eth-optimism/contracts@^0.0.2-alpha.7"
"old-contracts": "npm:@eth-optimism/contracts@^0.0.2-alpha.7",
"prom-client": "^13.1.0"
},
"devDependencies": {
"@eth-optimism/smock": "^1.1.1",
......
/* External Imports */
import { Contract, Signer, utils, providers } from 'ethers'
import { TransactionReceipt } from '@ethersproject/abstract-provider'
import { Gauge, Histogram } from 'prom-client'
import * as ynatm from '@eth-optimism/ynatm'
import { RollupInfo } from '@eth-optimism/core-utils'
import { Logger, Metrics } from '@eth-optimism/common-ts'
......@@ -17,12 +18,21 @@ export interface ResubmissionConfig {
gasRetryIncrement: number
}
interface BatchSubmitterMetrics {
batchSubmitterETHBalance: Gauge<string>
batchSizeInBytes: Histogram<string>
numTxPerBatch: Histogram<string>
submissionTimestamp: Histogram<string>
submissionGasUsed: Histogram<string>
}
export abstract class BatchSubmitter {
protected rollupInfo: RollupInfo
protected chainContract: Contract
protected l2ChainId: number
protected syncing: boolean
protected lastBatchSubmissionTimestamp: number = 0
protected metrics: BatchSubmitterMetrics
constructor(
readonly signer: Signer,
......@@ -41,8 +51,10 @@ export abstract class BatchSubmitter {
readonly gasRetryIncrement: number,
readonly gasThresholdInGwei: number,
readonly logger: Logger,
readonly metrics: Metrics
) {}
readonly defaultMetrics: Metrics
) {
this.metrics = this._registerMetrics(defaultMetrics)
}
public abstract _submitBatch(
startBlock: number,
......@@ -58,6 +70,7 @@ export abstract class BatchSubmitter {
}
await this._updateChainInfo()
await this._checkBalance()
this.logger.info('Readying to submit next batch...', {
l2ChainId: this.l2ChainId,
batchSubmitterAddress: await this.signer.getAddress(),
......@@ -87,6 +100,7 @@ export abstract class BatchSubmitter {
address,
ether,
})
this.metrics.batchSubmitterETHBalance.set(num)
if (num < this.minBalanceEther) {
this.logger.fatal('Current balance lower than min safe balance', {
......@@ -146,6 +160,7 @@ export abstract class BatchSubmitter {
lastBatchSubmissionTimestamp: this.lastBatchSubmissionTimestamp,
currentTimestamp,
})
this.metrics.batchSizeInBytes.observe(batchSizeInBytes)
return true
}
this.logger.info(
......@@ -156,6 +171,7 @@ export abstract class BatchSubmitter {
currentTimestamp,
}
)
this.metrics.batchSizeInBytes.observe(batchSizeInBytes)
return true
}
......@@ -223,6 +239,40 @@ export abstract class BatchSubmitter {
this.logger.info('Received transaction receipt', { receipt })
this.logger.info(successMessage)
this.metrics.submissionGasUsed.observe(receipt.gasUsed.toNumber())
this.metrics.submissionTimestamp.observe(Date.now())
return receipt
}
private _registerMetrics(metrics: Metrics): BatchSubmitterMetrics {
metrics.registry.clear()
return {
batchSubmitterETHBalance: new metrics.client.Gauge({
name: 'batch_submitter_eth_balance',
help: 'ETH balance of the batch submitter',
registers: [metrics.registry],
}),
batchSizeInBytes: new metrics.client.Histogram({
name: 'batch_size_in_bytes',
help: 'Size of batches in bytes',
registers: [metrics.registry],
}),
numTxPerBatch: new metrics.client.Histogram({
name: 'num_txs_per_batch',
help: 'Number of transactions in each batch',
registers: [metrics.registry],
}),
submissionTimestamp: new metrics.client.Histogram({
name: 'submission_timestamp',
help: 'Timestamp of each batch submitter submission',
registers: [metrics.registry],
}),
submissionGasUsed: new metrics.client.Histogram({
name: 'submission_gash_used',
help: 'Gas used to submit each batch',
registers: [metrics.registry],
}),
}
}
}
......@@ -237,6 +237,7 @@ export class TransactionBatchSubmitter extends BatchSubmitter {
if (!wasBatchTruncated && !this._shouldSubmitBatch(batchSizeInBytes)) {
return
}
this.metrics.numTxPerBatch.observe(endBlock - startBlock)
const l1tipHeight = await this.signer.provider.getBlockNumber()
this.logger.debug('Submitting batch.', {
calldata: batchParams,
......
......@@ -1914,15 +1914,15 @@
"@sentry/utils" "6.2.5"
tslib "^1.9.3"
"@sentry/core@6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.3.1.tgz#5e32ca919c9be30fec0bb3125a556bc711584bdf"
integrity sha512-aVuvVbaehGeN86jZlLDGGkhEtprdOtB6lvYLfGy40Dj1Tkh2mGWE550QsRXAXAqYvQzIYwQR23r6m3o8FujgVg==
dependencies:
"@sentry/hub" "6.3.1"
"@sentry/minimal" "6.3.1"
"@sentry/types" "6.3.1"
"@sentry/utils" "6.3.1"
"@sentry/core@6.3.5":
version "6.3.5"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.3.5.tgz#6b73de736eb9d0040be94cdbb06a744cd6b9172e"
integrity sha512-VR2ibDy33mryD0mT6d9fGhKjdNzS2FSwwZPe9GvmNOjkyjly/oV91BKVoYJneCqOeq8fyj2lvkJGKuupdJNDqg==
dependencies:
"@sentry/hub" "6.3.5"
"@sentry/minimal" "6.3.5"
"@sentry/types" "6.3.5"
"@sentry/utils" "6.3.5"
tslib "^1.9.3"
"@sentry/hub@5.30.0":
......@@ -1952,6 +1952,15 @@
"@sentry/utils" "6.3.1"
tslib "^1.9.3"
"@sentry/hub@6.3.5":
version "6.3.5"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.3.5.tgz#c5bc6760f7e4e53e87149703b106804299060389"
integrity sha512-ZYFo7VYKwdPVjuV9BDFiYn+MpANn6eZMz5QDBfZ2dugIvIVbuOyOOLx8PSa3ZXJoVTZZ7s2wD2fi/ZxKjNjZOQ==
dependencies:
"@sentry/types" "6.3.5"
"@sentry/utils" "6.3.5"
tslib "^1.9.3"
"@sentry/minimal@5.30.0":
version "5.30.0"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.30.0.tgz#ce3d3a6a273428e0084adcb800bc12e72d34637b"
......@@ -1979,6 +1988,15 @@
"@sentry/types" "6.3.1"
tslib "^1.9.3"
"@sentry/minimal@6.3.5":
version "6.3.5"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.3.5.tgz#ef4894771243d01d81e91819400d2ecdcb34b411"
integrity sha512-4RqIGAU0+8iI/1sw0GYPTr4SUA88/i2+JPjFJ+qloh5ANVaNwhFPRChw+Ys9xpre8LV9JZrEsEf8AvQr4fkNbA==
dependencies:
"@sentry/hub" "6.3.5"
"@sentry/types" "6.3.5"
tslib "^1.9.3"
"@sentry/node@^5.18.1":
version "5.30.0"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-5.30.0.tgz#4ca479e799b1021285d7fe12ac0858951c11cd48"
......@@ -2010,15 +2028,15 @@
tslib "^1.9.3"
"@sentry/node@^6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.3.1.tgz#0f81a0e352fa5b3e36bcc53adb6e26cd214c637d"
integrity sha512-D0r603fdNwUPkwvy0IcQaUSTafl+7lrOytiO5dfdLdlkhtTcwivwENc/n8ER8GOC2zpIvYOEIJvzP4PGL85khw==
dependencies:
"@sentry/core" "6.3.1"
"@sentry/hub" "6.3.1"
"@sentry/tracing" "6.3.1"
"@sentry/types" "6.3.1"
"@sentry/utils" "6.3.1"
version "6.3.5"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-6.3.5.tgz#d5cbf941d0a4caf7b8e644d71cc6b463eeda214e"
integrity sha512-scPB+DoAEPaqkYuyb8d/gVWbFmX5PhaYSNHybeHncaP/P4itLdq/AoAWGNxl0Hj4EQokfT4OZWxaaJi7SCYnaw==
dependencies:
"@sentry/core" "6.3.5"
"@sentry/hub" "6.3.5"
"@sentry/tracing" "6.3.5"
"@sentry/types" "6.3.5"
"@sentry/utils" "6.3.5"
cookie "^0.4.1"
https-proxy-agent "^5.0.0"
lru_map "^0.3.3"
......@@ -2046,7 +2064,18 @@
"@sentry/utils" "6.2.5"
tslib "^1.9.3"
"@sentry/tracing@6.3.1", "@sentry/tracing@^6.3.1":
"@sentry/tracing@6.3.5":
version "6.3.5"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.3.5.tgz#f76c362159141f860081ec7df80aa9f85b545860"
integrity sha512-TNKAST1ge2g24BlTfVxNp4gP5t3drbi0OVCh8h8ah+J7UjHSfdiqhd9W2h5qv1GO61gGlpWeN/TyioyQmOxu0Q==
dependencies:
"@sentry/hub" "6.3.5"
"@sentry/minimal" "6.3.5"
"@sentry/types" "6.3.5"
"@sentry/utils" "6.3.5"
tslib "^1.9.3"
"@sentry/tracing@^6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.3.1.tgz#3b96aabf4d9cebadfec070c006db79801a68ee24"
integrity sha512-qveDmoWsXy9qLEblZJwJ1OU/zZRlEd/q7Jhd0Hnwlob8Ci96huABEbYyGdJs18BKVHEFU3gSdVfvrikUE/W17g==
......@@ -2072,6 +2101,11 @@
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.3.1.tgz#af3b54728b29f633f38fbe51b8c10e3834fbc158"
integrity sha512-BEBn8JX1yaooCAuonbaMci9z0RjwwMbQ3Eny/eyDdd+rjXprZCZaStZnCvSThbNBqAJ8YaUqY2YBMnEwJxarAw==
"@sentry/types@6.3.5":
version "6.3.5"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.3.5.tgz#d5eca7e76c250882ab78c01a8df894a9a9ca537d"
integrity sha512-tY/3pkAmGYJ3F0BtwInsdt/uclNvF8aNG7XHsTPQNzk7BkNVWjCXx0sjxi6CILirl5nwNxYxVeTr2ZYAEZ/dSQ==
"@sentry/utils@5.30.0":
version "5.30.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.30.0.tgz#9a5bd7ccff85ccfe7856d493bffa64cabc41e980"
......@@ -2096,6 +2130,14 @@
"@sentry/types" "6.3.1"
tslib "^1.9.3"
"@sentry/utils@6.3.5":
version "6.3.5"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.3.5.tgz#a4805448cb0314d3d119688162aa695598a10bbb"
integrity sha512-kHUcZ37QYlNzz7c9LVdApITXHaNmQK7+sw/If3M/qpff1fd5XoecA8laLfcYuz+Cw5mRhVmdhPcCRM3Xi1IGXg==
dependencies:
"@sentry/types" "6.3.5"
tslib "^1.9.3"
"@sindresorhus/is@^0.14.0":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment