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

services/horizon: Add Stellar protocol version metrics #3634

Merged
merged 4 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions services/horizon/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type App struct {
historyElderLedgerCounter prometheus.CounterFunc
coreLatestLedgerCounter prometheus.CounterFunc
coreSynced prometheus.GaugeFunc
coreSupportedProtocolVersion prometheus.GaugeFunc
}

func (a *App) GetCoreState() corestate.State {
Expand Down
42 changes: 42 additions & 0 deletions services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ type stellarCoreClient interface {
}

type Metrics struct {
// MaxSupportedProtocolVersion exposes the maximum protocol version
// supported by this version.
MaxSupportedProtocolVersion prometheus.Gauge

// LocalLedger exposes the last ingested ledger by this ingesting instance.
LocalLatestLedger prometheus.Gauge

Expand All @@ -124,6 +128,10 @@ type Metrics struct {
// CaptiveStellarCoreSynced exposes synced status of Captive Stellar-Core.
// 1 if sync, 0 if not synced, -1 if unable to connect or HTTP server disabled.
CaptiveStellarCoreSynced prometheus.GaugeFunc

// CaptiveCoreSupportedProtocolVersion exposes the maximum protocol version
// supported by the running Captive-Core.
CaptiveCoreSupportedProtocolVersion prometheus.GaugeFunc
}

type System interface {
Expand Down Expand Up @@ -250,6 +258,13 @@ func NewSystem(config Config) (System, error) {
}

func (s *system) initMetrics() {
s.metrics.MaxSupportedProtocolVersion = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "horizon", Subsystem: "ingest", Name: "max_supported_protocol_version",
Help: "the maximum protocol version supported by this version.",
})

s.metrics.MaxSupportedProtocolVersion.Set(float64(MaxSupportedProtocolVersion))

s.metrics.LocalLatestLedger = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "horizon", Subsystem: "ingest", Name: "local_latest_ledger",
Help: "sequence number of the latest ledger ingested by this ingesting instance",
Expand Down Expand Up @@ -330,6 +345,33 @@ func (s *system) initMetrics() {
}
},
)

s.metrics.CaptiveCoreSupportedProtocolVersion = prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Namespace: "horizon", Subsystem: "ingest", Name: "captive_stellar_core_supported_protocol_version",
Help: "determines the supported version of the protocol by Captive-Core",
},
func() float64 {
if !s.config.EnableCaptiveCore || (s.config.CaptiveCoreToml.HTTPPort == 0) {
return -1
}

client := stellarcore.Client{
HTTP: &http.Client{
Timeout: 2 * time.Second,
},
URL: fmt.Sprintf("http://localhost:%d", s.config.CaptiveCoreToml.HTTPPort),
}

info, err := client.Info(s.ctx)
if err != nil {
log.WithError(err).Error("Cannot connect to Captive Stellar-Core HTTP server")
return -1
}

return float64(info.Info.ProtocolVersion)
},
)
}

func (s *system) Metrics() Metrics {
Expand Down
13 changes: 13 additions & 0 deletions services/horizon/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ func initDbMetrics(app *App) {
)
app.prometheusRegistry.MustRegister(app.coreSynced)

app.coreSupportedProtocolVersion = prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Namespace: "horizon", Subsystem: "stellar_core", Name: "supported_protocol_version",
Help: "determines the supported version of the protocol by Stellar-Core defined by --stellar-core-url",
},
func() float64 {
return float64(app.coreState.Get().CoreSupportedProtocolVersion)
},
)
app.prometheusRegistry.MustRegister(app.coreSupportedProtocolVersion)

app.prometheusRegistry.MustRegister(app.orderBookStream.LatestLedgerGauge)
}

Expand All @@ -243,13 +254,15 @@ func initIngestMetrics(app *App) {
}

app.ingestingGauge.Inc()
app.prometheusRegistry.MustRegister(app.ingester.Metrics().MaxSupportedProtocolVersion)
app.prometheusRegistry.MustRegister(app.ingester.Metrics().LocalLatestLedger)
app.prometheusRegistry.MustRegister(app.ingester.Metrics().LedgerIngestionDuration)
app.prometheusRegistry.MustRegister(app.ingester.Metrics().StateVerifyDuration)
app.prometheusRegistry.MustRegister(app.ingester.Metrics().StateInvalidGauge)
app.prometheusRegistry.MustRegister(app.ingester.Metrics().LedgerStatsCounter)
app.prometheusRegistry.MustRegister(app.ingester.Metrics().ProcessorsRunDuration)
app.prometheusRegistry.MustRegister(app.ingester.Metrics().CaptiveStellarCoreSynced)
app.prometheusRegistry.MustRegister(app.ingester.Metrics().CaptiveCoreSupportedProtocolVersion)
}

func initTxSubMetrics(app *App) {
Expand Down