Skip to content

Commit

Permalink
services/horizon/internal/txsub: Add metrics to track which types of …
Browse files Browse the repository at this point in the history
…transaction Horizon is receiving (#2553)
  • Loading branch information
tamirms authored May 5, 2020
1 parent 34aac57 commit 7c4596d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions services/horizon/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func initTxSubMetrics(app *App) {
app.metrics.Register("txsub.open", app.submitter.Metrics.OpenSubmissionsGauge)
app.metrics.Register("txsub.succeeded", app.submitter.Metrics.SuccessfulSubmissionsMeter)
app.metrics.Register("txsub.failed", app.submitter.Metrics.FailedSubmissionsMeter)
app.metrics.Register("txsub.v0", app.submitter.Metrics.V0TransactionsMeter)
app.metrics.Register("txsub.v1", app.submitter.Metrics.V1TransactionsMeter)
app.metrics.Register("txsub.feebump", app.submitter.Metrics.FeeBumpTransactionsMeter)
app.metrics.Register("txsub.total", app.submitter.Metrics.SubmissionTimer)
}

Expand Down
32 changes: 30 additions & 2 deletions services/horizon/internal/txsub/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ type System struct {
// SuccessfulSubmissionsMeter tracks the rate of successful transactions that
// have been submitted to this process
SuccessfulSubmissionsMeter metrics.Meter

// V0TransactionsMeter tracks the rate of v0 transaction envelopes that
// have been submitted to this process
V0TransactionsMeter metrics.Meter

// V1TransactionsMeter tracks the rate of v1 transaction envelopes that
// have been submitted to this process
V1TransactionsMeter metrics.Meter

// FeeBumpTransactionsMeter tracks the rate of fee bump transaction envelopes that
// have been submitted to this process
FeeBumpTransactionsMeter metrics.Meter
}
}

Expand All @@ -65,8 +77,9 @@ func (sys *System) Submit(
result = response

sys.Log.Ctx(ctx).WithFields(log.F{
"hash": hash,
"tx": rawTx,
"hash": hash,
"tx_type": envelope.Type.String(),
"tx": rawTx,
}).Info("Processing transaction")

// check the configured result provider for an existing result
Expand Down Expand Up @@ -124,6 +137,7 @@ func (sys *System) Submit(
}

sr := sys.submitOnce(ctx, rawTx)
sys.updateTransactionTypeMetrics(envelope)

// if submission succeeded
if sr.Err == nil {
Expand Down Expand Up @@ -183,6 +197,17 @@ func (sys *System) submitOnce(ctx context.Context, env string) SubmissionResult
return sr
}

func (sys *System) updateTransactionTypeMetrics(envelope xdr.TransactionEnvelope) {
switch envelope.Type {
case xdr.EnvelopeTypeEnvelopeTypeTxV0:
sys.Metrics.V0TransactionsMeter.Mark(1)
case xdr.EnvelopeTypeEnvelopeTypeTx:
sys.Metrics.V1TransactionsMeter.Mark(1)
case xdr.EnvelopeTypeEnvelopeTypeTxFeeBump:
sys.Metrics.FeeBumpTransactionsMeter.Mark(1)
}
}

// setTickInProgress sets `tickInProgress` to `true` if it's
// `false`. Returns `true` if `tickInProgress` has been switched
// to `true` inside this method and `Tick()` should continue.
Expand Down Expand Up @@ -275,6 +300,9 @@ func (sys *System) Init() {
sys.Metrics.SubmissionTimer = metrics.NewTimer()
sys.Metrics.OpenSubmissionsGauge = metrics.NewGauge()
sys.Metrics.BufferedSubmissionsGauge = metrics.NewGauge()
sys.Metrics.V0TransactionsMeter = metrics.NewMeter()
sys.Metrics.V1TransactionsMeter = metrics.NewMeter()
sys.Metrics.FeeBumpTransactionsMeter = metrics.NewMeter()

if sys.SubmissionTimeout == 0 {
// HTTP clients in SDKs usually timeout in 60 seconds. We want SubmissionTimeout
Expand Down

0 comments on commit 7c4596d

Please sign in to comment.