Skip to content

Commit

Permalink
[OTE-821] Affiliates roundtable metrics (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 authored Sep 20, 2024
1 parent 900984e commit a01cb54
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stats } from '@dydxprotocol-indexer/base';
import {
dbHelpers,
testConstants,
Expand Down Expand Up @@ -263,6 +264,23 @@ describe('update-affiliate-info', () => {
const updatedInfo = await AffiliateInfoTable.findById(testConstants.defaultWallet2.address);
expect(updatedInfo).toEqual(expectedAffiliateInfo);
});

it('Successfully records metrics', async () => {
jest.spyOn(stats, 'gauge');

await PersistentCacheTable.create({
key: PersistentCacheKeys.AFFILIATE_INFO_UPDATE_TIME,
value: DateTime.utc().toISO(),
});

await affiliateInfoUpdateTask();

expect(stats.gauge).toHaveBeenCalledWith(
`roundtable.persistent_cache_${PersistentCacheKeys.AFFILIATE_INFO_UPDATE_TIME}_lag_seconds`,
expect.any(Number),
{ cache: PersistentCacheKeys.AFFILIATE_INFO_UPDATE_TIME },
);
});
});

async function getAffiliateInfoUpdateTime(): Promise<DateTime | undefined> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stats } from '@dydxprotocol-indexer/base';
import {
dbHelpers,
testConstants,
Expand Down Expand Up @@ -222,6 +223,23 @@ describe('update-wallet-total-volume', () => {
totalVolume: '14', // 1 + 4 + 9
}));
});

it('Successfully records metrics', async () => {
jest.spyOn(stats, 'gauge');

await PersistentCacheTable.create({
key: PersistentCacheKeys.TOTAL_VOLUME_UPDATE_TIME,
value: DateTime.utc().toISO(),
});

await walletTotalVolumeUpdateTask();

expect(stats.gauge).toHaveBeenCalledWith(
`roundtable.persistent_cache_${PersistentCacheKeys.TOTAL_VOLUME_UPDATE_TIME}_lag_seconds`,
expect.any(Number),
{ cache: PersistentCacheKeys.TOTAL_VOLUME_UPDATE_TIME },
);
});
});

async function getTotalVolumeUpdateTime(): Promise<DateTime | undefined> {
Expand Down
11 changes: 10 additions & 1 deletion indexer/services/roundtable/src/tasks/update-affiliate-info.ts
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 {
PersistentCacheTable,
AffiliateInfoTable,
Expand All @@ -10,6 +10,8 @@ import {
} from '@dydxprotocol-indexer/postgres';
import { DateTime } from 'luxon';

import config from '../config';

const defaultLastUpdateTime: string = '2024-09-16T00:00:00Z';

/**
Expand All @@ -36,6 +38,13 @@ export default async function runTask(): Promise<void> {
? persistentCacheEntry.value
: defaultLastUpdateTime);

// Track how long ago the last update time (windowStartTime) in persistent cache was
stats.gauge(
`${config.SERVICE_NAME}.persistent_cache_${PersistentCacheKeys.AFFILIATE_INFO_UPDATE_TIME}_lag_seconds`,
DateTime.utc().diff(windowStartTime).as('seconds'),
{ cache: PersistentCacheKeys.AFFILIATE_INFO_UPDATE_TIME },
);

let windowEndTime = DateTime.fromISO(latestBlock.time);
// During backfilling, we process one day at a time to reduce roundtable runtime.
if (windowEndTime > windowStartTime.plus({ days: 1 })) {
Expand Down
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 {
PersistentCacheTable,
WalletTable,
Expand All @@ -10,6 +10,8 @@ import {
} from '@dydxprotocol-indexer/postgres';
import { DateTime } from 'luxon';

import config from '../config';

const defaultLastUpdateTime: string = '2023-10-26T00:00:00Z';

/**
Expand Down Expand Up @@ -39,6 +41,13 @@ export default async function runTask(): Promise<void> {
? persistentCacheEntry.value
: defaultLastUpdateTime);

// Track how long ago the last update time (windowStartTime) in persistent cache was
stats.gauge(
`${config.SERVICE_NAME}.persistent_cache_${PersistentCacheKeys.TOTAL_VOLUME_UPDATE_TIME}_lag_seconds`,
DateTime.utc().diff(windowStartTime).as('seconds'),
{ cache: PersistentCacheKeys.TOTAL_VOLUME_UPDATE_TIME },
);

let windowEndTime = DateTime.fromISO(latestBlock.time);
// During backfilling, we process one day at a time to reduce roundtable runtime.
if (windowEndTime > windowStartTime.plus({ days: 1 })) {
Expand Down

0 comments on commit a01cb54

Please sign in to comment.