Skip to content

feat(finops): optimize ReDoS regex and GitHubMetricsService N+1 pattern#9

Merged
Esaban17 merged 1 commit intomasterfrom
feature/finops-optimization
Mar 31, 2026
Merged

feat(finops): optimize ReDoS regex and GitHubMetricsService N+1 pattern#9
Esaban17 merged 1 commit intomasterfrom
feature/finops-optimization

Conversation

@Esaban17
Copy link
Copy Markdown
Collaborator

Delivery 5: FinOps Optimization & Final Defense

Optimizacion 1: ReDoS Email Regex (CPU)

  • Elimina regex con catastrophic backtracking O(2^n) en routes/products.js
  • Usa req.validatedBody de validatePurchase middleware (Zod) que ya valida el email de forma segura con z.string().email()
  • Antes: 2,745ms con input de ataque (33 chars)
  • Despues: 0.15ms — mejora del 99.99% (17,826x mas rapido)

Optimizacion 2: GitHubMetricsService N+1 (I/O)

  • Agrega cache en memoria con TTL de 5 minutos para deployments y statuses
  • Pre-carga paralela de statuses en lotes de 10 (_prefetchStatuses)
  • getAllMetrics: 1 fetch compartido en vez de 4 independientes
  • Commits de lead time: Promise.all en lotes en vez de for-await secuencial
  • Antes: ~2,519ms (154 llamadas secuenciales con 50 deployments)
  • Despues: ~180ms — mejora del 92.8% (14x mas rapido)
  • 2da llamada (cache hit): ~50ms — mejora del 98%

Tests

  • Nuevo test anti-ReDoS en validators.test.js (< 50ms con payload malicioso)
  • Nuevo test de cache en githubMetricsService.test.js
  • 35 tests pasan (unit)

Benchmarks y reporte

  • benchmarks/redos-email-benchmark.js
  • benchmarks/github-metrics-benchmark.js
  • reports/benchmarks/FINOPS_BENCHMARK_REPORT.md

README

  • Badges: CI, SonarCloud Quality Gate, Coverage, License, Node/Express/PostgreSQL
  • Estructura corregida: jerarquia de headings, Prerequisites, Documentation
  • Credenciales en bloque
    Details colapsable
  • Seccion Historial de Entregas y links a toda la documentacion

Delivery 5: FinOps Optimization & Final Defense

## Optimizacion 1: ReDoS Email Regex (CPU)
- Elimina regex con catastrophic backtracking O(2^n) en routes/products.js
- Usa req.validatedBody de validatePurchase middleware (Zod) que ya valida
  el email de forma segura con z.string().email()
- Antes: 2,745ms con input de ataque (33 chars)
- Despues: 0.15ms — mejora del 99.99% (17,826x mas rapido)

## Optimizacion 2: GitHubMetricsService N+1 (I/O)
- Agrega cache en memoria con TTL de 5 minutos para deployments y statuses
- Pre-carga paralela de statuses en lotes de 10 (_prefetchStatuses)
- getAllMetrics: 1 fetch compartido en vez de 4 independientes
- Commits de lead time: Promise.all en lotes en vez de for-await secuencial
- Antes: ~2,519ms (154 llamadas secuenciales con 50 deployments)
- Despues: ~180ms — mejora del 92.8% (14x mas rapido)
- 2da llamada (cache hit): ~50ms — mejora del 98%

## Tests
- Nuevo test anti-ReDoS en validators.test.js (< 50ms con payload malicioso)
- Nuevo test de cache en githubMetricsService.test.js
- 35 tests pasan (unit)

## Benchmarks y reporte
- benchmarks/redos-email-benchmark.js
- benchmarks/github-metrics-benchmark.js
- reports/benchmarks/FINOPS_BENCHMARK_REPORT.md

## README
- Badges: CI, SonarCloud Quality Gate, Coverage, License, Node/Express/PostgreSQL
- Estructura corregida: jerarquia de headings, Prerequisites, Documentation
- Credenciales en bloque <details> colapsable
- Seccion Historial de Entregas y links a toda la documentacion

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

@Esaban17 Esaban17 merged commit 1afcd77 into master Mar 31, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant