Skip to content

Commit

Permalink
services/horizon: Allow customization of the Captive Core log file. (#…
Browse files Browse the repository at this point in the history
…3472)

Introduces the --captive-core-log-path parameter.

Now, we can pass along to Stellar-Core's LOG_FILE_PATH="..." 
based on the value of the above parameter. We will still always 
log to Horizon's subservice=stellar-core.

Co-authored-by: Bartek Nowotarski <bartek@nowotarski.info>
  • Loading branch information
Shaptic and bartekn authored Mar 19, 2021
1 parent 17275e8 commit 5df6246
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ingest/ledgerbackend/captive_core_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ type CaptiveCoreConfig struct {
// Log is an (optional) custom logger which will capture any output from the Stellar Core process.
// If Log is omitted then all output will be printed to stdout.
Log *log.Entry
// LogPath is the (optional) path in which to store Core logs, passed along
// to Stellar Core's LOG_FILE_PATH
LogPath string
// Context is the (optional) context which controls the lifetime of a CaptiveStellarCore instance. Once the context is done
// the CaptiveStellarCore instance will not be able to stream ledgers from Stellar Core or spawn new
// instances of Stellar Core. If Context is omitted CaptiveStellarCore will default to using context.Background.
Expand All @@ -134,11 +137,14 @@ type CaptiveCoreConfig struct {
func NewCaptive(config CaptiveCoreConfig) (*CaptiveStellarCore, error) {
// Here we set defaults in the config. Because config is not a pointer this code should
// not mutate the original CaptiveCoreConfig instance which was passed into NewCaptive()

// Log Captive Core straight to stdout by default
if config.Log == nil {
config.Log = log.New()
config.Log.Logger.SetOutput(os.Stdout)
config.Log.SetLevel(logrus.InfoLevel)
}

parentCtx := config.Context
if parentCtx == nil {
parentCtx = context.Background()
Expand Down
4 changes: 3 additions & 1 deletion ingest/ledgerbackend/stellar_core_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type pipe struct {
}

type stellarCoreRunner struct {
logPath string
executablePath string
configAppendPath string
networkPassphrase string
Expand Down Expand Up @@ -82,6 +83,7 @@ func newStellarCoreRunner(config CaptiveCoreConfig, mode stellarCoreRunnerMode)
ctx, cancel := context.WithCancel(config.Context)

runner := &stellarCoreRunner{
logPath: config.LogPath,
executablePath: config.BinaryPath,
configAppendPath: config.ConfigAppendPath,
networkPassphrase: config.NetworkPassphrase,
Expand Down Expand Up @@ -116,7 +118,7 @@ func (r *stellarCoreRunner) generateConfig() (string, error) {
fmt.Sprintf(`NETWORK_PASSPHRASE="%s"`, r.networkPassphrase),
fmt.Sprintf(`BUCKET_DIR_PATH="%s"`, filepath.Join(r.tempDir, "buckets")),
fmt.Sprintf(`HTTP_PORT=%d`, r.httpPort),
`LOG_FILE_PATH=""`,
fmt.Sprintf(`LOG_FILE_PATH="%s"`, r.logPath),
}

if r.mode == stellarCoreRunnerModeOffline {
Expand Down
1 change: 1 addition & 0 deletions services/horizon/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Config struct {
CaptiveCoreConfigAppendPath string
RemoteCaptiveCoreURL string
CaptiveCoreHTTPPort uint
CaptiveCoreLogPath string

StellarCoreDatabaseURL string
StellarCoreURL string
Expand Down
6 changes: 6 additions & 0 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ func Flags() (*Config, support.ConfigOptions) {
OptType: types.String,
Usage: "name of the file where logs will be saved (leave empty to send logs to stdout)",
},
&support.ConfigOption{
Name: "captive-core-log-path",
ConfigKey: &config.CaptiveCoreLogPath,
OptType: types.String,
Usage: "name of the path for Core logs (leave empty to log w/ Horizon only)",
},
&support.ConfigOption{
Name: "max-path-length",
ConfigKey: &config.MaxPathLength,
Expand Down
5 changes: 4 additions & 1 deletion services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Config struct {
CaptiveCoreBinaryPath string
CaptiveCoreConfigAppendPath string
CaptiveCoreHTTPPort uint
CaptiveCoreLogPath string
RemoteCaptiveCoreURL string
NetworkPassphrase string

Expand Down Expand Up @@ -189,16 +190,18 @@ func NewSystem(config Config) (System, error) {
return nil, errors.Wrap(err, "error creating captive core backend")
}
} else {
logger := log.WithField("subservice", "stellar-core")
ledgerBackend, err = ledgerbackend.NewCaptive(
ledgerbackend.CaptiveCoreConfig{
LogPath: config.CaptiveCoreLogPath,
BinaryPath: config.CaptiveCoreBinaryPath,
ConfigAppendPath: config.CaptiveCoreConfigAppendPath,
HTTPPort: config.CaptiveCoreHTTPPort,
NetworkPassphrase: config.NetworkPassphrase,
HistoryArchiveURLs: []string{config.HistoryArchiveURL},
CheckpointFrequency: config.CheckpointFrequency,
LedgerHashStore: ledgerbackend.NewHorizonDBLedgerHashStore(config.HistorySession),
Log: log.WithField("subservice", "stellar-core"),
Log: logger,
Context: ctx,
},
)
Expand Down
1 change: 1 addition & 0 deletions services/horizon/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func initIngester(app *App) {
CaptiveCoreBinaryPath: app.config.CaptiveCoreBinaryPath,
CaptiveCoreConfigAppendPath: app.config.CaptiveCoreConfigAppendPath,
CaptiveCoreHTTPPort: app.config.CaptiveCoreHTTPPort,
CaptiveCoreLogPath: app.config.CaptiveCoreLogPath,
RemoteCaptiveCoreURL: app.config.RemoteCaptiveCoreURL,
EnableCaptiveCore: app.config.EnableCaptiveCoreIngestion,
DisableStateVerification: app.config.IngestDisableStateVerification,
Expand Down

0 comments on commit 5df6246

Please sign in to comment.