From 703541393be3332cac4bf408a27cf889d3822d46 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Tue, 19 Oct 2021 20:00:36 +0200 Subject: [PATCH] services/horizon: Add feature flag for extended ledger stats log --- services/horizon/internal/config.go | 3 +++ services/horizon/internal/flags.go | 7 +++++++ services/horizon/internal/ingest/fsm.go | 26 ++++++++++++++---------- services/horizon/internal/ingest/main.go | 8 +++++--- services/horizon/internal/init.go | 23 +++++++++++---------- 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/services/horizon/internal/config.go b/services/horizon/internal/config.go index c977fca7cc..8c0d46cf50 100644 --- a/services/horizon/internal/config.go +++ b/services/horizon/internal/config.go @@ -78,6 +78,9 @@ type Config struct { // IngestDisableStateVerification disables state verification // `System.verifyState()` when set to `true`. IngestDisableStateVerification bool + // IngestEnableExtendedLogLedgerStats enables extended ledger stats in + // logging. + IngestEnableExtendedLogLedgerStats bool // ApplyMigrations will apply pending migrations to the horizon database // before starting the horizon service ApplyMigrations bool diff --git a/services/horizon/internal/flags.go b/services/horizon/internal/flags.go index 4e52abf46e..6387166be1 100644 --- a/services/horizon/internal/flags.go +++ b/services/horizon/internal/flags.go @@ -453,6 +453,13 @@ func Flags() (*Config, support.ConfigOptions) { FlagDefault: false, Usage: "ingestion system runs a verification routing to compare state in local database with history buckets, this can be disabled however it's not recommended", }, + &support.ConfigOption{ + Name: "ingest-enable-extended-log-ledger-stats", + ConfigKey: &config.IngestEnableExtendedLogLedgerStats, + OptType: types.Bool, + FlagDefault: false, + Usage: "enables extended ledger stats in the log (ledger entry changes and operations stats)", + }, &support.ConfigOption{ Name: "apply-migrations", ConfigKey: &config.ApplyMigrations, diff --git a/services/horizon/internal/ingest/fsm.go b/services/horizon/internal/ingest/fsm.go index d610d7f5c7..5cdec1bf2d 100644 --- a/services/horizon/internal/ingest/fsm.go +++ b/services/horizon/internal/ingest/fsm.go @@ -492,17 +492,21 @@ func (r resumeState) run(s *system) (transition, error) { r.addLedgerStatsMetricFromMap(s, "ledger", transactionStatsMap) r.addProcessorDurationsMetricFromMap(s, transactionDurations) - log. - WithFields(changeStatsMap). - WithFields(transactionStatsMap). - WithFields(logpkg.F{ - "sequence": ingestLedger, - "duration": duration, - "state": true, - "ledger": true, - "commit": true, - }). - Info("Processed ledger") + localLog := log.WithFields(logpkg.F{ + "sequence": ingestLedger, + "duration": duration, + "state": true, + "ledger": true, + "commit": true, + }) + + if s.config.EnableExtendedLogLedgerStats { + localLog = localLog. + WithFields(changeStatsMap). + WithFields(transactionStatsMap) + } + + localLog.Info("Processed ledger") s.maybeVerifyState(ingestLedger) diff --git a/services/horizon/internal/ingest/main.go b/services/horizon/internal/ingest/main.go index 60fb5438a1..1c73aa67ce 100644 --- a/services/horizon/internal/ingest/main.go +++ b/services/horizon/internal/ingest/main.go @@ -78,9 +78,11 @@ type Config struct { RemoteCaptiveCoreURL string NetworkPassphrase string - HistorySession db.SessionInterface - HistoryArchiveURL string - DisableStateVerification bool + HistorySession db.SessionInterface + HistoryArchiveURL string + + DisableStateVerification bool + EnableExtendedLogLedgerStats bool MaxReingestRetries int ReingestRetryBackoffSeconds int diff --git a/services/horizon/internal/init.go b/services/horizon/internal/init.go index 04062e207c..13df5ee3f7 100644 --- a/services/horizon/internal/init.go +++ b/services/horizon/internal/init.go @@ -87,17 +87,18 @@ func initIngester(app *App) { // TODO: // Use the first archive for now. We don't have a mechanism to // use multiple archives at the same time currently. - HistoryArchiveURL: app.config.HistoryArchiveURLs[0], - CheckpointFrequency: app.config.CheckpointFrequency, - StellarCoreURL: app.config.StellarCoreURL, - StellarCoreCursor: app.config.CursorName, - CaptiveCoreBinaryPath: app.config.CaptiveCoreBinaryPath, - CaptiveCoreStoragePath: app.config.CaptiveCoreStoragePath, - CaptiveCoreReuseStoragePath: app.config.CaptiveCoreReuseStoragePath, - CaptiveCoreToml: app.config.CaptiveCoreToml, - RemoteCaptiveCoreURL: app.config.RemoteCaptiveCoreURL, - EnableCaptiveCore: app.config.EnableCaptiveCoreIngestion, - DisableStateVerification: app.config.IngestDisableStateVerification, + HistoryArchiveURL: app.config.HistoryArchiveURLs[0], + CheckpointFrequency: app.config.CheckpointFrequency, + StellarCoreURL: app.config.StellarCoreURL, + StellarCoreCursor: app.config.CursorName, + CaptiveCoreBinaryPath: app.config.CaptiveCoreBinaryPath, + CaptiveCoreStoragePath: app.config.CaptiveCoreStoragePath, + CaptiveCoreReuseStoragePath: app.config.CaptiveCoreReuseStoragePath, + CaptiveCoreToml: app.config.CaptiveCoreToml, + RemoteCaptiveCoreURL: app.config.RemoteCaptiveCoreURL, + EnableCaptiveCore: app.config.EnableCaptiveCoreIngestion, + DisableStateVerification: app.config.IngestDisableStateVerification, + EnableExtendedLogLedgerStats: app.config.IngestEnableExtendedLogLedgerStats, }) if err != nil {