Skip to content

Commit

Permalink
add gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 committed Sep 20, 2024
1 parent de847f2 commit 4703589
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,16 @@ describe('update-affiliate-info', () => {
});

it('Successfully records metrics', async () => {
jest.spyOn(stats, 'timing');
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));
expect(stats.timing).toHaveBeenCalledWith(`roundtable.update_affiliate_info_timing`, expect.any(Number));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,16 @@ describe('update-wallet-total-volume', () => {
});

it('Successfully records metrics', async () => {
jest.spyOn(stats, 'timing');
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));
expect(stats.timing).toHaveBeenCalledWith(`roundtable.update_wallet_total_volume_timing`, expect.any(Number));
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger, stats} from '@dydxprotocol-indexer/base';
import { logger, stats } from '@dydxprotocol-indexer/base';
import {
PersistentCacheTable,
AffiliateInfoTable,
Expand All @@ -9,6 +9,7 @@ import {
Transaction,
} from '@dydxprotocol-indexer/postgres';
import { DateTime } from 'luxon';

import config from '../config';

const defaultLastUpdateTime: string = '2024-09-16T00:00:00Z';
Expand Down Expand Up @@ -36,7 +37,7 @@ export default async function runTask(): Promise<void> {
const windowStartTime: DateTime = DateTime.fromISO(persistentCacheEntry
? 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`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
BlockTable,
} 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,10 +40,10 @@ export default async function runTask(): Promise<void> {
const windowStartTime: DateTime = DateTime.fromISO(persistentCacheEntry
? 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`,
`${config.SERVICE_NAME}.persistent_cache_${PersistentCacheKeys.TOTAL_VOLUME_UPDATE_TIME}_lag_seconds`,
DateTime.utc().diff(windowStartTime).as('seconds'),
);

Expand Down

0 comments on commit 4703589

Please sign in to comment.