From 21ebf8dd5e3b600c2af407259adf57cb78a8e6c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 17 May 2021 10:47:08 +0200 Subject: [PATCH] address comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../software-catalog/descriptor-format.md | 8 +++---- .../software-catalog/well-known-statuses.md | 4 ++-- .../catalog-backend/src/next/Stitcher.test.ts | 8 ++----- plugins/catalog-backend/src/next/Stitcher.ts | 22 +++++++++++++------ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/docs/features/software-catalog/descriptor-format.md b/docs/features/software-catalog/descriptor-format.md index 665c729191..699574b986 100644 --- a/docs/features/software-catalog/descriptor-format.md +++ b/docs/features/software-catalog/descriptor-format.md @@ -417,7 +417,7 @@ follows. { // ... "status": { - "backstage.io/processing-status": { + "backstage.io/catalog-processing": { "errors": [] } }, @@ -428,9 +428,9 @@ follows. ``` The keys of the `status` object are arbitrary strings. We recommend that any -statuses, that are not strictly private within the organization, be namespaced -to avoid collisions. Statuses emitted by Backstage core processes will for -example be prefixed with `backstage.io/` as in the example above. +statuses that are not strictly private within the organization be namespaced to +avoid collisions. Statuses emitted by Backstage core processes will for example +be prefixed with `backstage.io/` as in the example above. The values of the `status` object are currently left unrestricted, except that they must be objects. We reserve the right to extend this model in the future, diff --git a/docs/features/software-catalog/well-known-statuses.md b/docs/features/software-catalog/well-known-statuses.md index a516c61daf..7ddf320d26 100644 --- a/docs/features/software-catalog/well-known-statuses.md +++ b/docs/features/software-catalog/well-known-statuses.md @@ -27,7 +27,7 @@ a standard concept of "severity" or "level" to these. This is a (non-exhaustive) list of statuses that are known to be in active use. -### `backstage.io/processing-status` +### `backstage.io/catalog-processing` Contains the current status of the catalog's ingestion of this entity. Errors that may appear here include inability to read from the remote SCM provider, @@ -42,7 +42,7 @@ successfully ingested. This is normal. ```yaml # Example: status: - backstage.io/processing-status: + backstage.io/catalog-processing: errors: [] ``` diff --git a/plugins/catalog-backend/src/next/Stitcher.test.ts b/plugins/catalog-backend/src/next/Stitcher.test.ts index da1b79600a..644284f3e4 100644 --- a/plugins/catalog-backend/src/next/Stitcher.test.ts +++ b/plugins/catalog-backend/src/next/Stitcher.test.ts @@ -92,9 +92,7 @@ describe('Stitcher', () => { }, ], status: { - 'backstage.io/processing-status': { - errors: [], - }, + 'backstage.io/catalog-processing': {}, }, apiVersion: 'a', kind: 'k', @@ -177,9 +175,7 @@ describe('Stitcher', () => { }, ]), status: { - 'backstage.io/processing-status': { - errors: [], - }, + 'backstage.io/catalog-processing': {}, }, apiVersion: 'a', kind: 'k', diff --git a/plugins/catalog-backend/src/next/Stitcher.ts b/plugins/catalog-backend/src/next/Stitcher.ts index 8cf96c6b7f..d7d4325ad0 100644 --- a/plugins/catalog-backend/src/next/Stitcher.ts +++ b/plugins/catalog-backend/src/next/Stitcher.ts @@ -15,6 +15,7 @@ */ import { Entity, parseEntityRef } from '@backstage/catalog-model'; +import { JsonObject } from '@backstage/config'; import { ConflictError } from '@backstage/errors'; import { createHash } from 'crypto'; import stableStringify from 'fast-json-stable-stringify'; @@ -35,6 +36,10 @@ export type DbFinalEntitiesRow = { final_entity: string; }; +type ProcessingStatus = { + errors?: JsonObject[]; +}; + function generateStableHash(entity: Entity) { return createHash('sha1') .update(stableStringify({ ...entity })) @@ -134,6 +139,7 @@ export class Stitcher { // it const entity = JSON.parse(processedEntity) as Entity; const isOrphan = Number(incomingReferenceCount) === 0; + const processingStatus: ProcessingStatus = {}; if (isOrphan) { this.logger.debug(`${entityRef} is an orphan`); @@ -142,15 +148,13 @@ export class Stitcher { ['backstage.io/orphan']: 'true', }; } - if (errors !== '') { + if (errors) { const parsedErrors = JSON.parse(errors); - entity.status = { - ...entity.status, - 'backstage.io/processing-status': { - errors: parsedErrors, - }, - }; + if (Array.isArray(parsedErrors) && parsedErrors.length) { + processingStatus.errors = parsedErrors; + } } + // TODO: entityRef is lower case and should be uppercase in the final // result entity.relations = result @@ -159,6 +163,10 @@ export class Stitcher { type: row.relationType!, target: parseEntityRef(row.relationTarget!), })); + entity.status = { + ...entity.status, + 'backstage.io/catalog-processing': processingStatus, + }; // If the output entity was actually not changed, just abort const hash = generateStableHash(entity);