Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose captive core version details #5332

Merged
merged 8 commits into from
Jun 14, 2024
Merged
22 changes: 19 additions & 3 deletions ingest/ledgerbackend/captive_core_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ type CaptiveStellarCore struct {
lastLedger *uint32 // end of current segment if offline, nil if online
previousLedgerHash *string

config CaptiveCoreConfig
stellarCoreClient *stellarcore.Client
config CaptiveCoreConfig
stellarCoreClient *stellarcore.Client
captiveCoreVersion string // Updates when captive-core restarts
}

// CaptiveCoreConfig contains all the parameters required to create a CaptiveStellarCore instance
Expand Down Expand Up @@ -211,7 +212,7 @@ func NewCaptive(config CaptiveCoreConfig) (*CaptiveStellarCore, error) {
URL: fmt.Sprintf("http://localhost:%d", config.Toml.HTTPPort),
}
}

c.setCoreVersion()
psheth9 marked this conversation as resolved.
Show resolved Hide resolved
return c, nil
}

Expand Down Expand Up @@ -245,6 +246,21 @@ func (c *CaptiveStellarCore) coreVersionMetric() float64 {
return float64(info.Info.ProtocolVersion)
}

func (c *CaptiveStellarCore) setCoreVersion() {
if c.stellarCoreClient == nil {
log.WithField("err", errors.New("HTTP stellarCoreClient is not initialized")).Error("cannot fetch captive core version details")
return
}

info, err := c.stellarCoreClient.Info(c.config.Context)
psheth9 marked this conversation as resolved.
Show resolved Hide resolved
psheth9 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.WithField("err", err).Error("cannot fetch captive core version details from /info endpoint")
return
}

c.captiveCoreVersion = info.Info.Build
}

func (c *CaptiveStellarCore) registerMetrics(registry *prometheus.Registry, namespace string) {
coreSynced := prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Expand Down
Loading