Skip to content

refactor(service-monitor): migrate module from server - #2775

Merged
shikanime merged 21 commits into
mainfrom
feat/service-monitor-nestjs
Oct 21, 2026
Merged

shikanime merged 21 commits into
mainfrom
feat/service-monitor-nestjs

Conversation

@shikanime

@shikanime shikanime commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Issues liées

Refs #1889


Quel est le comportement actuel ?

Les routes GET /api/v1/health-services, GET /api/v1/complete-services et GET /api/v1/refresh-services sont servies par l'ancienne application Fastify apps/server, via le registre services de @cpn-console/hooks.

Quel est le nouveau comportement ?

Migration du module service-monitor vers apps/server-nestjs :

  • ServiceMonitorController : routes GET /health-services, GET /complete-services (admin ListSystem), GET /refresh-services (admin ManageSystem).
  • ServiceMonitorService : agrège les services de santé terminus de chaque module plugin (ArgoCDHealthService, GitlabHealthService, RegistryHealthService, KeycloakHealthService, NexusHealthService, SonarqubeHealthService, VaultHealthService). Aucune dépendance aux paquets @cpn-console/*-plugin ni au registre services de @cpn-console/hooks, tous deux appelés à être supprimés.
  • Le gating reproduit PluginModule et HealthzModule : ConditionalModule.registerWhen sur les variables USE_*, Keycloak toujours actif ; les sondes sont exécutées à l'initialisation du module.
  • Réalignement sur les conventions du dépôt : réutilisation de MonitorInfos et MonitorStatus de @cpn-console/shared (plus de type local dupliqué), narrow typé sans as conformément à la politique stricte du dépôt, titres legacy des plugins (ArgoCD, Gitlab, Harbor, Keycloak, Nexus, SonarQube, Vault), et cause renseigné sur les sondes en échec comme dans la registry legacy.
  • La PR nginx associée est empilée : chore(nginx-strangler): route service-monitor to server-nestjs #2776.

Cette PR introduit-elle un breaking change ?

Non.

Autres informations

Parité avec l'ancien serveur : mêmes routes, même schéma de réponse (MonitorInfos), mêmes permissions admin. Le nom affiché est le titre du plugin (ex. ArgoCD), comme avec le registre hooks.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

A preview of the application is available at : https://console-pr-2775.dso.cpin-hp.numerique-interieur.fr

Please be patient, deployment may take a few minutes.

Comment thread apps/server-nestjs/package.json Resolved
@StephaneTrebel
StephaneTrebel self-requested a review September 24, 2026 14:03

@StephaneTrebel StephaneTrebel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La migration introduit quatre écarts bloquants de sécurité et de parité fonctionnelle. Ils doivent être corrigés avant la bascule Nginx de la MR empilée #2776.

@iliesmrf iliesmrf added this to the 9.27.0 milestone Sep 25, 2026
@shikanime

Copy link
Copy Markdown
Member Author

L'import AuthModule de ServiceMonitorModule est rapatrié ici depuis #2776 : le module migré doit fournir les dépendances de son UserGuard.

La PR de bascule (#2776) ne porte plus que apps/nginx-strangler/conf.d/routing.conf.

@shikanime shikanime removed the preview Deploy preview app with Argo-cd label Sep 28, 2026
@shikanime shikanime self-assigned this Sep 29, 2026
@shikanime shikanime added the refactor Refactor code label Sep 29, 2026
@shikanime
shikanime requested review from a team and StephaneTrebel and removed request for StephaneTrebel September 29, 2026 13:07

@shikanime shikanime left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict : Commentaire

Le monitor migré reproduit fidèlement la sémantique legacy (sonde périodique, dernier état servi entre passes, cause masquée sur la route publique, états SonarQube et sonde Harbor complète repris). Les points bloquants soulevés sur les commits précédents semblent traités à head ; seul un fragilité mineure subsiste dans le mapping du probe terminus.

@shikanime
shikanime force-pushed the feat/service-monitor-nestjs branch 3 times, most recently from b1888a6 to 8b0c087 Compare October 1, 2026 15:15
@iliesmrf iliesmrf modified the milestones: 9.27.0, 9.28.0 Oct 2, 2026
@shikanime
shikanime force-pushed the feat/service-monitor-nestjs branch from 43fbc77 to a0fbda4 Compare October 2, 2026 11:56

@StephaneTrebel StephaneTrebel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La migration service-monitor remplace le registre legacy par des sondes Nest conditionnelles et conserve les trois niveaux d’accès ainsi que le format de réponse. Le ledger #1889 est global et non clos à l’échelle de cette PR ; fils résolus et CI verte sur cette tête.

@StephaneTrebel StephaneTrebel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings. Les trois routes, les permissions ListSystem/ManageSystem, le masquage public de cause, les sondes conditionnelles, les verdicts Harbor/SonarQube et le rafraîchissement avec cache sont cohérents ; 29 tests ciblés et le lint des modules concernés passent, avec CI verte et anciens fils résolus. Ledger #2720 : 3/4 démontrés, documentation désormais ajoutée, mais parité en mode dev non vérifiée dans cette revue ; la bascule reste portée par #2776, et le contrôle ESLint local sans écriture relève dans main.module.ts un ordre d’import déjà présent dans la base, hors diff fonctionnel.

shikanime and others added 21 commits October 21, 2026 10:49
…iases

Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: If8a72fc86040c89440538abed8b4a0ce6a6a6964

Signed-off-by: Shikanime Deva <22115108+shikanime@users.noreply.github.com>
Co-authored-by: Automata <automata@shikanime.studio>

Signed-off-by: Shikanime Deva <22115108+shikanime@users.noreply.github.com>
…-promise awaits

Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I335fba92cfd5882a8a05c51ef59d26696a6a6964

Signed-off-by: Shikanime Deva <22115108+shikanime@users.noreply.github.com>
…ealthCheck

Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: Iaecd853ed363b4bfd770aa5b447aec656a6a6964

Signed-off-by: Shikanime Deva <22115108+shikanime@users.noreply.github.com>
Deduplicate the private isRecord copies in service-monitor.utils and
sonarqube-health.service onto src/utils/record.utils, next to
hasEntries.

Co-authored-by: Automata <automata@shikanime.studio>
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I86a0cc083756a99f4b7f47c8c7ce8a596a6a6964

Signed-off-by: Shikanime Deva <22115108+shikanime@users.noreply.github.com>
… type block

Co-authored-by: Automata <automata@shikanime.studio>
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I6b3e511e25e17db048f94a7cb31bdbb56a6a6964
…ession

Remove the parallel monitor() probe paths: Harbor and SonarQube expose a
single check() that probes the legacy monitor endpoint and reports the
verdict directly with indicator.up()/down(), carrying message and cause
as indicator data. fromHealthCheck lifts message and cause into the
MonitorInfos shape, so every probe aggregates through the same check()
path without MonitorStatus leaking into the health services.

Co-authored-by: Automata <automata@shikanime.studio>
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I746a21c6837dd2c448f192aec7d763ca6a6a6964
Replace the private MonitoredService.lastStatus array and snapshot() with
the module cache (CacheModule.register + @Inject(CACHE_MANAGER)), matching
the registry and keycloak-secret-provider pattern. Reads fall back to the
pending status until the first probe pass writes a key.

Co-authored-by: Automata <automata@shikanime.studio>
Replace the hand-rolled setInterval timer (and its OnModuleDestroy
cleanup) with @Cron(CronExpression.EVERY_5_MINUTES) on runAll, matching
INTERVAL_MS; ScheduleModule.forRoot() is already global. onModuleInit
keeps the first pass.

Co-authored-by: Automata <automata@shikanime.studio>
The service now returns MonitorInfos.cause on every read; the public
GET /health-services strips it in the controller, where the admin-only
boundary lives. getCompleteServiceHealth and read(withCause) collapse
into getServiceHealth; a cached status no longer merges over the pending
fallback, so an OK entry never inherits the pending cause.

Co-authored-by: Automata <automata@shikanime.studio>
The service returns the raw cached cause; toCause stringification now
happens in toServiceHealth at the presentation layer, alongside the
public-route stripping. fromHealthCheck stays in utils (probe parsing).

Co-authored-by: Automata <automata@shikanime.studio>
toPublicServiceHealth replaces the inline destructure in health-services,
keeping the admin-only cause rationale next to its siblings.

Co-authored-by: Automata <automata@shikanime.studio>
Co-authored-by: Automata <automata@shikanime.studio>
Co-authored-by: Automata <automata@shikanime.studio>
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: If0057ad2b52eb20390f9f7649e26eb4c6a6a6964
The probe base64-encoded the token into a Bearer header — a Basic-auth
payload under the Bearer scheme, which SonarQube rejects with 401, so
the monitor reported UNKNOW on every pass. Send the raw token, matching
sonarqube-http-client.service.ts.

Co-authored-by: Automata <automata@shikanime.studio>
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I3eb3aa5b70626b11321b2c40339b58916a6a6964
Co-authored-by: Automata <automata@shikanime.studio>
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: Icd0efdbd5cd254d3f6a0bf09a700527a6a6a6964
Co-authored-by: Automata <automata@shikanime.studio>

Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I22dfe4768465ef30ee92028dcb71a23a6a6a6964
Move CACHE_KEY to constants, MonitoredService and pendingStatus to utils, rename runAll to refreshStatuses, add a readStatus private method, validate the probe detail with a zod schema, and share REQUEST_ERROR_MESSAGE from service-monitor instead of redefining it in the sonarqube plugin.

Co-authored-by: Automata <automata@shikanime.studio>

Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: Ibdc5ba2cb37552b8b3ef7030c2b4bccd6a6a6964
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: Idd59fcc80727541b180275604bae60e76a6a6964
Replace the MonitoredService array with a Map keyed by service name, matching the cache key identity, and drop the now-redundant interface.

Co-authored-by: Automata <automata@shikanime.studio>

Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I9aa44edf3f74e7c04e7907e41d5bfbfa66215664
Move service-monitor from legacy-only to registered-not-routed in the cartographie and statut tables (7 to 10 registered, 38 to 35 legacy, total unchanged).

Co-authored-by: Automata <automata@shikanime.studio>

Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I307f3779f81c0390cf5818e6c28252f5aca0592d
@shikanime
shikanime force-pushed the feat/service-monitor-nestjs branch from 94f0518 to 85de6b3 Compare October 21, 2026 08:49
@cloud-pi-native-sonarqube

Copy link
Copy Markdown

@shikanime
shikanime added this pull request to the merge queue Oct 21, 2026
Merged via the queue into main with commit 3f3d423 Oct 21, 2026
34 checks passed
@shikanime
shikanime deleted the feat/service-monitor-nestjs branch October 21, 2026 09:46
@github-project-automation github-project-automation Bot moved this from Refinement to Done in Cloud Pi Native Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

built preview Deploy preview app with Argo-cd refactor Refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💡 [REQUEST] - Migrer le module service-monitor vers server-nestjs

3 participants