Skip to content

Commit

Permalink
Merge pull request #23022 from RoadieHQ/quiter-logs
Browse files Browse the repository at this point in the history
Make catalog logging a little quieter where entities are erroring
  • Loading branch information
freben committed Apr 9, 2024
2 parents b8999c0 + 181e24d commit c6635e5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
37 changes: 37 additions & 0 deletions .changeset/selfish-rivers-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
'@backstage/plugin-catalog-backend': patch
---

Make entity collection errors a little quieter in the logs.

Instead of logging a warning line when an entity has an error
during processing, it will now instead emit an event on the event
broker.

This only removes a single log line, however it is possible to
add the log line back if it is required by subscribing to the
`CATALOG_ERRORS_TOPIC` as shown below.

```typescript
env.eventBroker.subscribe({
supportsEventTopics(): string[] {
return [CATALOG_ERRORS_TOPIC];
},

async onEvent(
params: EventParams<{
entity: string;
location?: string;
errors: Array<Error>;
}>,
): Promise<void> {
const { entity, location, errors } = params.eventPayload;
for (const error of errors) {
env.logger.warn(error.message, {
entity,
location,
});
}
},
});
```
3 changes: 3 additions & 0 deletions plugins/catalog-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export class BuiltinKindsEntityProcessor implements CatalogProcessor_2 {
// @public (undocumented)
export const CATALOG_CONFLICTS_TOPIC = 'experimental.catalog.conflict';

// @public (undocumented)
export const CATALOG_ERRORS_TOPIC = 'experimental.catalog.errors';

// @public
export class CatalogBuilder {
addEntityPolicy(
Expand Down
2 changes: 2 additions & 0 deletions plugins/catalog-backend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@

/** @public */
export const CATALOG_CONFLICTS_TOPIC = 'experimental.catalog.conflict';
/** @public */
export const CATALOG_ERRORS_TOPIC = 'experimental.catalog.errors';
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
withActiveSpan,
} from '../util/opentelemetry';
import { deleteOrphanedEntities } from '../database/operations/util/deleteOrphanedEntities';
import { EventBroker } from '@backstage/plugin-events-node';
import { CATALOG_ERRORS_TOPIC } from '../constants';

const CACHE_TTL = 5;

Expand Down Expand Up @@ -67,6 +69,7 @@ export class DefaultCatalogProcessingEngine {
errors: Error[];
}) => Promise<void> | void;
private readonly tracker: ProgressTracker;
private readonly eventBroker?: EventBroker;

private stopFunc?: () => void;

Expand All @@ -86,6 +89,7 @@ export class DefaultCatalogProcessingEngine {
errors: Error[];
}) => Promise<void> | void;
tracker?: ProgressTracker;
eventBroker?: EventBroker;
}) {
this.config = options.config;
this.scheduler = options.scheduler;
Expand All @@ -99,6 +103,7 @@ export class DefaultCatalogProcessingEngine {
this.orphanCleanupIntervalMs = options.orphanCleanupIntervalMs ?? 30_000;
this.onProcessingError = options.onProcessingError;
this.tracker = options.tracker ?? progressTracker();
this.eventBroker = options.eventBroker;

this.stopFunc = undefined;
}
Expand Down Expand Up @@ -194,10 +199,14 @@ export class DefaultCatalogProcessingEngine {

const location =
unprocessedEntity?.metadata?.annotations?.[ANNOTATION_LOCATION];
for (const error of result.errors) {
this.logger.warn(error.message, {
entity: entityRef,
location,
if (result.errors.length) {
this.eventBroker?.publish({
topic: CATALOG_ERRORS_TOPIC,
eventPayload: {
entity: entityRef,
location,
errors: result.errors,
},
});
}
const errorsString = JSON.stringify(
Expand Down
1 change: 1 addition & 0 deletions plugins/catalog-backend/src/service/CatalogBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ export class CatalogBuilder {
onProcessingError: event => {
this.onProcessingError?.(event);
},
eventBroker: this.eventBroker,
});

const locationAnalyzer =
Expand Down

0 comments on commit c6635e5

Please sign in to comment.