Skip to content

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

Closed
shikanime wants to merge 3 commits into
mainfrom
pr/service-monitor-migration
Closed

shikanime wants to merge 3 commits into
mainfrom
pr/service-monitor-migration

Conversation

@shikanime

@shikanime shikanime commented Aug 13, 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.
  • Routes nginx strangler (apps/nginx-strangler) : /api/v1/health-services, /complete-services, /refresh-services routées vers server-nestjs.

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 (ServiceHealthSchema), mêmes permissions admin. Le nom affiché est le title du plugin (ex. ArgoCD), comme avec le registre hooks.

@github-actions github-actions Bot added the built label Aug 13, 2026
@shikanime
shikanime force-pushed the pr/service-monitor-migration branch 4 times, most recently from 26a371b to 6bb502c Compare August 20, 2026 12:45
@shikanime
shikanime force-pushed the pr/service-monitor-migration branch 2 times, most recently from 0860d50 to a546036 Compare August 21, 2026 12:30
@shikanime shikanime closed this Sep 1, 2026
@shikanime
shikanime deleted the pr/service-monitor-migration branch September 1, 2026 10:29
@shikanime

Copy link
Copy Markdown
Member Author

Réouverte : couverture des familles restantes pour #1889 — le fermeture précédente était un tri, pas un rejet du travail.

@shikanime
shikanime restored the pr/service-monitor-migration branch September 17, 2026 09:51
@shikanime

Copy link
Copy Markdown
Member Author

Réouverte : famille requise pour #1889. Branche recréée depuis le SHA d'origine (l'ancienne ref avait été supprimée).

@shikanime shikanime reopened this Sep 17, 2026
@shikanime
shikanime force-pushed the pr/service-monitor-migration branch 3 times, most recently from f6fef1e to 03b632b Compare September 17, 2026 12:34
@shikanime shikanime self-assigned this Sep 17, 2026
@shikanime shikanime added this to the 9.27.0 milestone Sep 17, 2026
Aggregates plugin health from the terminus health services of each
plugin module (ArgoCD/Gitlab/Harbor/Keycloak/Nexus/Sonarqube/Vault),
gated by ConditionalModule.registerWhen like the healthz module
(Keycloak always on). No dependency on @cpn-console/*-plugin packages
or the hooks services registry, both scheduled for removal.

Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I2bd222e76a19ded2c0fabcc5a69a31c86a6a6964
@shikanime
shikanime force-pushed the pr/service-monitor-migration branch from 03b632b to 121da4a Compare September 17, 2026 13:33
@shikanime
shikanime force-pushed the pr/service-monitor-migration branch from cb741bd to c2033d0 Compare September 17, 2026 14:38
@@ -0,0 +1,28 @@
import type { ServiceMonitorService } from './service-monitor.service'

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.

🔴 bug: DI casse au boot : import type { ServiceMonitorService } efface le type de design:paramtypes — Nest ne résout pas le param service. Ajouter @Inject(ServiceMonitorService) (cf log.controller.ts / system-config.controller.ts).

const probes: Array<[string, (() => Promise<unknown>) | undefined]> = [
['argocd', argocd && (() => argocd.check())],
['gitlab', gitlab && (() => gitlab.check())],
['harbor', harbor && (() => harbor.check())],

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.

🔴 bug: Drift name : le legacy (services.getStatus() dans packages/hooks/src/services.ts) renvoie serviceInfos.title (« Keycloak », « ArgoCD », « Harbor », « SonarQube »…), pas la clé lowercase ; le front affiche service.name en tooltip et data-testid (ServicesHealth.vue L86-88). Mapper les sondes vers les titres legacy.

const up = detail.status === 'up'
return [{
name,
status: up ? 'OK' : 'En échec',

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.

🟡 risk: « Dégradé » et « Inconnu » inatteignables alors que l'interface les déclare — les monitors legacy retournent WARNING (dégradation partielle gitlab/harbor/nexus/sonarqube) et UNKNOW (erreur réseau), et le front bannit sur ces deux statuts. Distinguer via httpStatus (5xx → « Dégradé », fetch KO → « Inconnu »).

return this.collect()
}

onModuleInit(): void {

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.

🟡 risk: Drift refresh : le legacy met en cache lastStatus et Monitor.refresh() réarme un setInterval (packages/shared/src/utils/plugins.ts) ; ici les 3 endpoints sont identiques (= collect() live à chaque GET), interval: INTERVAL_MS cosmétique, onModuleInit jette le résultat. Cacher le dernier statut + scheduler, sinon retirer onModuleInit et l'interval factice.

status: up ? 'OK' : 'En échec',
interval: INTERVAL_MS,
lastUpdateTimestamp: timestamp,
message: up ? 'OK' : detail.message ?? 'Service en erreur',

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.

🟡 risk: cause absent sur la branche down (5xx / indicator.down) : le legacy pose cause sur les erreurs et /complete-services l'expose aux admins (contrat cause: z.any().optional()). Ajouter cause: detail.message sur le retour down.

argocd.check.mockResolvedValue({ argocd: { status: 'up', httpStatus: 200 } })
const keycloak = mockDeep<KeycloakHealthService>()
keycloak.check.mockResolvedValue({ keycloak: { status: 'down', httpStatus: 500 } })
const service = new ServiceMonitorService(keycloak, argocd, undefined, undefined, undefined, undefined, undefined)

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.

🔵 nit: 7 positionnels undefined dans new ServiceMonitorService(...) (aussi L27, L37, L51) : un réordonnancement du constructeur passe inaperçu. Objet d'options ou builder de fixtures.

…down

Co-authored-by: Automata <automata@shikanime.studio>
@cloud-pi-native-sonarqube

Copy link
Copy Markdown

@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.

Revue rapide : l'agrégation de probes est propre (ConditionalModule + probes optionnels). Un point de scope hors migration, détaillé inline.

@shikanime

Copy link
Copy Markdown
Member Author

🟠 Important : la suppression des 7 deps @cpn-console/*-plugin dans apps/server-nestjs/package.json (+ lockfile) est hors périmètre de la migration service-monitor. Si c'est un nettoyage volontaire (les plugins ne sont plus importés directement), à faire dans une PR séparée — sinon à retirer pour garder ce diff reviewable. @cpn-console/hooks reste conservé, OK.

@shikanime

Copy link
Copy Markdown
Member Author

Scindée en deux PR empilées :

@shikanime shikanime added the preview Deploy preview app with Argo-cd label Sep 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Hey !

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

Please be patient, deployment may take a few minutes.

@shikanime

Copy link
Copy Markdown
Member Author

Superseded by #2775 (+ #2776 for the nginx strangler routing).

@shikanime shikanime closed this Sep 24, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant