From 31105a009cb7e8bc5d61fb68a26109799ddc8dcb Mon Sep 17 00:00:00 2001 From: i-norden Date: Mon, 4 Apr 2022 14:35:18 -0500 Subject: [PATCH 1/3] add env bindings --- cmd/root.go | 20 +++++----- cmd/stateSnapshot.go | 14 +++---- environments/example.toml | 8 +++- pkg/snapshot/config.go | 72 +++++++++++++++------------------- pkg/snapshot/env.go | 82 +++++++++++++++++++++++++++++++++++++++ pkg/snapshot/service.go | 2 - pkg/snapshot/tracker.go | 2 +- 7 files changed, 139 insertions(+), 61 deletions(-) create mode 100644 pkg/snapshot/env.go diff --git a/cmd/root.go b/cmd/root.go index 259006e..9b10a29 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,6 +21,8 @@ import ( "os" "strings" + "github.com/vulcanize/ipld-eth-state-snapshot/pkg/snapshot" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -46,7 +48,7 @@ func Execute() { } func initFuncs(cmd *cobra.Command, args []string) { - logfile := viper.GetString("logfile") + logfile := viper.GetString("log.file") if logfile != "" { file, err := os.OpenFile(logfile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) @@ -84,7 +86,7 @@ func init() { viper.AutomaticEnv() rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file location") - rootCmd.PersistentFlags().String("logfile", "", "file path for logging") + rootCmd.PersistentFlags().String("log-file", "", "file path for logging") rootCmd.PersistentFlags().String("database-name", "vulcanize_public", "database name") rootCmd.PersistentFlags().Int("database-port", 5432, "database port") rootCmd.PersistentFlags().String("database-hostname", "localhost", "database hostname") @@ -92,13 +94,13 @@ func init() { rootCmd.PersistentFlags().String("database-password", "", "database password") rootCmd.PersistentFlags().String("log-level", log.InfoLevel.String(), "Log level (trace, debug, info, warn, error, fatal, panic") - viper.BindPFlag("logfile", rootCmd.PersistentFlags().Lookup("logfile")) - viper.BindPFlag("database.name", rootCmd.PersistentFlags().Lookup("database-name")) - viper.BindPFlag("database.port", rootCmd.PersistentFlags().Lookup("database-port")) - viper.BindPFlag("database.hostname", rootCmd.PersistentFlags().Lookup("database-hostname")) - viper.BindPFlag("database.user", rootCmd.PersistentFlags().Lookup("database-user")) - viper.BindPFlag("database.password", rootCmd.PersistentFlags().Lookup("database-password")) - viper.BindPFlag("log.level", rootCmd.PersistentFlags().Lookup("log-level")) + viper.BindPFlag(snapshot.LOGRUS_FILE_TOML, rootCmd.PersistentFlags().Lookup("log-file")) + viper.BindPFlag(snapshot.DATABASE_NAME_TOML, rootCmd.PersistentFlags().Lookup("database-name")) + viper.BindPFlag(snapshot.DATABASE_PORT_TOML, rootCmd.PersistentFlags().Lookup("database-port")) + viper.BindPFlag(snapshot.DATABASE_HOSTNAME_TOML, rootCmd.PersistentFlags().Lookup("database-hostname")) + viper.BindPFlag(snapshot.DATABASE_USER_TOML, rootCmd.PersistentFlags().Lookup("database-user")) + viper.BindPFlag(snapshot.DATABASE_PASSWORD_TOML, rootCmd.PersistentFlags().Lookup("database-password")) + viper.BindPFlag(snapshot.LOGRUS_LEVEL_TOML, rootCmd.PersistentFlags().Lookup("log-level")) } func initConfig() { diff --git a/cmd/stateSnapshot.go b/cmd/stateSnapshot.go index 4c79fb2..732befa 100644 --- a/cmd/stateSnapshot.go +++ b/cmd/stateSnapshot.go @@ -94,11 +94,11 @@ func init() { stateSnapshotCmd.PersistentFlags().String("snapshot-mode", "postgres", "output mode for snapshot ('file' or 'postgres')") stateSnapshotCmd.PersistentFlags().String("output-dir", "", "directory for writing ouput to while operating in 'file' mode") - viper.BindPFlag("leveldb.path", stateSnapshotCmd.PersistentFlags().Lookup("leveldb-path")) - viper.BindPFlag("leveldb.ancient", stateSnapshotCmd.PersistentFlags().Lookup("ancient-path")) - viper.BindPFlag("snapshot.blockHeight", stateSnapshotCmd.PersistentFlags().Lookup("block-height")) - viper.BindPFlag("snapshot.workers", stateSnapshotCmd.PersistentFlags().Lookup("workers")) - viper.BindPFlag("snapshot.recoveryFile", stateSnapshotCmd.PersistentFlags().Lookup("recovery-file")) - viper.BindPFlag("snapshot.mode", stateSnapshotCmd.PersistentFlags().Lookup("snapshot-mode")) - viper.BindPFlag("file.outputDir", stateSnapshotCmd.PersistentFlags().Lookup("output-dir")) + viper.BindPFlag(snapshot.LVL_DB_PATH_TOML, stateSnapshotCmd.PersistentFlags().Lookup("leveldb-path")) + viper.BindPFlag(snapshot.ANCIENT_DB_PATH_TOML, stateSnapshotCmd.PersistentFlags().Lookup("ancient-path")) + viper.BindPFlag(snapshot.SNAPSHOT_BLOCK_HEIGHT_TOML, stateSnapshotCmd.PersistentFlags().Lookup("block-height")) + viper.BindPFlag(snapshot.SNAPSHOT_WORKERS_TOML, stateSnapshotCmd.PersistentFlags().Lookup("workers")) + viper.BindPFlag(snapshot.SNAPSHOT_RECOVERY_FILE_TOML, stateSnapshotCmd.PersistentFlags().Lookup("recovery-file")) + viper.BindPFlag(snapshot.SNAPSHOT_MODE_TOML, stateSnapshotCmd.PersistentFlags().Lookup("snapshot-mode")) + viper.BindPFlag(snapshot.FILE_OUTPUT_DIR_TOML, stateSnapshotCmd.PersistentFlags().Lookup("output-dir")) } diff --git a/environments/example.toml b/environments/example.toml index 6741edf..dda9e41 100644 --- a/environments/example.toml +++ b/environments/example.toml @@ -5,8 +5,12 @@ user = "postgres" [leveldb] - path = "/Users/user/Library/Ethereum/geth/chaindata" - ancient = "/Users/user/Library/Ethereum/geth/chaindata/ancient" + path = "/Users/iannorden/Library/Ethereum/geth/chaindata" + ancient = "/Users/iannorden/Library/Ethereum/geth/chaindata/ancient" + +[log] + level = "info" + file = "log_file" [snapshot] mode = "file" diff --git a/pkg/snapshot/config.go b/pkg/snapshot/config.go index ab48889..a9133fb 100644 --- a/pkg/snapshot/config.go +++ b/pkg/snapshot/config.go @@ -26,15 +26,6 @@ import ( "github.com/spf13/viper" ) -const ( - ANCIENT_DB_PATH = "ANCIENT_DB_PATH" - ETH_CLIENT_NAME = "ETH_CLIENT_NAME" - ETH_GENESIS_BLOCK = "ETH_GENESIS_BLOCK" - ETH_NETWORK_ID = "ETH_NETWORK_ID" - ETH_NODE_ID = "ETH_NODE_ID" - LVL_DB_PATH = "LVL_DB_PATH" -) - // SnapshotMode specifies the snapshot data output method type SnapshotMode string @@ -80,24 +71,25 @@ func NewConfig(mode SnapshotMode) (*Config, error) { // Init Initialises config func (c *Config) Init(mode SnapshotMode) error { - viper.BindEnv("ethereum.nodeID", ETH_NODE_ID) - viper.BindEnv("ethereum.clientName", ETH_CLIENT_NAME) - viper.BindEnv("ethereum.genesisBlock", ETH_GENESIS_BLOCK) - viper.BindEnv("ethereum.networkID", ETH_NETWORK_ID) + viper.BindEnv(ETH_NODE_ID_TOML, ETH_NODE_ID) + viper.BindEnv(ETH_CLIENT_NAME_TOML, ETH_CLIENT_NAME) + viper.BindEnv(ETH_GENESIS_BLOCK_TOML, ETH_GENESIS_BLOCK) + viper.BindEnv(ETH_NETWORK_ID_TOML, ETH_NETWORK_ID) + viper.BindEnv(ETH_CHAIN_ID_TOML, ETH_CHAIN_ID) c.Eth.NodeInfo = ethNode.Info{ - ID: viper.GetString("ethereum.nodeID"), - ClientName: viper.GetString("ethereum.clientName"), - GenesisBlock: viper.GetString("ethereum.genesisBlock"), - NetworkID: viper.GetString("ethereum.networkID"), - ChainID: viper.GetUint64("ethereum.chainID"), + ID: viper.GetString(ETH_NODE_ID_TOML), + ClientName: viper.GetString(ETH_CLIENT_NAME_TOML), + GenesisBlock: viper.GetString(ETH_GENESIS_BLOCK_TOML), + NetworkID: viper.GetString(ETH_NETWORK_ID_TOML), + ChainID: viper.GetUint64(ETH_CHAIN_ID_TOML), } - viper.BindEnv("leveldb.ancient", ANCIENT_DB_PATH) - viper.BindEnv("leveldb.path", LVL_DB_PATH) + viper.BindEnv(ANCIENT_DB_PATH_TOML, ANCIENT_DB_PATH) + viper.BindEnv(LVL_DB_PATH_TOML, LVL_DB_PATH) - c.Eth.AncientDBPath = viper.GetString("leveldb.ancient") - c.Eth.LevelDBPath = viper.GetString("leveldb.path") + c.Eth.AncientDBPath = viper.GetString(ANCIENT_DB_PATH_TOML) + c.Eth.LevelDBPath = viper.GetString(LVL_DB_PATH_TOML) switch mode { case FileSnapshot: @@ -111,34 +103,34 @@ func (c *Config) Init(mode SnapshotMode) error { } func (c *DBConfig) Init() { - viper.BindEnv("database.name", "DATABASE_NAME") - viper.BindEnv("database.hostname", "DATABASE_HOSTNAME") - viper.BindEnv("database.port", "DATABASE_PORT") - viper.BindEnv("database.user", "DATABASE_USER") - viper.BindEnv("database.password", "DATABASE_PASSWORD") - viper.BindEnv("database.maxIdle", "DATABASE_MAX_IDLE_CONNECTIONS") - viper.BindEnv("database.maxOpen", "DATABASE_MAX_OPEN_CONNECTIONS") - viper.BindEnv("database.maxLifetime", "DATABASE_MAX_CONN_LIFETIME") + viper.BindEnv(DATABASE_NAME_TOML, DATABASE_NAME) + viper.BindEnv(DATABASE_HOSTNAME_TOML, DATABASE_HOSTNAME) + viper.BindEnv(DATABASE_PORT_TOML, DATABASE_PORT) + viper.BindEnv(DATABASE_USER_TOML, DATABASE_USER) + viper.BindEnv(DATABASE_PASSWORD_TOML, DATABASE_PASSWORD) + viper.BindEnv(DATABASE_MAX_IDLE_CONNECTIONS_TOML, DATABASE_MAX_IDLE_CONNECTIONS) + viper.BindEnv(DATABASE_MAX_OPEN_CONNECTIONS_TOML, DATABASE_MAX_OPEN_CONNECTIONS) + viper.BindEnv(DATABASE_MAX_CONN_LIFETIME_TOML, DATABASE_MAX_CONN_LIFETIME) dbParams := postgres.Config{} // DB params - dbParams.DatabaseName = viper.GetString("database.name") - dbParams.Hostname = viper.GetString("database.hostname") - dbParams.Port = viper.GetInt("database.port") - dbParams.Username = viper.GetString("database.user") - dbParams.Password = viper.GetString("database.password") + dbParams.DatabaseName = viper.GetString(DATABASE_NAME_TOML) + dbParams.Hostname = viper.GetString(DATABASE_HOSTNAME_TOML) + dbParams.Port = viper.GetInt(DATABASE_PORT_TOML) + dbParams.Username = viper.GetString(DATABASE_USER_TOML) + dbParams.Password = viper.GetString(DATABASE_PASSWORD_TOML) // Connection config - dbParams.MaxIdle = viper.GetInt("database.maxIdle") - dbParams.MaxConns = viper.GetInt("database.maxOpen") - dbParams.MaxConnLifetime = time.Duration(viper.GetInt("database.maxLifetime")) * time.Second + dbParams.MaxIdle = viper.GetInt(DATABASE_MAX_IDLE_CONNECTIONS_TOML) + dbParams.MaxConns = viper.GetInt(DATABASE_MAX_OPEN_CONNECTIONS_TOML) + dbParams.MaxConnLifetime = time.Duration(viper.GetInt(DATABASE_MAX_CONN_LIFETIME_TOML)) * time.Second c.ConnConfig = dbParams c.URI = dbParams.DbConnectionString() } func (c *FileConfig) Init() error { - viper.BindEnv("file.outputDir", "FILE_OUTPUT_DIR") - c.OutputDir = viper.GetString("file.outputDir") + viper.BindEnv(FILE_OUTPUT_DIR_TOML, FILE_OUTPUT_DIR) + c.OutputDir = viper.GetString(FILE_OUTPUT_DIR_TOML) if c.OutputDir == "" { logrus.Infof("no output directory set, using default: %s", defaultOutputDir) c.OutputDir = defaultOutputDir diff --git a/pkg/snapshot/env.go b/pkg/snapshot/env.go new file mode 100644 index 0000000..99935a0 --- /dev/null +++ b/pkg/snapshot/env.go @@ -0,0 +1,82 @@ +// Copyright © 2020 Vulcanize, Inc +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package snapshot + +/* + viper.BindPFlag("snapshot.blockHeight", stateSnapshotCmd.PersistentFlags().Lookup("block-height")) + viper.BindPFlag("snapshot.workers", stateSnapshotCmd.PersistentFlags().Lookup("workers")) + viper.BindPFlag("snapshot.recoveryFile", stateSnapshotCmd.PersistentFlags().Lookup("recovery-file")) + viper.BindPFlag("snapshot.mode", stateSnapshotCmd.PersistentFlags().Lookup("snapshot-mode")) +*/ +const ( + SNAPSHOT_BLOCK_HEIGHT = "SNAPSHOT_BLOCK_HEIGHT" + SNAPSHOT_WORKERS = "SNAPSHOT_WORKERS" + SNAPSHOT_RECOVERY_FILE = "SNAPSHOT_RECOVERY_FILE" + SNAPSHOT_MODE = "SNAPSHOT_MODE" + + LOGRUS_LEVEL = "LOGRUS_LEVEL" + LOGRUS_FILE = "LOGRUS_FILE" + + FILE_OUTPUT_DIR = "FILE_OUTPUT_DIR" + + ANCIENT_DB_PATH = "ANCIENT_DB_PATH" + LVL_DB_PATH = "LVL_DB_PATH" + + ETH_CLIENT_NAME = "ETH_CLIENT_NAME" + ETH_GENESIS_BLOCK = "ETH_GENESIS_BLOCK" + ETH_NETWORK_ID = "ETH_NETWORK_ID" + ETH_NODE_ID = "ETH_NODE_ID" + ETH_CHAIN_ID = "ETH_CHAIN_ID" + + DATABASE_NAME = "DATABASE_NAME" + DATABASE_HOSTNAME = "DATABASE_HOSTNAME" + DATABASE_PORT = "DATABASE_PORT" + DATABASE_USER = "DATABASE_USER" + DATABASE_PASSWORD = "DATABASE_PASSWORD" + DATABASE_MAX_IDLE_CONNECTIONS = "DATABASE_MAX_IDLE_CONNECTIONS" + DATABASE_MAX_OPEN_CONNECTIONS = "DATABASE_MAX_OPEN_CONNECTIONS" + DATABASE_MAX_CONN_LIFETIME = "DATABASE_MAX_CONN_LIFETIME" +) + +const ( + SNAPSHOT_BLOCK_HEIGHT_TOML = "snapshot.blockHeight" + SNAPSHOT_WORKERS_TOML = "snapshot.workers" + SNAPSHOT_RECOVERY_FILE_TOML = "snapshot.recoveryFile" + SNAPSHOT_MODE_TOML = "snapshot.mode" + + LOGRUS_LEVEL_TOML = "log.level" + LOGRUS_FILE_TOML = "log.file" + + FILE_OUTPUT_DIR_TOML = "file.outputDir" + + ANCIENT_DB_PATH_TOML = "leveldb.ancient" + LVL_DB_PATH_TOML = "leveldb.path" + + ETH_CLIENT_NAME_TOML = "ethereum.clientName" + ETH_GENESIS_BLOCK_TOML = "ethereum.genesisBlock" + ETH_NETWORK_ID_TOML = "ethereum.networkID" + ETH_NODE_ID_TOML = "ethereum.nodeID" + ETH_CHAIN_ID_TOML = "ethereum.chainID" + + DATABASE_NAME_TOML = "database.name" + DATABASE_HOSTNAME_TOML = "database.hostname" + DATABASE_PORT_TOML = "database.port" + DATABASE_USER_TOML = "database.user" + DATABASE_PASSWORD_TOML = "database.password" + DATABASE_MAX_IDLE_CONNECTIONS_TOML = "database.maxIdle" + DATABASE_MAX_OPEN_CONNECTIONS_TOML = "database.maxOpen" + DATABASE_MAX_CONN_LIFETIME_TOML = "database.maxLifetime" +) diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index bdd7bdc..efe8f62 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -55,8 +55,6 @@ type Service struct { } func NewLevelDB(con *EthConfig) (ethdb.Database, error) { - println(con.LevelDBPath) - println(con.AncientDBPath) edb, err := rawdb.NewLevelDBDatabaseWithFreezer( con.LevelDBPath, 1024, 256, con.AncientDBPath, "ipld-eth-state-snapshot", true, ) diff --git a/pkg/snapshot/tracker.go b/pkg/snapshot/tracker.go index 8f7d643..1e5fbdf 100644 --- a/pkg/snapshot/tracker.go +++ b/pkg/snapshot/tracker.go @@ -87,7 +87,7 @@ func (tr *iteratorTracker) tracked(it trie.NodeIterator) (ret *trackedIter) { // dumps iterator path and bounds to a text file so it can be restored later func (tr *iteratorTracker) dump() error { - log.Info("Dumping recovery state to:", tr.recoveryFile) + log.Info("Dumping recovery state to: ", tr.recoveryFile) var rows [][]string for it, _ := range tr.started { var endPath []byte From 004f3e6665959e0de28b58ec6b8be34ce0c89807 Mon Sep 17 00:00:00 2001 From: i-norden Date: Tue, 17 May 2022 22:23:38 -0500 Subject: [PATCH 2/3] constants for CLI binding strings --- cmd/root.go | 36 ++++++++++++++++++------------------ cmd/stateSnapshot.go | 36 ++++++++++++++++++------------------ pkg/snapshot/env.go | 39 +++++++++++++++++++++++++++++++++------ 3 files changed, 69 insertions(+), 42 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 9b10a29..33e54e8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,11 +21,11 @@ import ( "os" "strings" - "github.com/vulcanize/ipld-eth-state-snapshot/pkg/snapshot" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" + + "github.com/vulcanize/ipld-eth-state-snapshot/pkg/snapshot" ) var ( @@ -48,7 +48,7 @@ func Execute() { } func initFuncs(cmd *cobra.Command, args []string) { - logfile := viper.GetString("log.file") + logfile := viper.GetString(snapshot.LOGRUS_FILE_TOML) if logfile != "" { file, err := os.OpenFile(logfile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) @@ -68,7 +68,7 @@ func initFuncs(cmd *cobra.Command, args []string) { } func logLevel() error { - lvl, err := log.ParseLevel(viper.GetString("log.level")) + lvl, err := log.ParseLevel(viper.GetString(snapshot.LOGRUS_LEVEL_TOML)) if err != nil { return err } @@ -86,21 +86,21 @@ func init() { viper.AutomaticEnv() rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file location") - rootCmd.PersistentFlags().String("log-file", "", "file path for logging") - rootCmd.PersistentFlags().String("database-name", "vulcanize_public", "database name") - rootCmd.PersistentFlags().Int("database-port", 5432, "database port") - rootCmd.PersistentFlags().String("database-hostname", "localhost", "database hostname") - rootCmd.PersistentFlags().String("database-user", "", "database user") - rootCmd.PersistentFlags().String("database-password", "", "database password") - rootCmd.PersistentFlags().String("log-level", log.InfoLevel.String(), "Log level (trace, debug, info, warn, error, fatal, panic") + rootCmd.PersistentFlags().String(snapshot.LOGRUS_FILE_CLI, "", "file path for logging") + rootCmd.PersistentFlags().String(snapshot.DATABASE_NAME_CLI, "vulcanize_public", "database name") + rootCmd.PersistentFlags().Int(snapshot.DATABASE_PORT_CLI, 5432, "database port") + rootCmd.PersistentFlags().String(snapshot.DATABASE_HOSTNAME_CLI, "localhost", "database hostname") + rootCmd.PersistentFlags().String(snapshot.DATABASE_USER_CLI, "", "database user") + rootCmd.PersistentFlags().String(snapshot.DATABASE_PASSWORD_CLI, "", "database password") + rootCmd.PersistentFlags().String(snapshot.LOGRUS_LEVEL_CLI, log.InfoLevel.String(), "log level (trace, debug, info, warn, error, fatal, panic") - viper.BindPFlag(snapshot.LOGRUS_FILE_TOML, rootCmd.PersistentFlags().Lookup("log-file")) - viper.BindPFlag(snapshot.DATABASE_NAME_TOML, rootCmd.PersistentFlags().Lookup("database-name")) - viper.BindPFlag(snapshot.DATABASE_PORT_TOML, rootCmd.PersistentFlags().Lookup("database-port")) - viper.BindPFlag(snapshot.DATABASE_HOSTNAME_TOML, rootCmd.PersistentFlags().Lookup("database-hostname")) - viper.BindPFlag(snapshot.DATABASE_USER_TOML, rootCmd.PersistentFlags().Lookup("database-user")) - viper.BindPFlag(snapshot.DATABASE_PASSWORD_TOML, rootCmd.PersistentFlags().Lookup("database-password")) - viper.BindPFlag(snapshot.LOGRUS_LEVEL_TOML, rootCmd.PersistentFlags().Lookup("log-level")) + viper.BindPFlag(snapshot.LOGRUS_FILE_TOML, rootCmd.PersistentFlags().Lookup(snapshot.LOGRUS_FILE_CLI)) + viper.BindPFlag(snapshot.DATABASE_NAME_TOML, rootCmd.PersistentFlags().Lookup(snapshot.DATABASE_NAME_CLI)) + viper.BindPFlag(snapshot.DATABASE_PORT_TOML, rootCmd.PersistentFlags().Lookup(snapshot.DATABASE_PORT_CLI)) + viper.BindPFlag(snapshot.DATABASE_HOSTNAME_TOML, rootCmd.PersistentFlags().Lookup(snapshot.DATABASE_HOSTNAME_CLI)) + viper.BindPFlag(snapshot.DATABASE_USER_TOML, rootCmd.PersistentFlags().Lookup(snapshot.DATABASE_USER_CLI)) + viper.BindPFlag(snapshot.DATABASE_PASSWORD_TOML, rootCmd.PersistentFlags().Lookup(snapshot.DATABASE_PASSWORD_CLI)) + viper.BindPFlag(snapshot.LOGRUS_LEVEL_TOML, rootCmd.PersistentFlags().Lookup(snapshot.LOGRUS_LEVEL_CLI)) } func initConfig() { diff --git a/cmd/stateSnapshot.go b/cmd/stateSnapshot.go index 732befa..c44d84e 100644 --- a/cmd/stateSnapshot.go +++ b/cmd/stateSnapshot.go @@ -40,7 +40,7 @@ var stateSnapshotCmd = &cobra.Command{ } func stateSnapshot() { - modeStr := viper.GetString("snapshot.mode") + modeStr := viper.GetString(snapshot.SNAPSHOT_MODE_TOML) mode := snapshot.SnapshotMode(modeStr) config, err := snapshot.NewConfig(mode) if err != nil { @@ -52,8 +52,8 @@ func stateSnapshot() { if err != nil { logWithCommand.Fatal(err) } - height := viper.GetInt64("snapshot.blockHeight") - recoveryFile := viper.GetString("snapshot.recoveryFile") + height := viper.GetInt64(snapshot.SNAPSHOT_BLOCK_HEIGHT_TOML) + recoveryFile := viper.GetString(snapshot.SNAPSHOT_RECOVERY_FILE_TOML) if recoveryFile == "" { recoveryFile = fmt.Sprintf("./%d_snapshot_recovery", height) logWithCommand.Infof("no recovery file set, creating default: %s", recoveryFile) @@ -68,7 +68,7 @@ func stateSnapshot() { if err != nil { logWithCommand.Fatal(err) } - workers := viper.GetUint("snapshot.workers") + workers := viper.GetUint(snapshot.SNAPSHOT_WORKERS_TOML) if height < 0 { if err := snapshotService.CreateLatestSnapshot(workers); err != nil { @@ -86,19 +86,19 @@ func stateSnapshot() { func init() { rootCmd.AddCommand(stateSnapshotCmd) - stateSnapshotCmd.PersistentFlags().String("leveldb-path", "", "path to primary datastore") - stateSnapshotCmd.PersistentFlags().String("ancient-path", "", "path to ancient datastore") - stateSnapshotCmd.PersistentFlags().String("block-height", "", "blockheight to extract state at") - stateSnapshotCmd.PersistentFlags().Int("workers", 1, "number of concurrent workers to use") - stateSnapshotCmd.PersistentFlags().String("recovery-file", "", "file to recover from a previous iteration") - stateSnapshotCmd.PersistentFlags().String("snapshot-mode", "postgres", "output mode for snapshot ('file' or 'postgres')") - stateSnapshotCmd.PersistentFlags().String("output-dir", "", "directory for writing ouput to while operating in 'file' mode") + stateSnapshotCmd.PersistentFlags().String(snapshot.LVL_DB_PATH_CLI, "", "path to primary datastore") + stateSnapshotCmd.PersistentFlags().String(snapshot.ANCIENT_DB_PATH_CLI, "", "path to ancient datastore") + stateSnapshotCmd.PersistentFlags().String(snapshot.SNAPSHOT_BLOCK_HEIGHT_CLI, "", "block height to extract state at") + stateSnapshotCmd.PersistentFlags().Int(snapshot.SNAPSHOT_WORKERS_CLI, 1, "number of concurrent workers to use") + stateSnapshotCmd.PersistentFlags().String(snapshot.SNAPSHOT_RECOVERY_FILE_CLI, "", "file to recover from a previous iteration") + stateSnapshotCmd.PersistentFlags().String(snapshot.SNAPSHOT_MODE_CLI, "postgres", "output mode for snapshot ('file' or 'postgres')") + stateSnapshotCmd.PersistentFlags().String(snapshot.FILE_OUTPUT_DIR_CLI, "", "directory for writing ouput to while operating in 'file' mode") - viper.BindPFlag(snapshot.LVL_DB_PATH_TOML, stateSnapshotCmd.PersistentFlags().Lookup("leveldb-path")) - viper.BindPFlag(snapshot.ANCIENT_DB_PATH_TOML, stateSnapshotCmd.PersistentFlags().Lookup("ancient-path")) - viper.BindPFlag(snapshot.SNAPSHOT_BLOCK_HEIGHT_TOML, stateSnapshotCmd.PersistentFlags().Lookup("block-height")) - viper.BindPFlag(snapshot.SNAPSHOT_WORKERS_TOML, stateSnapshotCmd.PersistentFlags().Lookup("workers")) - viper.BindPFlag(snapshot.SNAPSHOT_RECOVERY_FILE_TOML, stateSnapshotCmd.PersistentFlags().Lookup("recovery-file")) - viper.BindPFlag(snapshot.SNAPSHOT_MODE_TOML, stateSnapshotCmd.PersistentFlags().Lookup("snapshot-mode")) - viper.BindPFlag(snapshot.FILE_OUTPUT_DIR_TOML, stateSnapshotCmd.PersistentFlags().Lookup("output-dir")) + viper.BindPFlag(snapshot.LVL_DB_PATH_TOML, stateSnapshotCmd.PersistentFlags().Lookup(snapshot.LVL_DB_PATH_CLI)) + viper.BindPFlag(snapshot.ANCIENT_DB_PATH_TOML, stateSnapshotCmd.PersistentFlags().Lookup(snapshot.ANCIENT_DB_PATH_CLI)) + viper.BindPFlag(snapshot.SNAPSHOT_BLOCK_HEIGHT_TOML, stateSnapshotCmd.PersistentFlags().Lookup(snapshot.SNAPSHOT_BLOCK_HEIGHT_CLI)) + viper.BindPFlag(snapshot.SNAPSHOT_WORKERS_TOML, stateSnapshotCmd.PersistentFlags().Lookup(snapshot.SNAPSHOT_WORKERS_CLI)) + viper.BindPFlag(snapshot.SNAPSHOT_RECOVERY_FILE_TOML, stateSnapshotCmd.PersistentFlags().Lookup(snapshot.SNAPSHOT_RECOVERY_FILE_CLI)) + viper.BindPFlag(snapshot.SNAPSHOT_MODE_TOML, stateSnapshotCmd.PersistentFlags().Lookup(snapshot.SNAPSHOT_MODE_CLI)) + viper.BindPFlag(snapshot.FILE_OUTPUT_DIR_TOML, stateSnapshotCmd.PersistentFlags().Lookup(snapshot.FILE_OUTPUT_DIR_CLI)) } diff --git a/pkg/snapshot/env.go b/pkg/snapshot/env.go index 99935a0..b851ceb 100644 --- a/pkg/snapshot/env.go +++ b/pkg/snapshot/env.go @@ -15,12 +15,7 @@ package snapshot -/* - viper.BindPFlag("snapshot.blockHeight", stateSnapshotCmd.PersistentFlags().Lookup("block-height")) - viper.BindPFlag("snapshot.workers", stateSnapshotCmd.PersistentFlags().Lookup("workers")) - viper.BindPFlag("snapshot.recoveryFile", stateSnapshotCmd.PersistentFlags().Lookup("recovery-file")) - viper.BindPFlag("snapshot.mode", stateSnapshotCmd.PersistentFlags().Lookup("snapshot-mode")) -*/ +// ENV variables const ( SNAPSHOT_BLOCK_HEIGHT = "SNAPSHOT_BLOCK_HEIGHT" SNAPSHOT_WORKERS = "SNAPSHOT_WORKERS" @@ -51,6 +46,7 @@ const ( DATABASE_MAX_CONN_LIFETIME = "DATABASE_MAX_CONN_LIFETIME" ) +// TOML bindings const ( SNAPSHOT_BLOCK_HEIGHT_TOML = "snapshot.blockHeight" SNAPSHOT_WORKERS_TOML = "snapshot.workers" @@ -80,3 +76,34 @@ const ( DATABASE_MAX_OPEN_CONNECTIONS_TOML = "database.maxOpen" DATABASE_MAX_CONN_LIFETIME_TOML = "database.maxLifetime" ) + +// CLI flags +const ( + SNAPSHOT_BLOCK_HEIGHT_CLI = "block-height" + SNAPSHOT_WORKERS_CLI = "workers" + SNAPSHOT_RECOVERY_FILE_CLI = "recovery-file" + SNAPSHOT_MODE_CLI = "snapshot-mode" + + LOGRUS_LEVEL_CLI = "log-level" + LOGRUS_FILE_CLI = "log-file" + + FILE_OUTPUT_DIR_CLI = "output-dir" + + ANCIENT_DB_PATH_CLI = "ancient-path" + LVL_DB_PATH_CLI = "leveldb-path" + + ETH_CLIENT_NAME_CLI = "ethereum-client-name" + ETH_GENESIS_BLOCK_CLI = "ethereum-genesis-block" + ETH_NETWORK_ID_CLI = "ethereum-network-id" + ETH_NODE_ID_CLI = "ethereum-node-id" + ETH_CHAIN_ID_CLI = "ethereum-chain-id" + + DATABASE_NAME_CLI = "database-name" + DATABASE_HOSTNAME_CLI = "database-hostname" + DATABASE_PORT_CLI = "database-port" + DATABASE_USER_CLI = "database-user" + DATABASE_PASSWORD_CLI = "database-password" + DATABASE_MAX_IDLE_CONNECTIONS_CLI = "database-max-idle" + DATABASE_MAX_OPEN_CONNECTIONS_CLI = "database-max-open" + DATABASE_MAX_CONN_LIFETIME_CLI = "database-max-lifetime" +) From cce45bda57bb5b07b85854d9f38add4d5dff8ceb Mon Sep 17 00:00:00 2001 From: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Date: Mon, 23 May 2022 16:56:48 +0530 Subject: [PATCH 3/3] Add prometheus metrics collection (#33) * Upgrade geth * Add prometheus metrics collection * Update README --- Makefile | 4 + README.md | 13 ++- cmd/root.go | 31 +++++- environments/example.toml | 7 ++ go.mod | 8 +- go.sum | 70 ++++++++++--- pkg/prom/db_stats_collector.go | 157 ++++++++++++++++++++++++++++ pkg/prom/prom.go | 90 ++++++++++++++++ pkg/prom/serve.go | 47 +++++++++ pkg/snapshot/env.go | 18 ++++ pkg/snapshot/file/publisher.go | 7 ++ pkg/snapshot/file/publisher_test.go | 1 + pkg/snapshot/pg/publisher.go | 4 + pkg/snapshot/service.go | 3 +- pkg/snapshot/util.go | 4 + 15 files changed, 443 insertions(+), 21 deletions(-) create mode 100644 pkg/prom/db_stats_collector.go create mode 100644 pkg/prom/prom.go create mode 100644 pkg/prom/serve.go diff --git a/Makefile b/Makefile index 76d7f0c..eebd422 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,7 @@ mocks/snapshot/publisher.go: pkg/types/publisher.go clean: rm -f mocks/snapshot/publisher.go + +build: + go fmt ./... + go build diff --git a/README.md b/README.md index 01fda86..1c0bed2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/vulcanize/ipld-eth-state-snapshot)](https://goreportcard.com/report/github.com/vulcanize/ipld-eth-state-snapshot) -## Usage +## Usage ./ipld-eth-state-snapshot stateSnapshot --config={path to toml config file} @@ -32,4 +32,15 @@ Config format: [file] outputDir = "output_dir/" # when operating in 'file' output mode, this is the directory the files are written to + +[log] + level = "info" # log level (trace, debug, info, warn, error, fatal, panic) (default: info) + file = "log_file" # file path for logging + +[prom] + metrics = true # enable prometheus metrics (default: false) + http = true # enable prometheus http service (default: false) + httpAddr = "0.0.0.0" # prometheus http host (default: 127.0.0.1) + httpPort = 9101 # prometheus http port (default: 8086) + dbStats = true # enable prometheus db stats (default: false) ``` diff --git a/cmd/root.go b/cmd/root.go index 33e54e8..b4bd74e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -25,6 +25,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/vulcanize/ipld-eth-state-snapshot/pkg/prom" "github.com/vulcanize/ipld-eth-state-snapshot/pkg/snapshot" ) @@ -65,6 +66,21 @@ func initFuncs(cmd *cobra.Command, args []string) { if err := logLevel(); err != nil { log.Fatal("Could not set log level: ", err) } + + if viper.GetBool(snapshot.PROM_METRICS_TOML) { + log.Info("initializing prometheus metrics") + prom.Init() + } + + if viper.GetBool(snapshot.PROM_HTTP_TOML) { + addr := fmt.Sprintf( + "%s:%s", + viper.GetString(snapshot.PROM_HTTP_ADDR_TOML), + viper.GetString(snapshot.PROM_HTTP_PORT_TOML), + ) + log.Info("starting prometheus server") + prom.Serve(addr) + } } func logLevel() error { @@ -77,6 +93,7 @@ func logLevel() error { log.SetReportCaller(true) } log.Info("Log level set to ", lvl.String()) + return nil } @@ -92,7 +109,13 @@ func init() { rootCmd.PersistentFlags().String(snapshot.DATABASE_HOSTNAME_CLI, "localhost", "database hostname") rootCmd.PersistentFlags().String(snapshot.DATABASE_USER_CLI, "", "database user") rootCmd.PersistentFlags().String(snapshot.DATABASE_PASSWORD_CLI, "", "database password") - rootCmd.PersistentFlags().String(snapshot.LOGRUS_LEVEL_CLI, log.InfoLevel.String(), "log level (trace, debug, info, warn, error, fatal, panic") + rootCmd.PersistentFlags().String(snapshot.LOGRUS_LEVEL_CLI, log.InfoLevel.String(), "log level (trace, debug, info, warn, error, fatal, panic)") + + rootCmd.PersistentFlags().Bool(snapshot.PROM_METRICS_CLI, false, "enable prometheus metrics") + rootCmd.PersistentFlags().Bool(snapshot.PROM_HTTP_CLI, false, "enable prometheus http service") + rootCmd.PersistentFlags().String(snapshot.PROM_HTTP_ADDR_CLI, "127.0.0.1", "prometheus http host") + rootCmd.PersistentFlags().String(snapshot.PROM_HTTP_PORT_CLI, "8086", "prometheus http port") + rootCmd.PersistentFlags().Bool(snapshot.PROM_DB_STATS_CLI, false, "enables prometheus db stats") viper.BindPFlag(snapshot.LOGRUS_FILE_TOML, rootCmd.PersistentFlags().Lookup(snapshot.LOGRUS_FILE_CLI)) viper.BindPFlag(snapshot.DATABASE_NAME_TOML, rootCmd.PersistentFlags().Lookup(snapshot.DATABASE_NAME_CLI)) @@ -101,6 +124,12 @@ func init() { viper.BindPFlag(snapshot.DATABASE_USER_TOML, rootCmd.PersistentFlags().Lookup(snapshot.DATABASE_USER_CLI)) viper.BindPFlag(snapshot.DATABASE_PASSWORD_TOML, rootCmd.PersistentFlags().Lookup(snapshot.DATABASE_PASSWORD_CLI)) viper.BindPFlag(snapshot.LOGRUS_LEVEL_TOML, rootCmd.PersistentFlags().Lookup(snapshot.LOGRUS_LEVEL_CLI)) + + viper.BindPFlag(snapshot.PROM_METRICS_TOML, rootCmd.PersistentFlags().Lookup(snapshot.PROM_METRICS_CLI)) + viper.BindPFlag(snapshot.PROM_HTTP_TOML, rootCmd.PersistentFlags().Lookup(snapshot.PROM_HTTP_CLI)) + viper.BindPFlag(snapshot.PROM_HTTP_ADDR_TOML, rootCmd.PersistentFlags().Lookup(snapshot.PROM_HTTP_ADDR_CLI)) + viper.BindPFlag(snapshot.PROM_HTTP_PORT_TOML, rootCmd.PersistentFlags().Lookup(snapshot.PROM_HTTP_PORT_CLI)) + viper.BindPFlag(snapshot.PROM_DB_STATS_TOML, rootCmd.PersistentFlags().Lookup(snapshot.PROM_DB_STATS_CLI)) } func initConfig() { diff --git a/environments/example.toml b/environments/example.toml index dda9e41..d3d181a 100644 --- a/environments/example.toml +++ b/environments/example.toml @@ -12,6 +12,13 @@ level = "info" file = "log_file" +[prom] + metrics = true + http = true + httpAddr = "0.0.0.0" + httpPort = 9101 + dbStats = true + [snapshot] mode = "file" workers = 4 diff --git a/go.mod b/go.mod index 0a16f70..149553b 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,10 @@ module github.com/vulcanize/ipld-eth-state-snapshot go 1.15 require ( - github.com/btcsuite/btcd v0.22.0-beta // indirect + github.com/btcsuite/btcd v0.22.1 // indirect + github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect - github.com/ethereum/go-ethereum v1.10.16 + github.com/ethereum/go-ethereum v1.10.17 github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/go-kit/kit v0.10.0 // indirect github.com/golang/mock v1.6.0 @@ -24,6 +25,7 @@ require ( github.com/multiformats/go-multihash v0.1.0 github.com/onsi/ginkgo v1.16.5 // indirect github.com/onsi/gomega v1.13.0 // indirect + github.com/prometheus/client_golang v1.3.0 github.com/sirupsen/logrus v1.6.0 github.com/smartystreets/assertions v1.0.0 // indirect github.com/spf13/cobra v1.0.0 @@ -43,4 +45,4 @@ require ( lukechampine.com/blake3 v1.1.7 // indirect ) -replace github.com/ethereum/go-ethereum v1.10.16 => github.com/vulcanize/go-ethereum v1.10.16-statediff-3.0.2 +replace github.com/ethereum/go-ethereum v1.10.17 => github.com/vulcanize/go-ethereum v1.10.17-statediff-3.2.1 diff --git a/go.sum b/go.sum index 5530067..0eeaba2 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,9 @@ collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= +github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo= github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4= github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= @@ -47,6 +50,7 @@ github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrU github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= +github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= @@ -81,23 +85,38 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= +github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= -github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrfdnWo= -github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA= +github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= +github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= +github.com/btcsuite/btcd/btcec/v2 v2.1.2/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= +github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= +github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4= github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJGQE= github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0 h1:J9B4L7e3oqhXOcm+2IuNApwzQec85lE+QaikUcCs+dk= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= @@ -144,9 +163,14 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea h1:j4317fAZh7X6GqbFowYdYdI0L9bwxL07jyPZIdepyZ0= github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= +github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= +github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= +github.com/decred/dcrd/lru v1.0.0 h1:Kbsb1SFDsIlaupWPwsPp+dkxiBY1frcS07PCPgotKz8= github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M= github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw= @@ -155,6 +179,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8/go.mod h1:VMaSuZ+SZcx/wljOQKvp5srsbCiKDEb6K2wC4+PiBmQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= +github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= @@ -223,6 +249,8 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog= +github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= @@ -262,6 +290,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= @@ -276,6 +305,7 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4 github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -335,8 +365,9 @@ github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= -github.com/huin/goupnp v1.0.2 h1:RfGLP+h3mvisuWEyybxNq5Eft3NWhHLPeUN72kpKZoI= github.com/huin/goupnp v1.0.2/go.mod h1:0dxJBVBHqTMjIUMkESDTNgOOx/Mw5wYIfyFmdzSamkM= +github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204 h1:+EYBkW+dbi3F/atB+LSQZSWh7+HNrV3A/N0y6DSoy9k= +github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= @@ -396,7 +427,6 @@ github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9 github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= -github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ= github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA= github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s= @@ -469,8 +499,8 @@ github.com/jackc/puddle v1.1.2/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.2.1 h1:gI8os0wpRXFd4FiAY2dWiqRK037tjj3t7rKFeO4X5iw= github.com/jackc/puddle v1.2.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 h1:6OvNmYgJyexcZ3pYbTI9jWx5tHo1Dee/tWbLMfPe2TA= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY= @@ -478,6 +508,7 @@ github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0 github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= @@ -488,6 +519,7 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/jrick/logrotate v1.0.0 h1:lQ1bL/n9mBNeIXoTUoYRlK4dHuNJVofX9oWqBtPnSzI= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -506,6 +538,7 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 h1:FOOIBWrEkLgmlgGfMuZT83xIwfPDxEI2OHu6xUmJMFE= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5 h1:2U0HzY8BJ8hVwDKIzp7y4voR9CX/nvcfymLmg2UiOio= @@ -579,6 +612,7 @@ github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsO github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw= github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= @@ -603,6 +637,7 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= @@ -678,6 +713,7 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9 github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= +github.com/pganalyze/pg_query_go/v2 v2.1.0/go.mod h1:XAxmVqz1tEGqizcQ3YSdN90vCOHBWjJi8URL1er5+cA= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= @@ -694,22 +730,26 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.3.0 h1:miYCvYqFXtl/J9FIy8eNpBfYthAEFg+Ys0XyUVEcDsc= github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.1.0 h1:ElTg5tNp4DqfV7UQjDqv2+RJlNzsDtvNAWccbItceIE= github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= +github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= @@ -792,6 +832,7 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= +github.com/thoas/go-funk v0.9.2/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= @@ -808,14 +849,10 @@ github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/X github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -github.com/vulcanize/go-eth-state-node-iterator v1.0.0 h1:FQ4s0K5TnRD44p3vO4uQtjfE8C1Gr2EDMT2vVGS3Lu8= -github.com/vulcanize/go-eth-state-node-iterator v1.0.0/go.mod h1:uWhleTvUEZ+cEkNRIAmBpZ14KilTP71OxY5NZDrpNlo= github.com/vulcanize/go-eth-state-node-iterator v1.0.1 h1:lI8+moQ0Nv62NwmiCxgvWkC/Wj46KmDPX1dhBwyqRy8= github.com/vulcanize/go-eth-state-node-iterator v1.0.1/go.mod h1:uWhleTvUEZ+cEkNRIAmBpZ14KilTP71OxY5NZDrpNlo= -github.com/vulcanize/go-ethereum v1.10.15-statediff-3.0.1 h1:MX7WcTwxpxOoYVMifrs9vsHDmM6gKOFF+2KnP19LddI= -github.com/vulcanize/go-ethereum v1.10.15-statediff-3.0.1/go.mod h1:XO9WLkNXfwoJN05BZj0//xgOWHJyUrUPdnudbQfKlUo= -github.com/vulcanize/go-ethereum v1.10.16-statediff-3.0.2 h1:H3SLHZdvTyKYbFc1CO2b8A9XF3BcakcXtvThKPbgT8k= -github.com/vulcanize/go-ethereum v1.10.16-statediff-3.0.2/go.mod h1:NI+tCVeIQBPrMfJUZvTLjhCieb7CZcmNPbJVlXbncxU= +github.com/vulcanize/go-ethereum v1.10.17-statediff-3.2.1 h1:BUIaiqqsWM61KfzIowqrGJ8TM2SWwmral4iJ/nhTSe0= +github.com/vulcanize/go-ethereum v1.10.17-statediff-3.2.1/go.mod h1:mDwZX+QoWdqzQo6SDG3YVqCYACutcSG6uzpziMvTu28= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= @@ -885,6 +922,7 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b h1:QAqMVf3pSa6eeTsuklijukjXBlj7Es2QQplab+/RbQ4= golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -897,6 +935,7 @@ golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm0 golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20220426173459-3bcf042a4bf5/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= @@ -918,8 +957,9 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 h1:LQmS1nU0twXLA96Kt7U9qtHJEbBk3z6Q0V4UXjZkpr4= +golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -947,12 +987,14 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -1085,8 +1127,8 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w= golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/prom/db_stats_collector.go b/pkg/prom/db_stats_collector.go new file mode 100644 index 0000000..ea5efa6 --- /dev/null +++ b/pkg/prom/db_stats_collector.go @@ -0,0 +1,157 @@ +// VulcanizeDB +// Copyright © 2022 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package prom + +import ( + "github.com/prometheus/client_golang/prometheus" + + "github.com/ethereum/go-ethereum/statediff/indexer/database/sql" +) + +// DBStatsGetter is an interface that gets sql.DBStats. +type DBStatsGetter interface { + Stats() sql.Stats +} + +// DBStatsCollector implements the prometheus.Collector interface. +type DBStatsCollector struct { + sg DBStatsGetter + + // descriptions of exported metrics + maxOpenDesc *prometheus.Desc + openDesc *prometheus.Desc + inUseDesc *prometheus.Desc + idleDesc *prometheus.Desc + waitedForDesc *prometheus.Desc + blockedSecondsDesc *prometheus.Desc + closedMaxIdleDesc *prometheus.Desc + closedMaxLifetimeDesc *prometheus.Desc +} + +// NewDBStatsCollector creates a new DBStatsCollector. +func NewDBStatsCollector(dbName string, sg DBStatsGetter) *DBStatsCollector { + labels := prometheus.Labels{"db_name": dbName} + return &DBStatsCollector{ + sg: sg, + maxOpenDesc: prometheus.NewDesc( + prometheus.BuildFQName(namespace, connSubsystem, "max_open"), + "Maximum number of open connections to the database.", + nil, + labels, + ), + openDesc: prometheus.NewDesc( + prometheus.BuildFQName(namespace, connSubsystem, "open"), + "The number of established connections both in use and idle.", + nil, + labels, + ), + inUseDesc: prometheus.NewDesc( + prometheus.BuildFQName(namespace, connSubsystem, "in_use"), + "The number of connections currently in use.", + nil, + labels, + ), + idleDesc: prometheus.NewDesc( + prometheus.BuildFQName(namespace, connSubsystem, "idle"), + "The number of idle connections.", + nil, + labels, + ), + waitedForDesc: prometheus.NewDesc( + prometheus.BuildFQName(namespace, connSubsystem, "waited_for"), + "The total number of connections waited for.", + nil, + labels, + ), + blockedSecondsDesc: prometheus.NewDesc( + prometheus.BuildFQName(namespace, connSubsystem, "blocked_seconds"), + "The total time blocked waiting for a new connection.", + nil, + labels, + ), + closedMaxIdleDesc: prometheus.NewDesc( + prometheus.BuildFQName(namespace, connSubsystem, "closed_max_idle"), + "The total number of connections closed due to SetMaxIdleConns.", + nil, + labels, + ), + closedMaxLifetimeDesc: prometheus.NewDesc( + prometheus.BuildFQName(namespace, connSubsystem, "closed_max_lifetime"), + "The total number of connections closed due to SetConnMaxLifetime.", + nil, + labels, + ), + } +} + +// Describe implements the prometheus.Collector interface. +func (c DBStatsCollector) Describe(ch chan<- *prometheus.Desc) { + ch <- c.maxOpenDesc + ch <- c.openDesc + ch <- c.inUseDesc + ch <- c.idleDesc + ch <- c.waitedForDesc + ch <- c.blockedSecondsDesc + ch <- c.closedMaxIdleDesc + ch <- c.closedMaxLifetimeDesc +} + +// Collect implements the prometheus.Collector interface. +func (c DBStatsCollector) Collect(ch chan<- prometheus.Metric) { + stats := c.sg.Stats() + + ch <- prometheus.MustNewConstMetric( + c.maxOpenDesc, + prometheus.GaugeValue, + float64(stats.MaxOpen()), + ) + ch <- prometheus.MustNewConstMetric( + c.openDesc, + prometheus.GaugeValue, + float64(stats.Open()), + ) + ch <- prometheus.MustNewConstMetric( + c.inUseDesc, + prometheus.GaugeValue, + float64(stats.InUse()), + ) + ch <- prometheus.MustNewConstMetric( + c.idleDesc, + prometheus.GaugeValue, + float64(stats.Idle()), + ) + ch <- prometheus.MustNewConstMetric( + c.waitedForDesc, + prometheus.CounterValue, + float64(stats.WaitCount()), + ) + ch <- prometheus.MustNewConstMetric( + c.blockedSecondsDesc, + prometheus.CounterValue, + stats.WaitDuration().Seconds(), + ) + ch <- prometheus.MustNewConstMetric( + c.closedMaxIdleDesc, + prometheus.CounterValue, + float64(stats.MaxIdleClosed()), + ) + ch <- prometheus.MustNewConstMetric( + c.closedMaxLifetimeDesc, + prometheus.CounterValue, + float64(stats.MaxLifetimeClosed()), + ) +} diff --git a/pkg/prom/prom.go b/pkg/prom/prom.go new file mode 100644 index 0000000..4c9e027 --- /dev/null +++ b/pkg/prom/prom.go @@ -0,0 +1,90 @@ +// VulcanizeDB +// Copyright © 2022 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package prom + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +const ( + namespace = "ipld_eth_state_snapshot" + + connSubsystem = "connections" + statsSubsystem = "stats" +) + +var ( + metrics bool + + stateNodeCount prometheus.Counter + storageNodeCount prometheus.Counter + codeNodeCount prometheus.Counter +) + +func Init() { + metrics = true + + stateNodeCount = promauto.NewCounter(prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: statsSubsystem, + Name: "state_node_count", + Help: "Number of state nodes processed", + }) + + storageNodeCount = promauto.NewCounter(prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: statsSubsystem, + Name: "storage_node_count", + Help: "Number of storage nodes processed", + }) + + codeNodeCount = promauto.NewCounter(prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: statsSubsystem, + Name: "code_node_count", + Help: "Number of code nodes processed", + }) +} + +// RegisterDBCollector create metric collector for given connection +func RegisterDBCollector(name string, db DBStatsGetter) { + if metrics { + prometheus.Register(NewDBStatsCollector(name, db)) + } +} + +// IncStateNodeCount increments the number of state nodes processed +func IncStateNodeCount() { + if metrics { + stateNodeCount.Inc() + } +} + +// IncStorageNodeCount increments the number of storage nodes processed +func IncStorageNodeCount() { + if metrics { + storageNodeCount.Inc() + } +} + +// IncCodeNodeCount increments the number of code nodes processed +func IncCodeNodeCount() { + if metrics { + codeNodeCount.Inc() + } +} diff --git a/pkg/prom/serve.go b/pkg/prom/serve.go new file mode 100644 index 0000000..4501a42 --- /dev/null +++ b/pkg/prom/serve.go @@ -0,0 +1,47 @@ +// VulcanizeDB +// Copyright © 2022 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package prom + +import ( + "errors" + "net/http" + + "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/sirupsen/logrus" +) + +var errPromHTTP = errors.New("can't start http server for prometheus") + +// Serve start listening http +func Serve(addr string) *http.Server { + mux := http.NewServeMux() + mux.Handle("/metrics", promhttp.Handler()) + srv := http.Server{ + Addr: addr, + Handler: mux, + } + go func() { + if err := srv.ListenAndServe(); err != nil { + logrus. + WithError(err). + WithField("module", "prom"). + WithField("addr", addr). + Fatal(errPromHTTP) + } + }() + return &srv +} diff --git a/pkg/snapshot/env.go b/pkg/snapshot/env.go index b851ceb..2ec6100 100644 --- a/pkg/snapshot/env.go +++ b/pkg/snapshot/env.go @@ -25,6 +25,12 @@ const ( LOGRUS_LEVEL = "LOGRUS_LEVEL" LOGRUS_FILE = "LOGRUS_FILE" + PROM_METRICS = "PROM_METRICS" + PROM_HTTP = "PROM_HTTP" + PROM_HTTP_ADDR = "PROM_HTTP_ADDR" + PROM_HTTP_PORT = "PROM_HTTP_PORT" + PROM_DB_STATS = "PROM_DB_STATS" + FILE_OUTPUT_DIR = "FILE_OUTPUT_DIR" ANCIENT_DB_PATH = "ANCIENT_DB_PATH" @@ -56,6 +62,12 @@ const ( LOGRUS_LEVEL_TOML = "log.level" LOGRUS_FILE_TOML = "log.file" + PROM_METRICS_TOML = "prom.metrics" + PROM_HTTP_TOML = "prom.http" + PROM_HTTP_ADDR_TOML = "prom.httpAddr" + PROM_HTTP_PORT_TOML = "prom.httpPort" + PROM_DB_STATS_TOML = "prom.dbStats" + FILE_OUTPUT_DIR_TOML = "file.outputDir" ANCIENT_DB_PATH_TOML = "leveldb.ancient" @@ -87,6 +99,12 @@ const ( LOGRUS_LEVEL_CLI = "log-level" LOGRUS_FILE_CLI = "log-file" + PROM_METRICS_CLI = "prom-metrics" + PROM_HTTP_CLI = "prom-http" + PROM_HTTP_ADDR_CLI = "prom-httpAddr" + PROM_HTTP_PORT_CLI = "prom-httpPort" + PROM_DB_STATS_CLI = "prom-dbStats" + FILE_OUTPUT_DIR_CLI = "output-dir" ANCIENT_DB_PATH_CLI = "ancient-path" diff --git a/pkg/snapshot/file/publisher.go b/pkg/snapshot/file/publisher.go index f20dfb8..a76a906 100644 --- a/pkg/snapshot/file/publisher.go +++ b/pkg/snapshot/file/publisher.go @@ -34,6 +34,7 @@ import ( "github.com/ethereum/go-ethereum/statediff/indexer/ipld" nodeinfo "github.com/ethereum/go-ethereum/statediff/indexer/node" "github.com/ethereum/go-ethereum/statediff/indexer/shared" + "github.com/vulcanize/ipld-eth-state-snapshot/pkg/prom" snapt "github.com/vulcanize/ipld-eth-state-snapshot/pkg/types" ) @@ -223,6 +224,8 @@ func (p *publisher) PublishStateNode(node *snapt.Node, headerID string, snapTx s } // increment state node counter. atomic.AddUint64(&p.stateNodeCounter, 1) + prom.IncStateNodeCount() + // increment current batch size counter p.currBatchSize += 2 return err @@ -249,6 +252,8 @@ func (p *publisher) PublishStorageNode(node *snapt.Node, headerID string, stateP } // increment storage node counter. atomic.AddUint64(&p.storageNodeCounter, 1) + prom.IncStorageNodeCount() + // increment current batch size counter p.currBatchSize += 2 return nil @@ -268,6 +273,8 @@ func (p *publisher) PublishCode(codeHash common.Hash, codeBytes []byte, snapTx s } // increment code node counter. atomic.AddUint64(&p.codeNodeCounter, 1) + prom.IncCodeNodeCount() + p.currBatchSize++ return nil } diff --git a/pkg/snapshot/file/publisher_test.go b/pkg/snapshot/file/publisher_test.go index f2a591c..233b035 100644 --- a/pkg/snapshot/file/publisher_test.go +++ b/pkg/snapshot/file/publisher_test.go @@ -127,6 +127,7 @@ func TestPgCopy(t *testing.T) { test.NoError(t, err) headerNode, err := ipld.NewEthHeader(&fixt.Block1_Header) + test.NoError(t, err) test.ExpectEqual(t, headerNode.Cid().String(), header.CID) test.ExpectEqual(t, fixt.Block1_Header.Hash().String(), header.BlockHash) } diff --git a/pkg/snapshot/pg/publisher.go b/pkg/snapshot/pg/publisher.go index 3b7f4a2..4177795 100644 --- a/pkg/snapshot/pg/publisher.go +++ b/pkg/snapshot/pg/publisher.go @@ -33,6 +33,7 @@ import ( "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres" "github.com/ethereum/go-ethereum/statediff/indexer/ipld" "github.com/ethereum/go-ethereum/statediff/indexer/shared" + "github.com/vulcanize/ipld-eth-state-snapshot/pkg/prom" snapt "github.com/vulcanize/ipld-eth-state-snapshot/pkg/types" ) @@ -150,6 +151,7 @@ func (p *publisher) PublishStateNode(node *snapt.Node, headerID string, snapTx s } // increment state node counter. atomic.AddUint64(&p.stateNodeCounter, 1) + prom.IncStateNodeCount() // increment current batch size counter p.currBatchSize += 2 @@ -176,6 +178,7 @@ func (p *publisher) PublishStorageNode(node *snapt.Node, headerID string, stateP } // increment storage node counter. atomic.AddUint64(&p.storageNodeCounter, 1) + prom.IncStorageNodeCount() // increment current batch size counter p.currBatchSize += 2 @@ -197,6 +200,7 @@ func (p *publisher) PublishCode(codeHash common.Hash, codeBytes []byte, snapTx s // increment code node counter. atomic.AddUint64(&p.codeNodeCounter, 1) + prom.IncCodeNodeCount() p.currBatchSize++ return nil diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index efe8f62..3e269a9 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -36,7 +36,7 @@ import ( ) var ( - emptyNode, _ = rlp.EncodeToBytes([]byte{}) + emptyNode, _ = rlp.EncodeToBytes(&[]byte{}) emptyCodeHash = crypto.Keccak256([]byte{}) emptyContractRoot = crypto.Keccak256Hash(emptyNode) @@ -142,7 +142,6 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { } else { return s.createSnapshot(iters[0], headerID) } - return nil } // Create snapshot up to head (ignores height param) diff --git a/pkg/snapshot/util.go b/pkg/snapshot/util.go index c5673d0..a2ca7ee 100644 --- a/pkg/snapshot/util.go +++ b/pkg/snapshot/util.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres" + "github.com/vulcanize/ipld-eth-state-snapshot/pkg/prom" file "github.com/vulcanize/ipld-eth-state-snapshot/pkg/snapshot/file" pg "github.com/vulcanize/ipld-eth-state-snapshot/pkg/snapshot/pg" snapt "github.com/vulcanize/ipld-eth-state-snapshot/pkg/types" @@ -18,6 +19,9 @@ func NewPublisher(mode SnapshotMode, config *Config) (snapt.Publisher, error) { if err != nil { return nil, err } + + prom.RegisterDBCollector(config.DB.ConnConfig.DatabaseName, driver) + return pg.NewPublisher(postgres.NewPostgresDB(driver)), nil case FileSnapshot: return file.NewPublisher(config.File.OutputDir, config.Eth.NodeInfo)