merge: Reduce log spam from charts (!748)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/748

Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Tess K <me@thvxl.se>
This commit is contained in:
Hazelnoot 2024-11-21 16:32:32 +00:00
commit 34a5dbe21b
2 changed files with 11 additions and 4 deletions

View File

@ -6,6 +6,8 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { ChartLoggerService } from '@/core/chart/ChartLoggerService.js';
import Logger from '@/logger.js';
import FederationChart from './charts/federation.js'; import FederationChart from './charts/federation.js';
import NotesChart from './charts/notes.js'; import NotesChart from './charts/notes.js';
import UsersChart from './charts/users.js'; import UsersChart from './charts/users.js';
@ -24,6 +26,7 @@ import type { OnApplicationShutdown } from '@nestjs/common';
export class ChartManagementService implements OnApplicationShutdown { export class ChartManagementService implements OnApplicationShutdown {
private charts; private charts;
private saveIntervalId: NodeJS.Timeout; private saveIntervalId: NodeJS.Timeout;
private readonly logger: Logger;
constructor( constructor(
private federationChart: FederationChart, private federationChart: FederationChart,
@ -38,6 +41,7 @@ export class ChartManagementService implements OnApplicationShutdown {
private perUserFollowingChart: PerUserFollowingChart, private perUserFollowingChart: PerUserFollowingChart,
private perUserDriveChart: PerUserDriveChart, private perUserDriveChart: PerUserDriveChart,
private apRequestChart: ApRequestChart, private apRequestChart: ApRequestChart,
private chartLoggerService: ChartLoggerService,
) { ) {
this.charts = [ this.charts = [
this.federationChart, this.federationChart,
@ -53,6 +57,7 @@ export class ChartManagementService implements OnApplicationShutdown {
this.perUserDriveChart, this.perUserDriveChart,
this.apRequestChart, this.apRequestChart,
]; ];
this.logger = chartLoggerService.logger;
} }
@bindThis @bindThis
@ -62,6 +67,7 @@ export class ChartManagementService implements OnApplicationShutdown {
for (const chart of this.charts) { for (const chart of this.charts) {
chart.save(); chart.save();
} }
this.logger.info('All charts saved');
}, 1000 * 60 * 20); }, 1000 * 60 * 20);
} }
@ -72,6 +78,7 @@ export class ChartManagementService implements OnApplicationShutdown {
await Promise.all( await Promise.all(
this.charts.map(chart => chart.save()), this.charts.map(chart => chart.save()),
); );
this.logger.info('All charts saved');
} }
} }

View File

@ -368,7 +368,7 @@ export default abstract class Chart<T extends Schema> {
// 初期ログデータを作成 // 初期ログデータを作成
data = this.getNewLog(null); data = this.getNewLog(null);
this.logger.info(`${this.name + (group ? `:${group}` : '')}(${span}): Initial commit created`); this.logger.debug(`${this.name + (group ? `:${group}` : '')}(${span}): Initial commit created`);
} }
const date = Chart.dateToTimestamp(current); const date = Chart.dateToTimestamp(current);
@ -398,7 +398,7 @@ export default abstract class Chart<T extends Schema> {
...columns, ...columns,
}) as RawRecord<T>; }) as RawRecord<T>;
this.logger.info(`${this.name + (group ? `:${group}` : '')}(${span}): New commit created`); this.logger.debug(`${this.name + (group ? `:${group}` : '')}(${span}): New commit created`);
return log; return log;
} finally { } finally {
@ -418,7 +418,7 @@ export default abstract class Chart<T extends Schema> {
@bindThis @bindThis
public async save(): Promise<void> { public async save(): Promise<void> {
if (this.buffer.length === 0) { if (this.buffer.length === 0) {
this.logger.info(`${this.name}: Write skipped`); this.logger.debug(`${this.name}: Write skipped`);
return; return;
} }
@ -519,7 +519,7 @@ export default abstract class Chart<T extends Schema> {
.execute(), .execute(),
]); ]);
this.logger.info(`${this.name + (logHour.group ? `:${logHour.group}` : '')}: Updated`); this.logger.debug(`${this.name + (logHour.group ? `:${logHour.group}` : '')}: Updated`);
// TODO: この一連の処理が始まった後に新たにbufferに入ったものは消さないようにする // TODO: この一連の処理が始まった後に新たにbufferに入ったものは消さないようにする
this.buffer = this.buffer.filter(q => q.group != null && (q.group !== logHour.group)); this.buffer = this.buffer.filter(q => q.group != null && (q.group !== logHour.group));