From 470358918652ef753713784e5fccdea7472cd02a Mon Sep 17 00:00:00 2001 From: Jerry Fan Date: Fri, 20 Sep 2024 15:26:03 -0400 Subject: [PATCH] add gauge --- .../__tests__/tasks/update-affiliate-info.test.ts | 6 ++---- .../__tests__/tasks/update-wallet-total-volume.test.ts | 6 ++---- .../services/roundtable/src/tasks/update-affiliate-info.ts | 5 +++-- .../roundtable/src/tasks/update-wallet-total-volume.ts | 5 +++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/indexer/services/roundtable/__tests__/tasks/update-affiliate-info.test.ts b/indexer/services/roundtable/__tests__/tasks/update-affiliate-info.test.ts index 871d3771cb..7e824eb9d7 100644 --- a/indexer/services/roundtable/__tests__/tasks/update-affiliate-info.test.ts +++ b/indexer/services/roundtable/__tests__/tasks/update-affiliate-info.test.ts @@ -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)); }); }); diff --git a/indexer/services/roundtable/__tests__/tasks/update-wallet-total-volume.test.ts b/indexer/services/roundtable/__tests__/tasks/update-wallet-total-volume.test.ts index 228c5f1e67..6ef5dcec97 100644 --- a/indexer/services/roundtable/__tests__/tasks/update-wallet-total-volume.test.ts +++ b/indexer/services/roundtable/__tests__/tasks/update-wallet-total-volume.test.ts @@ -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)); }); }); diff --git a/indexer/services/roundtable/src/tasks/update-affiliate-info.ts b/indexer/services/roundtable/src/tasks/update-affiliate-info.ts index f7a6386811..929d1a3c35 100644 --- a/indexer/services/roundtable/src/tasks/update-affiliate-info.ts +++ b/indexer/services/roundtable/src/tasks/update-affiliate-info.ts @@ -1,4 +1,4 @@ -import { logger, stats} from '@dydxprotocol-indexer/base'; +import { logger, stats } from '@dydxprotocol-indexer/base'; import { PersistentCacheTable, AffiliateInfoTable, @@ -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'; @@ -36,7 +37,7 @@ export default async function runTask(): Promise { 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`, diff --git a/indexer/services/roundtable/src/tasks/update-wallet-total-volume.ts b/indexer/services/roundtable/src/tasks/update-wallet-total-volume.ts index 09ea9727b2..4cf52c4103 100644 --- a/indexer/services/roundtable/src/tasks/update-wallet-total-volume.ts +++ b/indexer/services/roundtable/src/tasks/update-wallet-total-volume.ts @@ -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'; @@ -39,10 +40,10 @@ export default async function runTask(): Promise { 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'), );