Skip to content

Commit

Permalink
register db metrics in separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya1702 committed Jan 31, 2025
1 parent 4294b13 commit a58da1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,22 @@ func OpenDBConnectionPool(dataSourceName string, metricsRegistry *prometheus.Reg
sqlxDB.SetConnMaxIdleTime(MaxDBConnIdleTime)
sqlxDB.SetMaxOpenConns(MaxOpenDBConns)

if metricsRegistry != nil {
collector := sqlstats.NewStatsCollector("wallet-backend-db", sqlxDB)
metricsRegistry.MustRegister(collector)
}

err = sqlxDB.Ping()
if err != nil {
return nil, fmt.Errorf("error pinging app DB connection pool: %w", err)
}

return &ConnectionPoolImplementation{DB: sqlxDB}, nil
db := &ConnectionPoolImplementation{DB: sqlxDB}
if metricsRegistry != nil {
db.registerMetrics(metricsRegistry)
}

return db, nil
}

func (db *ConnectionPoolImplementation) registerMetrics(metricsRegistry *prometheus.Registry) {
collector := sqlstats.NewStatsCollector("wallet-backend-db", db.DB)
metricsRegistry.MustRegister(collector)
}

func (db *ConnectionPoolImplementation) BeginTxx(ctx context.Context, opts *sql.TxOptions) (Transaction, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/services/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ func NewIngestService(
ingestionDuration: ingestionDuration,
}

ingestService.RegisterMetrics(metricsRegistry)
ingestService.registerMetrics(metricsRegistry)
return ingestService, nil
}

func (m *ingestService) RegisterMetrics(registry *prometheus.Registry) {
func (m *ingestService) registerMetrics(registry *prometheus.Registry) {
registry.MustRegister(
m.numPaymentOpsIngestedPerLedger,
m.numTssTransactionsIngestedPerLedger,
Expand Down

0 comments on commit a58da1a

Please sign in to comment.