Skip to content

Commit

Permalink
refreshAllLocations uses a child logger with meta. Refs #3602
Browse files Browse the repository at this point in the history
When there are a large number of location, `refreshAllLocations` can
emit a lot of logs that are noisy and can make debugging hard.

To solve this problem, create a child logger with a meta : `component` =
`refreshAllLocations`. That can be used to filter out logs if needed
  • Loading branch information
Govindarajan Nagarajan committed Dec 8, 2020
1 parent faa7be4 commit e708679
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-flowers-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---

refreshAllLocations uses a child logger of the HigherOrderOperation with a meta `component` : `catalog-all-locations-refresh`
22 changes: 14 additions & 8 deletions plugins/catalog-backend/src/ingestion/HigherOrderOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,34 @@ export class HigherOrderOperations implements HigherOrderOperation {
*/
async refreshAllLocations(): Promise<void> {
const startTimestamp = process.hrtime();
this.logger.info('Beginning locations refresh');
const logger = this.logger.child({
component: 'catalog-all-locations-refresh',
});

logger.info('Locations Refresh: Beginning locations refresh');

const locations = await this.locationsCatalog.locations();
this.logger.info(`Visiting ${locations.length} locations`);
logger.info(`Locations Refresh: Visiting ${locations.length} locations`);

for (const { data: location } of locations) {
this.logger.info(
`Refreshing location ${location.type}:${location.target}`,
logger.info(
`Locations Refresh: Refreshing location ${location.type}:${location.target}`,
);
try {
await this.refreshSingleLocation(location);
await this.locationsCatalog.logUpdateSuccess(location.id, undefined);
} catch (e) {
this.logger.warn(
`Failed to refresh location ${location.type}:${location.target}, ${e.stack}`,
logger.warn(
`Locations Refresh: Failed to refresh location ${location.type}:${location.target}, ${e.stack}`,
);
await this.locationsCatalog.logUpdateFailure(location.id, e);
}
}

this.logger.info(
`Completed locations refresh in ${durationText(startTimestamp)}`,
logger.info(
`Locations Refresh: Completed locations refresh in ${durationText(
startTimestamp,
)}`,
);
}

Expand Down

0 comments on commit e708679

Please sign in to comment.