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

Add additional debug logging #1680

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/config/entities/__tests__/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default (): ReturnType<typeof configuration> => ({
zerionBalancesChainIds: ['137'],
swapsDecoding: true,
twapsDecoding: true,
historyDebugLogs: false,
debugLogs: false,
imitationMapping: false,
auth: false,
confirmationView: false,
Expand Down
3 changes: 1 addition & 2 deletions src/config/entities/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ export default () => ({
process.env.FF_ZERION_BALANCES_CHAIN_IDS?.split(',') ?? [],
swapsDecoding: process.env.FF_SWAPS_DECODING?.toLowerCase() === 'true',
twapsDecoding: process.env.FF_TWAPS_DECODING?.toLowerCase() === 'true',
historyDebugLogs:
process.env.FF_HISTORY_DEBUG_LOGS?.toLowerCase() === 'true',
debugLogs: process.env.FF_DEBUG_LOGS?.toLowerCase() === 'true',
imitationMapping:
process.env.FF_IMITATION_MAPPING?.toLowerCase() === 'true',
auth: process.env.FF_AUTH?.toLowerCase() === 'true',
Expand Down
2 changes: 1 addition & 1 deletion src/datasources/cache/cache.first.data.source.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('CacheFirstDataSource', () => {
jest.useFakeTimers();
fakeCacheService = new FakeCacheService();
fakeConfigurationService = new FakeConfigurationService();
fakeConfigurationService.set('features.historyDebugLogs', true);
fakeConfigurationService.set('features.debugLogs', true);
cacheFirstDataSource = new CacheFirstDataSource(
fakeCacheService,
mockNetworkService,
Expand Down
42 changes: 35 additions & 7 deletions src/datasources/cache/cache.first.data.source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@/domain/safe/entities/transaction.entity';
import { IConfigurationService } from '@/config/configuration.service.interface';
import { isArray } from 'lodash';
import { Safe } from '@/domain/safe/entities/safe.entity';

/**
* A data source which tries to retrieve values from cache using
Expand All @@ -33,7 +34,7 @@ import { isArray } from 'lodash';
*/
@Injectable()
export class CacheFirstDataSource {
private readonly isHistoryDebugLogsEnabled: boolean;
private readonly areDebugLogsEnabled: boolean;

constructor(
@Inject(CacheService) private readonly cacheService: ICacheService,
Expand All @@ -42,10 +43,8 @@ export class CacheFirstDataSource {
@Inject(IConfigurationService)
private readonly configurationService: IConfigurationService,
) {
this.isHistoryDebugLogsEnabled =
this.configurationService.getOrThrow<boolean>(
'features.historyDebugLogs',
);
this.areDebugLogsEnabled =
this.configurationService.getOrThrow<boolean>('features.debugLogs');
}

/**
Expand Down Expand Up @@ -132,15 +131,24 @@ export class CacheFirstDataSource {

// TODO: transient logging for debugging
if (
this.isHistoryDebugLogsEnabled &&
args.url.includes('all-transactions')
this.areDebugLogsEnabled &&
(args.url.includes('all-transactions') ||
args.url.includes('multisig-transactions'))
) {
this.logTransactionsCacheWrite(
startTimeMs,
args.cacheDir,
data as Page<Transaction>,
);
}

if (this.areDebugLogsEnabled && args.cacheDir.key.includes('_safe_')) {
this.logSafeMetadataCacheWrite(
startTimeMs,
args.cacheDir,
data as Safe,
);
}
}
return data;
}
Expand Down Expand Up @@ -237,4 +245,24 @@ export class CacheFirstDataSource {
}),
});
}

/**
* Logs the Safe metadata retrieved.
* NOTE: this is a debugging-only function.
* TODO: remove this function after debugging.
*/
private logSafeMetadataCacheWrite(
requestStartTime: number,
cacheDir: CacheDir,
safe: Safe,
): void {
this.loggingService.info({
type: 'cache_write',
cacheKey: cacheDir.key,
cacheField: cacheDir.field,
cacheWriteTime: new Date(),
requestStartTime: new Date(requestStartTime),
safe,
});
}
}
Loading