Merge pull request #32183 from tomislacker/bugfix/msgraph-semantic-logging

fix(catalog-msgraph) Semantic Logging of Operational Statistics
This commit is contained in:
Andre Wanlin
2026-01-27 12:14:43 -06:00
committed by GitHub
3 changed files with 42 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend-module-msgraph': minor
---
Log group/user count, tenant ID, execution time as separate fields
@@ -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!