From 41f60504072b5f6191cfa70bd8e9e3b1c917aa94 Mon Sep 17 00:00:00 2001 From: Patrick Pfeiffer Date: Wed, 31 Jul 2024 09:52:03 +0200 Subject: [PATCH] (NOBIDS) move ratelimit-updater to fdu --- cmd/misc/main.go | 5 +---- ratelimit/ratelimit.go | 2 +- services/services.go | 5 +++++ types/config.go | 4 ++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/misc/main.go b/cmd/misc/main.go index 12a4f8ec7e..fc21f0fe86 100644 --- a/cmd/misc/main.go +++ b/cmd/misc/main.go @@ -19,7 +19,6 @@ import ( "github.com/gobitfly/eth2-beaconchain-explorer/cmd/misc/commands" "github.com/gobitfly/eth2-beaconchain-explorer/db" "github.com/gobitfly/eth2-beaconchain-explorer/exporter" - "github.com/gobitfly/eth2-beaconchain-explorer/ratelimit" "github.com/gobitfly/eth2-beaconchain-explorer/rpc" "github.com/gobitfly/eth2-beaconchain-explorer/services" "github.com/gobitfly/eth2-beaconchain-explorer/types" @@ -76,7 +75,7 @@ func main() { statsPartitionCommand := commands.StatsMigratorCommand{} configPath := flag.String("config", "config/default.config.yml", "Path to the config file") - flag.StringVar(&opts.Command, "command", "", "command to run, available: updateAPIKey, applyDbSchema, initBigtableSchema, epoch-export, debug-rewards, debug-blocks, clear-bigtable, index-old-eth1-blocks, update-aggregation-bits, historic-prices-export, index-missing-blocks, export-epoch-missed-slots, migrate-last-attestation-slot-bigtable, export-genesis-validators, update-block-finalization-sequentially, nameValidatorsByRanges, export-stats-totals, export-sync-committee-periods, export-sync-committee-validator-stats, partition-validator-stats, migrate-app-purchases, update-ratelimits, disable-user-per-email") + flag.StringVar(&opts.Command, "command", "", "command to run, available: updateAPIKey, applyDbSchema, initBigtableSchema, epoch-export, debug-rewards, debug-blocks, clear-bigtable, index-old-eth1-blocks, update-aggregation-bits, historic-prices-export, index-missing-blocks, export-epoch-missed-slots, migrate-last-attestation-slot-bigtable, export-genesis-validators, update-block-finalization-sequentially, nameValidatorsByRanges, export-stats-totals, export-sync-committee-periods, export-sync-committee-validator-stats, partition-validator-stats, migrate-app-purchases, disable-user-per-email") flag.Uint64Var(&opts.StartEpoch, "start-epoch", 0, "start epoch") flag.Uint64Var(&opts.EndEpoch, "end-epoch", 0, "end epoch") flag.Uint64Var(&opts.User, "user", 0, "user id") @@ -435,8 +434,6 @@ func main() { err = fixEns(erigonClient) case "fix-ens-addresses": err = fixEnsAddresses(erigonClient) - case "update-ratelimits": - ratelimit.DBUpdater() case "disable-user-per-email": err = disableUserPerEmail() case "fix-epochs": diff --git a/ratelimit/ratelimit.go b/ratelimit/ratelimit.go index 77f3fee277..c70c1e0e6e 100644 --- a/ratelimit/ratelimit.go +++ b/ratelimit/ratelimit.go @@ -1057,7 +1057,7 @@ func DBGetCurrentApiProducts() ([]*ApiProduct, error) { } func DBUpdater() { - iv := utils.Config.Frontend.RatelimitUpdateInterval + iv := utils.Config.RatelimitUpdater.UpdateInterval if iv < time.Second { logger.Warnf("updateInterval is below 1s, setting to 60s") iv = time.Second * 60 diff --git a/services/services.go b/services/services.go index 56fd372b15..9dc6ca9f09 100644 --- a/services/services.go +++ b/services/services.go @@ -17,6 +17,7 @@ import ( "github.com/gobitfly/eth2-beaconchain-explorer/db" ethclients "github.com/gobitfly/eth2-beaconchain-explorer/ethClients" "github.com/gobitfly/eth2-beaconchain-explorer/price" + "github.com/gobitfly/eth2-beaconchain-explorer/ratelimit" "github.com/gobitfly/eth2-beaconchain-explorer/types" "github.com/gobitfly/eth2-beaconchain-explorer/utils" @@ -86,6 +87,10 @@ func Init() { ready.Add(1) go latestExportedStatisticDayUpdater(ready) + if utils.Config.RatelimitUpdater.Enabled { + go ratelimit.DBUpdater() + } + ready.Wait() } diff --git a/types/config.go b/types/config.go index 08d4fde385..289a7f3bd0 100644 --- a/types/config.go +++ b/types/config.go @@ -235,6 +235,10 @@ type Config struct { MachineEventFirstRatioThreshold float64 `yaml:"machineEventFirstRatioThreshold" envconfig:"MACHINE_EVENT_FIRST_RATIO_THRESHOLD"` MachineEventSecondRatioThreshold float64 `yaml:"machineEventSecondRatioThreshold" envconfig:"MACHINE_EVENT_SECOND_RATIO_THRESHOLD"` } `yaml:"notifications"` + RatelimitUpdater struct { + Enabled bool `yaml:"enabled" envconfig:"RATELIMIT_UPDATER_ENABLED"` + UpdateInterval time.Duration `yaml:"updateInterval" envconfig:"RATELIMIT_UPDATER_UPDATE_INTERVAL"` + } SSVExporter struct { Enabled bool `yaml:"enabled" envconfig:"SSV_EXPORTER_ENABLED"` Address string `yaml:"address" envconfig:"SSV_EXPORTER_ADDRESS"`