Add API timing diagnostics

This commit is contained in:
Ben
2026-06-08 00:47:11 -04:00
parent df35549f27
commit 7b7dc87242
7 changed files with 149 additions and 38 deletions
@@ -5,6 +5,7 @@ import { Repository } from 'typeorm';
import { ClientEntity } from '../../client/client.entity';
import { UserAgentReportView } from './user-agent-report.view';
import { RedisMessagingService } from '../../../services/redis-messaging.service';
import { logTiming, timeAsync, timingStart } from '../../../utils/timing.utils';
@Injectable()
export class UserAgentReportService {
@@ -22,21 +23,27 @@ export class UserAgentReportService {
}
public async getReport() {
const cachedReport = await this.redisMessagingService
const start = timingStart();
const cachedReport = await timeAsync('user agent report shared cache read', () => this.redisMessagingService
.getJsonCache<UserAgentReportView[]>(this.liveReportCacheKey)
.catch(error => {
console.error(`Live user-agent report cache read failed: ${error.message}`);
return null;
});
}));
if (cachedReport != null) {
logTiming('user agent report getReport', start, { cache: 'hit', rows: cachedReport.length });
return cachedReport;
}
if (process.env.API_ONLY == 'true') {
return this.userAgentReport.find();
const rows = await timeAsync('user agent report materialized view read', () => this.userAgentReport.find());
logTiming('user agent report getReport', start, { cache: 'miss', source: 'materialized-view', rows: rows.length });
return rows;
}
return this.refreshLiveReport();
const rows = await this.refreshLiveReport();
logTiming('user agent report getReport', start, { cache: 'miss', source: 'live-presence', rows: rows.length });
return rows;
}
public async refreshLiveReport() {
@@ -53,7 +60,8 @@ export class UserAgentReportService {
}
private async buildLiveReport() {
const presences = await this.redisMessagingService.getAllClientPresence();
const start = timingStart();
const presences = await timeAsync('user agent report all presence load', () => this.redisMessagingService.getAllClientPresence());
const rows = new Map<string, {
userAgent: string;
count: number;
@@ -95,6 +103,7 @@ export class UserAgentReportService {
console.error(`Live user-agent report cache write failed: ${error.message}`);
});
logTiming('user agent report buildLiveReport', start, { presences: presences.length, rows: report.length });
return report;
}