Skip to content

Commit

Permalink
add more granular stats for liquidations/deleveraging (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
dydxwill authored Jan 5, 2024
1 parent db848d2 commit a495f46
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger } from '@dydxprotocol-indexer/base';
import { logger, stats } from '@dydxprotocol-indexer/base';
import { redis } from '@dydxprotocol-indexer/redis';
import {
assetRefresher,
Expand Down Expand Up @@ -73,6 +73,9 @@ describe('DeleveragingHandler', () => {
beforeAll(async () => {
await dbHelpers.migrate();
await createPostgresFunctions();
jest.spyOn(stats, 'increment');
jest.spyOn(stats, 'timing');
jest.spyOn(stats, 'gauge');
});

beforeEach(async () => {
Expand Down Expand Up @@ -315,6 +318,7 @@ describe('DeleveragingHandler', () => {
producerSendMock,
eventId,
),
expectTimingStats(),
]);
});

Expand Down Expand Up @@ -345,3 +349,14 @@ describe('DeleveragingHandler', () => {
);
}
});

function expectTimingStats() {
expect(stats.timing).toHaveBeenCalledWith(
'ender.handle_event.timing',
expect.any(Number),
{
className: 'DeleveragingHandler',
eventType: 'DeleveragingEvent',
},
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger } from '@dydxprotocol-indexer/base';
import { logger, stats } from '@dydxprotocol-indexer/base';
import {
IndexerTendermintBlock, IndexerTendermintEvent, Timestamp,
LiquidationOrderV1,
Expand Down Expand Up @@ -89,6 +89,9 @@ describe('LiquidationHandler', () => {
beforeAll(async () => {
await dbHelpers.migrate();
await createPostgresFunctions();
jest.spyOn(stats, 'increment');
jest.spyOn(stats, 'timing');
jest.spyOn(stats, 'gauge');
});

beforeEach(async () => {
Expand Down Expand Up @@ -976,6 +979,7 @@ describe('LiquidationHandler', () => {
OrderTable.orderIdToUuid(makerOrderProto.orderId!),
orderFillEvent.totalFilledMaker.toString(),
),
expectTimingStats(),
]);
});

Expand Down Expand Up @@ -1196,3 +1200,14 @@ async function expectNoCandles() {
const candles: CandleFromDatabase[] = await CandleTable.findAll({}, []);
expect(candles.length).toEqual(0);
}

function expectTimingStats() {
expect(stats.timing).toHaveBeenCalledWith(
'ender.handle_event.timing',
expect.any(Number),
{
className: 'LiquidationHandler',
eventType: 'LiquidationEvent',
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import { AbstractOrderFillHandler } from './abstract-order-fill-handler';

export class LiquidationHandler extends AbstractOrderFillHandler<OrderFillWithLiquidity> {
eventType: string = 'OrderFillEvent';
eventType: string = 'LiquidationEvent';

/**
* @returns the parallelizationIds for the this.event.liquidity order
Expand Down

0 comments on commit a495f46

Please sign in to comment.