Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTE-821] Affiliates roundtable metrics #2311

Merged
merged 32 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9ddfb77
add update affiliate info roundtable
jerryfan01234 Sep 10, 2024
368742b
modify affiliate api stubs
jerryfan01234 Sep 11, 2024
bc16518
implement comlink GET affiliates/metadata
jerryfan01234 Sep 11, 2024
0a16cad
Merge branch 'main' into affiliates-comlink-metadata
jerryfan01234 Sep 11, 2024
ac62c32
tests
jerryfan01234 Sep 12, 2024
f321a91
Merge branch 'main' into affiliates-comlink-metadata
jerryfan01234 Sep 12, 2024
0784cfa
revert package.json
jerryfan01234 Sep 12, 2024
21481ec
lint fix
jerryfan01234 Sep 12, 2024
3fa0437
replace affiliates address and total_volume stubs with real implement…
jerryfan01234 Sep 12, 2024
5e7e139
Merge branch 'main' into affiliates-comlink-total-volume
jerryfan01234 Sep 13, 2024
93d3f83
replace affiliates snapshot stub with real implementation
jerryfan01234 Sep 16, 2024
dd9d66c
Merge branch 'main' into affiliates-comlink-affiliate-info
jerryfan01234 Sep 16, 2024
860f044
Merge branch 'main' into affiliates-roundtable-affiliate-info
jerryfan01234 Sep 16, 2024
804fc75
Merge branch 'affiliates-comlink-affiliate-info' into affiliates-roun…
jerryfan01234 Sep 16, 2024
cf8e449
Merge branch 'main' into affiliates-roundtable-affiliate-info
jerryfan01234 Sep 17, 2024
6f4447a
minor edits
jerryfan01234 Sep 18, 2024
46439ee
Merge branch 'main' into affiliates-roundtable-affiliate-info
jerryfan01234 Sep 18, 2024
d6fdbb4
minor edit
jerryfan01234 Sep 18, 2024
b0c02f4
minor edit
jerryfan01234 Sep 18, 2024
38c7da3
minor edit
jerryfan01234 Sep 18, 2024
6a681a0
pr revision
jerryfan01234 Sep 19, 2024
c4036b0
address most PR comments
jerryfan01234 Sep 19, 2024
dedb955
resolve race condition and revert wallet roundtable
jerryfan01234 Sep 19, 2024
436c4d2
revision
jerryfan01234 Sep 19, 2024
bcb20ba
Wrap wallet total volume roundtable queries in transaction
jerryfan01234 Sep 20, 2024
ca5355a
Merge branch 'main' into affiliates-roundtable-total-volume
jerryfan01234 Sep 20, 2024
4db9ad7
minor edit
jerryfan01234 Sep 20, 2024
e62129d
add metrics to affiliate roundtable tasks
jerryfan01234 Sep 20, 2024
7d4b127
Merge branch 'affiliates-roundtable-total-volume' into affiliates-rou…
jerryfan01234 Sep 20, 2024
de847f2
Merge branch 'main' into affiliates-roundtable-metrics
jerryfan01234 Sep 20, 2024
4703589
add gauge
jerryfan01234 Sep 20, 2024
cade120
revision
jerryfan01234 Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,19 @@ 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));
});
});

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,19 @@ 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));
});
});

async function getTotalVolumeUpdateTime(): Promise<DateTime | undefined> {
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,
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,12 @@ 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'),
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: actually since we can track this in the same dashboard let's do this

Suggested change
stats.gauge(
`${config.SERVICE_NAME}.persistent_cache_${PersistentCacheKeys.AFFILIATE_INFO_UPDATE_TIME}_lag_seconds`,
DateTime.utc().diff(windowStartTime).as('seconds'),
);
stats.gauge(
`${config.SERVICE_NAME}.persistent_cache_lag_seconds`,
DateTime.utc().diff(windowStartTime).as('seconds'),
{ cache: PersistentCacheKeys.AFFILIATE_INFO_UPDATE_TIME.},
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also for the other task

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

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,12 @@ 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'),
);

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
Loading