From 05c292cd55ba027feb2ac6a0e1498685fe96fb2f Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Thu, 6 Feb 2025 14:59:14 +0100 Subject: [PATCH] feat: track error count for unexpected errors during schema publish/check (#6480) --- .../schema/providers/schema-publisher.ts | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/services/api/src/modules/schema/providers/schema-publisher.ts b/packages/services/api/src/modules/schema/providers/schema-publisher.ts index fbcdc7b0d..2dca30ce7 100644 --- a/packages/services/api/src/modules/schema/providers/schema-publisher.ts +++ b/packages/services/api/src/modules/schema/providers/schema-publisher.ts @@ -69,6 +69,18 @@ const schemaPublishCount = new promClient.Counter({ labelNames: ['model', 'projectType', 'conclusion'], }); +const schemaPublishUnexpectedErrorCount = new promClient.Counter({ + name: 'registry_publish_unexpected_error_count', + help: 'Unexpected, not gracefully handled errors. E.g. from GitHub or other third-party services.', + labelNames: ['errorName'], +}); + +const schemaCheckUnexpectedErrorCount = new promClient.Counter({ + name: 'registry_check_unexpected_error_count', + help: 'Unexpected, not gracefully handled errors. E.g. from GitHub or other third-party services.', + labelNames: ['errorName'], +}); + const schemaDeleteCount = new promClient.Counter({ name: 'registry_delete_count', help: 'Number of schema deletes', @@ -250,7 +262,7 @@ export class SchemaPublisher { }; } - @traceFn('SchemaPublisher.check', { + @traceFn('SchemaPublisher.internalCheck', { initAttributes: input => ({ 'hive.organization.slug': input.target?.bySelector?.organizationSlug, 'hive.project.slug': input.target?.bySelector?.projectSlug, @@ -261,7 +273,7 @@ export class SchemaPublisher { 'hive.check.result': result.__typename, }), }) - async check(input: CheckInput) { + private async internalCheck(input: CheckInput) { this.logger.info('Checking schema (input=%o)', lodash.omit(input, ['sdl'])); const selector = await this.idTranslator.resolveTargetReference({ @@ -959,6 +971,18 @@ export class SchemaPublisher { } as const; } + async check(input: CheckInput) { + return await this.internalCheck(input).catch(error => { + if (error instanceof HiveError === false) { + schemaCheckUnexpectedErrorCount.inc({ + errorName: (error instanceof Error && error.name) || 'unknown', + }); + } + + throw error; + }); + } + @traceFn('SchemaPublisher.publish', { initAttributes: (input, _) => ({ 'hive.organization.slug': input.target?.bySelector?.organizationSlug, @@ -1082,6 +1106,12 @@ export class SchemaPublisher { } satisfies PublishResult; } + if (error instanceof HiveError === false) { + schemaPublishUnexpectedErrorCount.inc({ + errorName: (error instanceof Error && error.name) || 'unknown', + }); + } + throw error; }); }