@@ -10,8 +10,32 @@ import (
10
10
"github.com/prometheus/client_golang/prometheus"
11
11
)
12
12
13
+ type MetricsService interface {
14
+ RegisterPoolMetrics (channel string , pool * pond.WorkerPool )
15
+ GetRegistry () * prometheus.Registry
16
+ SetNumPaymentOpsIngestedPerLedger (operationType string , value int )
17
+ SetNumTssTransactionsIngestedPerLedger (status string , value float64 )
18
+ SetLatestLedgerIngested (value float64 )
19
+ ObserveIngestionDuration (ingestionType string , duration float64 )
20
+ IncNumTSSTransactionsSubmitted ()
21
+ ObserveTSSTransactionInclusionTime (status string , durationSeconds float64 )
22
+ IncActiveAccount ()
23
+ DecActiveAccount ()
24
+ IncRPCRequests (endpoint string )
25
+ ObserveRPCRequestDuration (endpoint string , duration float64 )
26
+ IncRPCEndpointFailure (endpoint string )
27
+ IncRPCEndpointSuccess (endpoint string )
28
+ SetRPCServiceHealth (healthy bool )
29
+ SetRPCLatestLedger (ledger int64 )
30
+ IncNumRequests (endpoint , method string , statusCode int )
31
+ ObserveRequestDuration (endpoint , method string , duration float64 )
32
+ ObserveDBQueryDuration (queryType , table string , duration float64 )
33
+ IncDBQuery (queryType , table string )
34
+ RecordTSSTransactionStatusTransition (oldStatus , newStatus string )
35
+ }
36
+
13
37
// MetricsService handles all metrics for the wallet-backend
14
- type MetricsService struct {
38
+ type metricsService struct {
15
39
registry * prometheus.Registry
16
40
db * sqlx.DB
17
41
@@ -49,8 +73,8 @@ type MetricsService struct {
49
73
}
50
74
51
75
// NewMetricsService creates a new metrics service with all metrics registered
52
- func NewMetricsService (db * sqlx.DB ) * MetricsService {
53
- m := & MetricsService {
76
+ func NewMetricsService (db * sqlx.DB ) MetricsService {
77
+ m := & metricsService {
54
78
registry : prometheus .NewRegistry (),
55
79
db : db ,
56
80
}
@@ -197,7 +221,7 @@ func NewMetricsService(db *sqlx.DB) *MetricsService {
197
221
return m
198
222
}
199
223
200
- func (m * MetricsService ) registerMetrics () {
224
+ func (m * metricsService ) registerMetrics () {
201
225
collector := sqlstats .NewStatsCollector ("wallet-backend-db" , m .db )
202
226
m .registry .MustRegister (
203
227
collector ,
@@ -223,7 +247,7 @@ func (m *MetricsService) registerMetrics() {
223
247
}
224
248
225
249
// RegisterPool registers a worker pool for metrics collection
226
- func (m * MetricsService ) RegisterPoolMetrics (channel string , pool * pond.WorkerPool ) {
250
+ func (m * metricsService ) RegisterPoolMetrics (channel string , pool * pond.WorkerPool ) {
227
251
m .registry .MustRegister (prometheus .NewGaugeFunc (
228
252
prometheus.GaugeOpts {
229
253
Name : fmt .Sprintf ("pool_workers_running_%s" , channel ),
@@ -303,95 +327,95 @@ func (m *MetricsService) RegisterPoolMetrics(channel string, pool *pond.WorkerPo
303
327
}
304
328
305
329
// GetRegistry returns the prometheus registry
306
- func (m * MetricsService ) GetRegistry () * prometheus.Registry {
330
+ func (m * metricsService ) GetRegistry () * prometheus.Registry {
307
331
return m .registry
308
332
}
309
333
310
334
// Ingest Service Metrics
311
- func (m * MetricsService ) SetNumPaymentOpsIngestedPerLedger (operationType string , value int ) {
335
+ func (m * metricsService ) SetNumPaymentOpsIngestedPerLedger (operationType string , value int ) {
312
336
m .numPaymentOpsIngestedPerLedger .WithLabelValues (operationType ).Set (float64 (value ))
313
337
}
314
338
315
- func (m * MetricsService ) SetNumTssTransactionsIngestedPerLedger (status string , value float64 ) {
339
+ func (m * metricsService ) SetNumTssTransactionsIngestedPerLedger (status string , value float64 ) {
316
340
m .numTssTransactionsIngestedPerLedger .WithLabelValues (status ).Set (value )
317
341
}
318
342
319
- func (m * MetricsService ) SetLatestLedgerIngested (value float64 ) {
343
+ func (m * metricsService ) SetLatestLedgerIngested (value float64 ) {
320
344
m .latestLedgerIngested .Set (value )
321
345
}
322
346
323
- func (m * MetricsService ) ObserveIngestionDuration (ingestionType string , duration float64 ) {
347
+ func (m * metricsService ) ObserveIngestionDuration (ingestionType string , duration float64 ) {
324
348
m .ingestionDuration .WithLabelValues (ingestionType ).Observe (duration )
325
349
}
326
350
327
351
// TSS Service Metrics
328
- func (m * MetricsService ) IncNumTSSTransactionsSubmitted () {
352
+ func (m * metricsService ) IncNumTSSTransactionsSubmitted () {
329
353
m .numTSSTransactionsSubmitted .Inc ()
330
354
}
331
355
332
356
// ObserveTSSTransactionInclusionTime records the time taken for a transaction to be included in the ledger
333
- func (m * MetricsService ) ObserveTSSTransactionInclusionTime (status string , durationSeconds float64 ) {
357
+ func (m * metricsService ) ObserveTSSTransactionInclusionTime (status string , durationSeconds float64 ) {
334
358
m .timeUntilTSSTransactionInclusion .WithLabelValues (status ).Observe (durationSeconds )
335
359
}
336
360
337
361
// Account Service Metrics
338
- func (m * MetricsService ) IncActiveAccount () {
362
+ func (m * metricsService ) IncActiveAccount () {
339
363
m .activeAccounts .Inc ()
340
364
}
341
365
342
- func (m * MetricsService ) DecActiveAccount () {
366
+ func (m * metricsService ) DecActiveAccount () {
343
367
m .activeAccounts .Dec ()
344
368
}
345
369
346
370
// RPC Service Metrics
347
- func (m * MetricsService ) IncRPCRequests (endpoint string ) {
371
+ func (m * metricsService ) IncRPCRequests (endpoint string ) {
348
372
m .rpcRequestsTotal .WithLabelValues (endpoint ).Inc ()
349
373
}
350
374
351
- func (m * MetricsService ) ObserveRPCRequestDuration (endpoint string , duration float64 ) {
375
+ func (m * metricsService ) ObserveRPCRequestDuration (endpoint string , duration float64 ) {
352
376
m .rpcRequestsDuration .WithLabelValues (endpoint ).Observe (duration )
353
377
}
354
378
355
- func (m * MetricsService ) IncRPCEndpointFailure (endpoint string ) {
379
+ func (m * metricsService ) IncRPCEndpointFailure (endpoint string ) {
356
380
m .rpcEndpointFailures .WithLabelValues (endpoint ).Inc ()
357
381
}
358
382
359
- func (m * MetricsService ) IncRPCEndpointSuccess (endpoint string ) {
383
+ func (m * metricsService ) IncRPCEndpointSuccess (endpoint string ) {
360
384
m .rpcEndpointSuccesses .WithLabelValues (endpoint ).Inc ()
361
385
}
362
386
363
- func (m * MetricsService ) SetRPCServiceHealth (healthy bool ) {
387
+ func (m * metricsService ) SetRPCServiceHealth (healthy bool ) {
364
388
if healthy {
365
389
m .rpcServiceHealth .Set (1 )
366
390
} else {
367
391
m .rpcServiceHealth .Set (0 )
368
392
}
369
393
}
370
394
371
- func (m * MetricsService ) SetRPCLatestLedger (ledger int64 ) {
395
+ func (m * metricsService ) SetRPCLatestLedger (ledger int64 ) {
372
396
m .rpcLatestLedger .Set (float64 (ledger ))
373
397
}
374
398
375
399
// HTTP Request Metrics
376
- func (m * MetricsService ) IncNumRequests (endpoint , method string , statusCode int ) {
400
+ func (m * metricsService ) IncNumRequests (endpoint , method string , statusCode int ) {
377
401
m .numRequestsTotal .WithLabelValues (endpoint , method , strconv .Itoa (statusCode )).Inc ()
378
402
}
379
403
380
- func (m * MetricsService ) ObserveRequestDuration (endpoint , method string , duration float64 ) {
404
+ func (m * metricsService ) ObserveRequestDuration (endpoint , method string , duration float64 ) {
381
405
m .requestsDuration .WithLabelValues (endpoint , method ).Observe (duration )
382
406
}
383
407
384
408
// DB Query Metrics
385
- func (m * MetricsService ) ObserveDBQueryDuration (queryType , table string , duration float64 ) {
409
+ func (m * metricsService ) ObserveDBQueryDuration (queryType , table string , duration float64 ) {
386
410
m .dbQueryDuration .WithLabelValues (queryType , table ).Observe (duration )
387
411
}
388
412
389
- func (m * MetricsService ) IncDBQuery (queryType , table string ) {
413
+ func (m * metricsService ) IncDBQuery (queryType , table string ) {
390
414
m .dbQueriesTotal .WithLabelValues (queryType , table ).Inc ()
391
415
}
392
416
393
417
// TSS Transaction Status Metrics
394
- func (m * MetricsService ) RecordTSSTransactionStatusTransition (oldStatus , newStatus string ) {
418
+ func (m * metricsService ) RecordTSSTransactionStatusTransition (oldStatus , newStatus string ) {
395
419
if oldStatus == newStatus {
396
420
return
397
421
}
0 commit comments