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 <tomislacker@users.noreply.github.com>
This commit is contained in:
tomislacker
2025-12-18 12:29:33 -05:00
parent 05fe7d53e8
commit a7ec48f980
2 changed files with 37 additions and 7 deletions
@@ -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 };
@@ -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!