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:
Etienne
2025-02-10 12:24:42 +01:00
committed by GitHub
parent e70e69cf94
commit d4ffd52988
12 changed files with 213 additions and 4 deletions

View File

@ -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',
);
}
}
}