Skip to content

Commit

Permalink
services/horizon: Add feature flag for extended ledger stats log (#4017)
Browse files Browse the repository at this point in the history
Add a new feature flag `--ingest-enable-extended-log-ledger-stats` (`false` by
default) that enables extra ledger stats when logging ledger processing info.

There are just too many information in extended stats that are not relevant for
average user. This make the log hard to read. Advanced users can enable the
stats.
  • Loading branch information
bartekn authored Oct 21, 2021
1 parent 68b39bd commit c4a3cbc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
3 changes: 3 additions & 0 deletions services/horizon/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 15 additions & 11 deletions services/horizon/internal/ingest/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,17 +495,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)

Expand Down
8 changes: 5 additions & 3 deletions services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions services/horizon/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c4a3cbc

Please sign in to comment.