Skip to content

Commit 493c4f8

Browse files
authored
Remove redundant logging (#22108)
1 parent 27234dc commit 493c4f8

1 file changed

Lines changed: 10 additions & 21 deletions

File tree

apps/api/v2/src/lib/throttler-guard.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ export class CustomThrottlerGuard extends ThrottlerGuard {
5858
const IP = request?.headers?.["cf-connecting-ip"] ?? request?.headers?.["CF-Connecting-IP"] ?? request.ip;
5959
const response = context.switchToHttp().getResponse<Response>();
6060
const tracker = await this.getTracker(request);
61-
this.logger.verbose(
62-
`Tracker "${tracker}" generated based on: Bearer token "${request.get(
63-
"Authorization"
64-
)}", OAuth client ID "${request.get(X_CAL_CLIENT_ID)}" and IP "${IP}"`
65-
);
66-
6761
if (throttleOptions) {
6862
return this.handleApiEndpointThrottle(tracker, throttleOptions, response);
6963
}
@@ -104,9 +98,9 @@ export class CustomThrottlerGuard extends ThrottlerGuard {
10498

10599
private async handleNonApiKeyRequest(tracker: string, response: Response): Promise<boolean> {
106100
const rateLimit = this.getDefaultRateLimit(tracker);
107-
this.logger.verbose(`Tracker "${tracker}" uses default rate limits because it is not tracking api key:
101+
/*this.logger.verbose(`Tracker "${tracker}" uses default rate limits because it is not tracking api key:
108102
${JSON.stringify(rateLimit, null, 2)}
109-
`);
103+
`);*/
110104

111105
const { isBlocked } = await this.incrementRateLimit(tracker, rateLimit, response);
112106
if (isBlocked) {
@@ -150,9 +144,9 @@ export class CustomThrottlerGuard extends ThrottlerGuard {
150144

151145
const cachedRateLimits = await this.storageService.redis.get(cacheKey);
152146
if (cachedRateLimits) {
153-
this.logger.verbose(`Tracker "${tracker}" rate limits retrieved from redis cache:
147+
/*this.logger.verbose(`Tracker "${tracker}" rate limits retrieved from redis cache:
154148
${cachedRateLimits}
155-
`);
149+
`);*/
156150
return rateLimitsSchema.parse(JSON.parse(cachedRateLimits));
157151
}
158152

@@ -172,15 +166,10 @@ export class CustomThrottlerGuard extends ThrottlerGuard {
172166
select: { name: true, limit: true, ttl: true, blockDuration: true },
173167
});
174168

175-
if (rateLimits) {
176-
this.logger.verbose(`Tracker "${tracker}" rate limits retrieved from database:
177-
${JSON.stringify(rateLimits, null, 2)}`);
178-
}
179-
180169
if (!rateLimits || rateLimits.length === 0) {
181170
rateLimits = [this.getDefaultRateLimit(tracker)];
182-
this.logger.verbose(`Tracker "${tracker}" rate limits not found in database. Using default rate limits:
183-
${JSON.stringify(rateLimits, null, 2)}`);
171+
/*this.logger.verbose(`Tracker "${tracker}" rate limits not found in database. Using default rate limits:
172+
${JSON.stringify(rateLimits, null, 2)}`);*/
184173
}
185174

186175
await this.storageService.redis.set(cacheKey, JSON.stringify(rateLimits), "EX", 3600);
@@ -209,15 +198,15 @@ export class CustomThrottlerGuard extends ThrottlerGuard {
209198
);
210199
response.setHeader(`X-RateLimit-Reset-${nameFirstUpper}`, timeToBlockExpire || timeToExpire);
211200

212-
this.logger.verbose(
201+
/*this.logger.verbose(
213202
`Tracker "${tracker}" rate limit "${name}" incremented. isBlocked ${isBlocked}, totalHits ${totalHits}, timeToExpire ${timeToExpire}, timeToBlockExpire ${timeToBlockExpire}`
214-
);
215-
this.logger.verbose(
203+
);*/
204+
/*this.logger.verbose(
216205
`Tracker "${tracker}" rate limit "${name}" response headers:
217206
X-RateLimit-Limit-${nameFirstUpper}: ${limit},
218207
X-RateLimit-Remaining-${nameFirstUpper}: ${timeToBlockExpire ? 0 : Math.max(0, limit - totalHits)},
219208
X-RateLimit-Reset-${nameFirstUpper}: ${timeToBlockExpire || timeToExpire}`
220-
);
209+
);*/
221210

222211
return { isBlocked };
223212
}

0 commit comments

Comments
 (0)