Skip to content

Commit 24bb6ad

Browse files
committed
chore: add RC_DISABLE_STATISTICS_REPORTING check to a common function
1 parent 81bec20 commit 24bb6ad

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

apps/meteor/app/statistics/server/functions/sendUsageReport.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { tracerSpan } from '@rocket.chat/tracing';
66
import { Meteor } from 'meteor/meteor';
77

88
import { statistics } from '..';
9+
import { shouldReportStatistics } from '../../../../server/cron/usageReport';
910
import { getWorkspaceAccessToken } from '../../../cloud/server';
1011

1112
async function sendStats(logger: Logger, cronStatistics: IStats): Promise<string | undefined> {
@@ -36,7 +37,7 @@ async function sendStats(logger: Logger, cronStatistics: IStats): Promise<string
3637
export async function sendUsageReport(logger: Logger): Promise<string | undefined> {
3738
// Even when disabled, we still generate statistics locally to avoid breaking
3839
// internal processes, such as restriction checks for air-gapped workspaces.
39-
const shouldSendToCollector = process.env.RC_DISABLE_STATISTICS_REPORTING?.toLowerCase() !== 'true';
40+
const shouldSendToCollector = shouldReportStatistics();
4041

4142
return tracerSpan('generateStatistics', {}, async () => {
4243
const last = await Statistics.findLast();

apps/meteor/server/cron/usageReport.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ export const sendUsageReportAndComputeRestriction = async (statsToken?: string)
1313
void AirGappedRestriction.computeRestriction(token);
1414
};
1515

16+
export const shouldReportStatistics = () => process.env.RC_DISABLE_STATISTICS_REPORTING?.toLowerCase() !== 'true';
17+
1618
export async function usageReportCron(logger: Logger): Promise<void> {
1719
// The actual send suppression happens inside `sendUsageReport`, but since this
1820
// is the entry point, we log a warning here when reporting is disabled.
19-
const shouldSendToCollector = process.env.RC_DISABLE_STATISTICS_REPORTING?.toLowerCase() !== 'true';
20-
if (!shouldSendToCollector) {
21+
if (!shouldReportStatistics()) {
2122
logger.warn(
2223
'Statistics reporting disabled via environment variable (RC_DISABLE_STATISTICS_REPORTING). This may impact product improvements.',
2324
);

0 commit comments

Comments
 (0)