Commit 32639605 authored by Conner Fromknecht's avatar Conner Fromknecht Committed by GitHub

fix: correct FailedDatabase counter for upsert_disbursement, expose api-server metrics (#2548)

* fix: correct FailedDatabase counter for upsert_disbursement

Previously we would always increment the counter instead of adding the
number of failed upserts observed.

* feat: expose teleportr-api metrics server
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent b7a04acf
---
'@eth-optimism/teleportr': patch
---
Fix teleportr FailedDatabaseOperations method for upsert_disbursement
---
'@eth-optimism/teleportr': patch
---
Expose metrics server
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
bsscore "github.com/ethereum-optimism/optimism/bss-core" bsscore "github.com/ethereum-optimism/optimism/bss-core"
"github.com/ethereum-optimism/optimism/bss-core/dial" "github.com/ethereum-optimism/optimism/bss-core/dial"
"github.com/ethereum-optimism/optimism/bss-core/drivers" "github.com/ethereum-optimism/optimism/bss-core/drivers"
"github.com/ethereum-optimism/optimism/bss-core/metrics"
"github.com/ethereum-optimism/optimism/bss-core/txmgr" "github.com/ethereum-optimism/optimism/bss-core/txmgr"
"github.com/ethereum-optimism/optimism/teleportr/bindings/deposit" "github.com/ethereum-optimism/optimism/teleportr/bindings/deposit"
"github.com/ethereum-optimism/optimism/teleportr/db" "github.com/ethereum-optimism/optimism/teleportr/db"
...@@ -84,6 +85,10 @@ func Main(gitVersion string) func(*cli.Context) error { ...@@ -84,6 +85,10 @@ func Main(gitVersion string) func(*cli.Context) error {
} }
defer database.Close() defer database.Close()
if cfg.MetricsServerEnable {
go metrics.RunServer(cfg.MetricsHostname, cfg.MetricsPort)
}
server := NewServer( server := NewServer(
ctx, ctx,
l1Client, l1Client,
...@@ -124,33 +129,40 @@ func Main(gitVersion string) func(*cli.Context) error { ...@@ -124,33 +129,40 @@ func Main(gitVersion string) func(*cli.Context) error {
} }
type Config struct { type Config struct {
Hostname string Hostname string
Port uint16 Port uint16
L1EthRpc string L1EthRpc string
DepositAddress string DepositAddress string
NumConfirmations uint64 NumConfirmations uint64
PostgresHost string PostgresHost string
PostgresPort uint16 PostgresPort uint16
PostgresUser string PostgresUser string
PostgresPassword string PostgresPassword string
PostgresDBName string PostgresDBName string
PostgresEnableSSL bool PostgresEnableSSL bool
DisableHTTP2 bool MetricsServerEnable bool
MetricsHostname string
MetricsPort uint64
DisableHTTP2 bool
} }
func NewConfig(ctx *cli.Context) (Config, error) { func NewConfig(ctx *cli.Context) (Config, error) {
return Config{ return Config{
Hostname: ctx.GlobalString(flags.APIHostnameFlag.Name), Hostname: ctx.GlobalString(flags.APIHostnameFlag.Name),
Port: uint16(ctx.GlobalUint64(flags.APIPortFlag.Name)), Port: uint16(ctx.GlobalUint64(flags.APIPortFlag.Name)),
L1EthRpc: ctx.GlobalString(flags.L1EthRpcFlag.Name), L1EthRpc: ctx.GlobalString(flags.L1EthRpcFlag.Name),
DepositAddress: ctx.GlobalString(flags.DepositAddressFlag.Name), DepositAddress: ctx.GlobalString(flags.DepositAddressFlag.Name),
NumConfirmations: ctx.GlobalUint64(flags.NumDepositConfirmationsFlag.Name), NumConfirmations: ctx.GlobalUint64(flags.NumDepositConfirmationsFlag.Name),
PostgresHost: ctx.GlobalString(flags.PostgresHostFlag.Name), PostgresHost: ctx.GlobalString(flags.PostgresHostFlag.Name),
PostgresPort: uint16(ctx.GlobalUint64(flags.PostgresPortFlag.Name)), PostgresPort: uint16(ctx.GlobalUint64(flags.PostgresPortFlag.Name)),
PostgresUser: ctx.GlobalString(flags.PostgresUserFlag.Name), PostgresUser: ctx.GlobalString(flags.PostgresUserFlag.Name),
PostgresPassword: ctx.GlobalString(flags.PostgresPasswordFlag.Name), PostgresPassword: ctx.GlobalString(flags.PostgresPasswordFlag.Name),
PostgresDBName: ctx.GlobalString(flags.PostgresDBNameFlag.Name), PostgresDBName: ctx.GlobalString(flags.PostgresDBNameFlag.Name),
PostgresEnableSSL: ctx.GlobalBool(flags.PostgresEnableSSLFlag.Name), PostgresEnableSSL: ctx.GlobalBool(flags.PostgresEnableSSLFlag.Name),
MetricsServerEnable: ctx.GlobalBool(flags.MetricsServerEnableFlag.Name),
MetricsHostname: ctx.GlobalString(flags.MetricsHostnameFlag.Name),
MetricsPort: ctx.GlobalUint64(flags.MetricsPortFlag.Name),
DisableHTTP2: ctx.GlobalBool(flags.HTTP2DisableFlag.Name),
}, nil }, nil
} }
......
...@@ -436,7 +436,7 @@ func (d *Driver) processPendingTxs(ctx context.Context) error { ...@@ -436,7 +436,7 @@ func (d *Driver) processPendingTxs(ctx context.Context) error {
d.metrics.SuccessfulDisbursements.Add(float64(successfulDisbursements)) d.metrics.SuccessfulDisbursements.Add(float64(successfulDisbursements))
d.metrics.FailedDisbursements.Add(float64(failedDisbursements)) d.metrics.FailedDisbursements.Add(float64(failedDisbursements))
d.metrics.FailedDatabaseMethods.With(DBMethodUpsertDisbursement). d.metrics.FailedDatabaseMethods.With(DBMethodUpsertDisbursement).
Inc() Add(float64(failedUpserts))
// 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.
......
...@@ -38,4 +38,8 @@ var APIFlags = []cli.Flag{ ...@@ -38,4 +38,8 @@ var APIFlags = []cli.Flag{
PostgresPasswordFlag, PostgresPasswordFlag,
PostgresDBNameFlag, PostgresDBNameFlag,
PostgresEnableSSLFlag, PostgresEnableSSLFlag,
MetricsServerEnableFlag,
MetricsHostnameFlag,
MetricsPortFlag,
HTTP2DisableFlag,
} }
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