From a7ec48f9809f963acffeed1ea31c57b115978b90 Mon Sep 17 00:00:00 2001 From: tomislacker Date: Thu, 18 Dec 2025 12:29:33 -0500 Subject: [PATCH] feat(msgraph): Pass explicit metric data in msgraph This includes the group count, user count, tenant ID, and operational duration of the synchronization process. With this, the JSON log output can be ingested to track metrics on the functionality. Signed-off-by: tomislacker --- .../MicrosoftGraphOrgEntityProvider.ts | 34 +++++++++++++++---- .../MicrosoftGraphOrgReaderProcessor.ts | 10 +++++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts index bf55d92d18..b223c18d6e 100644 --- a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts @@ -364,7 +364,11 @@ export class MicrosoftGraphOrgEntityProvider implements EntityProvider { }, ); - const { markCommitComplete } = markReadComplete({ users, groups }); + const { markCommitComplete } = markReadComplete({ + users, + groups, + tenantId: provider.tenantId, + }); await this.connection.applyMutation({ type: 'full', @@ -374,7 +378,7 @@ export class MicrosoftGraphOrgEntityProvider implements EntityProvider { })), }); - markCommitComplete(); + markCommitComplete(groups.length, users.length, provider.tenantId); } private schedule(taskRunner: SchedulerServiceTaskRunner) { @@ -410,17 +414,35 @@ function trackProgress(logger: LoggerService) { logger.info('Reading msgraph users and groups'); - function markReadComplete(read: { users: unknown[]; groups: unknown[] }) { + function markReadComplete(read: { + users: unknown[]; + groups: unknown[]; + tenantId: string; + }) { summary = `${read.users.length} msgraph users and ${read.groups.length} msgraph groups`; const readDuration = ((Date.now() - timestamp) / 1000).toFixed(1); timestamp = Date.now(); - logger.info(`Read ${summary} in ${readDuration} seconds. Committing...`); + logger.info(`Read ${summary} in ${readDuration} seconds. Committing...`, { + readDuration, + tenantId: read.tenantId, + usersCount: read.users.length, + groupsCount: read.groups.length, + }); return { markCommitComplete }; } - function markCommitComplete() { + function markCommitComplete( + groupsCount: number, + usersCount: number, + tenantId: string, + ) { const commitDuration = ((Date.now() - timestamp) / 1000).toFixed(1); - logger.info(`Committed ${summary} in ${commitDuration} seconds.`); + logger.info(`Committed ${summary} in ${commitDuration} seconds.`, { + commitDuration, + tenantId, + usersCount, + groupsCount, + }); } return { markReadComplete }; diff --git a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgReaderProcessor.ts b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgReaderProcessor.ts index 7c65dcee6c..9e88183dcc 100644 --- a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgReaderProcessor.ts +++ b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgReaderProcessor.ts @@ -102,7 +102,9 @@ export class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor { // Read out all the raw data const startTimestamp = Date.now(); - this.logger.info('Reading Microsoft Graph users and groups'); + this.logger.info('Reading Microsoft Graph users and groups', { + tenantId: provider.tenantId, + }); // We create a client each time as we need one that matches the specific provider const client = MicrosoftGraphClient.create(provider); @@ -131,6 +133,12 @@ export class MicrosoftGraphOrgReaderProcessor implements CatalogProcessor { const duration = ((Date.now() - startTimestamp) / 1000).toFixed(1); this.logger.debug( `Read ${users.length} users and ${groups.length} groups from Microsoft Graph in ${duration} seconds`, + { + groupCount: groups.length, + readDuration: duration, + tenantId: provider.tenantId, + userCount: users.length, + }, ); // Done!