add invalid captcha and messageChannel sync status health monitoring (#10029)
Context : We want to implement some counters to monitor server health. First counters will track : messageChannel sync status during job execution and invalid captcha. How : Counters are stored in cache and grouped by one-minute windows. Controllers are created for each metric, aggregating counter over a five-minutes window. Endpoints are public and will be queried by Prometheus. closes https://github.com/twentyhq/core-team-issues/issues/55
This commit is contained in:
@ -7,10 +7,14 @@ import {
|
||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||
|
||||
import { CaptchaService } from 'src/engine/core-modules/captcha/captcha.service';
|
||||
import { HealthCacheService } from 'src/engine/core-modules/health/health-cache.service';
|
||||
|
||||
@Injectable()
|
||||
export class CaptchaGuard implements CanActivate {
|
||||
constructor(private captchaService: CaptchaService) {}
|
||||
constructor(
|
||||
private captchaService: CaptchaService,
|
||||
private healthCacheService: HealthCacheService,
|
||||
) {}
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const ctx = GqlExecutionContext.create(context);
|
||||
@ -19,10 +23,14 @@ export class CaptchaGuard implements CanActivate {
|
||||
|
||||
const result = await this.captchaService.validate(token || '');
|
||||
|
||||
if (result.success) return true;
|
||||
else
|
||||
if (result.success) {
|
||||
return true;
|
||||
} else {
|
||||
await this.healthCacheService.incrementInvalidCaptchaCounter();
|
||||
|
||||
throw new BadRequestException(
|
||||
'Invalid Captcha, please try another device',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user