1
+ import { Counter } from 'prom-client' ;
1
2
import { FillQuoteTransformerOrderType , Orderbook , SignedLimitOrder } from '../asset-swapper' ;
3
+ import { PROMETHEUS_LABEL_STATUS_ERROR , PROMETHEUS_LABEL_STATUS_OK } from '../config' ;
2
4
import { DEFAULT_PAGE , DEFAULT_PER_PAGE } from '../constants' ;
3
5
import { logger } from '../logger' ;
4
6
import { OrderBookService } from '../services/orderbook_service' ;
5
7
import { SRAOrder } from '../types' ;
6
8
9
+ const ORDERBOOK_REQUESTS = new Counter ( {
10
+ name : 'orderbook_requests' ,
11
+ help : 'The count of orderbook requests' ,
12
+ labelNames : [ 'status' ] ,
13
+ } ) ;
14
+
7
15
export class AssetSwapperOrderbook extends Orderbook {
8
16
constructor ( public readonly orderbookService : OrderBookService ) {
9
17
super ( ) ;
@@ -30,6 +38,7 @@ export class AssetSwapperOrderbook extends Orderbook {
30
38
{ } ,
31
39
)
32
40
. catch ( ( err ) => {
41
+ ORDERBOOK_REQUESTS . labels ( PROMETHEUS_LABEL_STATUS_ERROR ) . inc ( ) ;
33
42
logger . warn (
34
43
{
35
44
takerToken,
@@ -38,12 +47,12 @@ export class AssetSwapperOrderbook extends Orderbook {
38
47
} ,
39
48
'Request to OrderBookService failed' ,
40
49
) ;
41
-
42
50
return {
43
51
records : [ ] ,
44
52
} ;
45
53
} ) ;
46
54
55
+ ORDERBOOK_REQUESTS . labels ( PROMETHEUS_LABEL_STATUS_OK ) . inc ( ) ;
47
56
const orders = apiOrders . records . map ( apiOrderToOrderbookOrder ) ;
48
57
const result = pruneFn ? orders . filter ( pruneFn ) : orders ;
49
58
return result ;
0 commit comments