From 2e0689e536245e45e0dd426f60d513a68a42e5b4 Mon Sep 17 00:00:00 2001 From: Niek te Grootenhuis Date: Fri, 19 Aug 2022 13:51:49 +0200 Subject: [PATCH 1/7] fix: createFactRetriever not supporting timeout Signed-off-by: Niek te Grootenhuis --- .changeset/strong-planes-return.md | 6 ++++++ .../src/service/fact/createFactRetriever.ts | 6 +++++- plugins/tech-insights-node/package.json | 1 + plugins/tech-insights-node/src/facts.ts | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .changeset/strong-planes-return.md diff --git a/.changeset/strong-planes-return.md b/.changeset/strong-planes-return.md new file mode 100644 index 0000000000..d7f02934c9 --- /dev/null +++ b/.changeset/strong-planes-return.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-tech-insights-backend': minor +'@backstage/plugin-tech-insights-node': minor +--- + +Support for timeout in FactRetrieverRegistrationOptions diff --git a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts index de49888e1b..c14cc260f9 100644 --- a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { HumanDuration } from '@backstage/backend-tasks'; import { FactLifecycle, FactRetriever, FactRetrieverRegistration, } from '@backstage/plugin-tech-insights-node'; +import { Duration } from 'luxon'; /** * @public @@ -31,6 +33,7 @@ export type FactRetrieverRegistrationOptions = { cadence: string; factRetriever: FactRetriever; lifecycle?: FactLifecycle; + timeout: Duration | HumanDuration; }; /** @@ -64,10 +67,11 @@ export type FactRetrieverRegistrationOptions = { export function createFactRetrieverRegistration( options: FactRetrieverRegistrationOptions, ): FactRetrieverRegistration { - const { cadence, factRetriever, lifecycle } = options; + const { cadence, factRetriever, lifecycle, timeout } = options; return { cadence, factRetriever, lifecycle, + timeout, }; } diff --git a/plugins/tech-insights-node/package.json b/plugins/tech-insights-node/package.json index 0233fac050..355806bdfa 100644 --- a/plugins/tech-insights-node/package.json +++ b/plugins/tech-insights-node/package.json @@ -34,6 +34,7 @@ }, "dependencies": { "@backstage/backend-common": "^0.15.0", + "@backstage/backend-tasks": "^0.3.4", "@backstage/config": "^1.0.1", "@backstage/plugin-tech-insights-common": "^0.2.6", "@backstage/types": "^1.0.0", diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index cda238694f..41db302fd5 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -21,6 +21,7 @@ import { TokenManager, } from '@backstage/backend-common'; import { Logger } from 'winston'; +import { HumanDuration } from '@backstage/backend-tasks'; /** * A container for facts. The shape of the fact records needs to correspond to the FactSchema with same `ref` value. @@ -270,7 +271,7 @@ export type FactRetrieverRegistration = { * defaults to 5 minutes. * */ - timeout?: Duration; + timeout?: Duration | HumanDuration; /** * Fact lifecycle definition From cfddfca453611eac16ec26fb07afee57f9ca95da Mon Sep 17 00:00:00 2001 From: Niek te Grootenhuis Date: Fri, 19 Aug 2022 14:01:59 +0200 Subject: [PATCH 2/7] docs: added missing param to docs Signed-off-by: Niek te Grootenhuis --- .../src/service/fact/createFactRetriever.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts index c14cc260f9..6f1cc25d48 100644 --- a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts @@ -27,6 +27,7 @@ import { Duration } from 'luxon'; * @param cadence - cron expression to indicate when the fact retriever should be triggered * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run + * @param timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes * */ export type FactRetrieverRegistrationOptions = { @@ -40,10 +41,10 @@ export type FactRetrieverRegistrationOptions = { * @public * * A helper function to construct fact retriever registrations. - * - * @param cadence - cron expression to indicate when the fact retriever should be triggered - * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler - * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run + * @param options.cadence - Cron expression to indicate when the fact retriever should be triggered + * @param options.factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler + * @param options.lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run + * @param options.timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes * * * @remarks From 03fe82e6d1ac0247b67721e5b35ca9eef81dbe0c Mon Sep 17 00:00:00 2001 From: Niek te Grootenhuis Date: Fri, 19 Aug 2022 14:02:36 +0200 Subject: [PATCH 3/7] chore: made timeout property optional Signed-off-by: Niek te Grootenhuis --- .../src/service/fact/createFactRetriever.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts index 6f1cc25d48..aa4d9aff03 100644 --- a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts @@ -34,7 +34,7 @@ export type FactRetrieverRegistrationOptions = { cadence: string; factRetriever: FactRetriever; lifecycle?: FactLifecycle; - timeout: Duration | HumanDuration; + timeout?: Duration | HumanDuration; }; /** From 0ec1dd309813c9b3a4b511a7a85fd9349975a6a6 Mon Sep 17 00:00:00 2001 From: Niek te Grootenhuis Date: Mon, 22 Aug 2022 10:06:31 +0200 Subject: [PATCH 4/7] chore: updated api-reports Signed-off-by: Niek te Grootenhuis --- plugins/tech-insights-backend/api-report.md | 3 +++ plugins/tech-insights-node/api-report.md | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/tech-insights-backend/api-report.md b/plugins/tech-insights-backend/api-report.md index dc90d76107..5d08a644db 100644 --- a/plugins/tech-insights-backend/api-report.md +++ b/plugins/tech-insights-backend/api-report.md @@ -5,6 +5,7 @@ ```ts import { CheckResult } from '@backstage/plugin-tech-insights-common'; import { Config } from '@backstage/config'; +import { Duration } from 'luxon'; import express from 'express'; import { FactChecker } from '@backstage/plugin-tech-insights-node'; import { FactCheckerFactory } from '@backstage/plugin-tech-insights-node'; @@ -12,6 +13,7 @@ import { FactLifecycle } from '@backstage/plugin-tech-insights-node'; import { FactRetriever } from '@backstage/plugin-tech-insights-node'; import { FactRetrieverRegistration } from '@backstage/plugin-tech-insights-node'; import { FactSchema } from '@backstage/plugin-tech-insights-node'; +import { HumanDuration } from '@backstage/backend-tasks'; import { Logger } from 'winston'; import { PluginDatabaseManager } from '@backstage/backend-common'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; @@ -50,6 +52,7 @@ export type FactRetrieverRegistrationOptions = { cadence: string; factRetriever: FactRetriever; lifecycle?: FactLifecycle; + timeout?: Duration | HumanDuration; }; // @public (undocumented) diff --git a/plugins/tech-insights-node/api-report.md b/plugins/tech-insights-node/api-report.md index 19645d604b..a57cf3ec4a 100644 --- a/plugins/tech-insights-node/api-report.md +++ b/plugins/tech-insights-node/api-report.md @@ -8,6 +8,7 @@ import { Config } from '@backstage/config'; import { DateTime } from 'luxon'; import { Duration } from 'luxon'; import { DurationLike } from 'luxon'; +import { HumanDuration } from '@backstage/backend-tasks'; import { JsonValue } from '@backstage/types'; import { Logger } from 'winston'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; @@ -72,7 +73,7 @@ export type FactRetrieverContext = { export type FactRetrieverRegistration = { factRetriever: FactRetriever; cadence?: string; - timeout?: Duration; + timeout?: Duration | HumanDuration; lifecycle?: FactLifecycle; }; From 6cad070a728fbfa38b9332d074f5f0c82ea5a7e0 Mon Sep 17 00:00:00 2001 From: Niek te Grootenhuis Date: Mon, 22 Aug 2022 10:23:34 +0200 Subject: [PATCH 5/7] chore: remove options reference from jsdoc Signed-off-by: Niek te Grootenhuis --- .../src/service/fact/createFactRetriever.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts index aa4d9aff03..aaba29ecb1 100644 --- a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts @@ -41,10 +41,10 @@ export type FactRetrieverRegistrationOptions = { * @public * * A helper function to construct fact retriever registrations. - * @param options.cadence - Cron expression to indicate when the fact retriever should be triggered - * @param options.factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler - * @param options.lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run - * @param options.timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes + * @param cadence - Cron expression to indicate when the fact retriever should be triggered + * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler + * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run + * @param timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes * * * @remarks From 99138edc66aaaae4f6b4e62f90a0fae5843ab450 Mon Sep 17 00:00:00 2001 From: Niek te Grootenhuis Date: Mon, 22 Aug 2022 10:40:43 +0200 Subject: [PATCH 6/7] chore: add missing luxon types Signed-off-by: Niek te Grootenhuis --- plugins/tech-insights-backend/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/tech-insights-backend/package.json b/plugins/tech-insights-backend/package.json index 194959d163..e176a5d5f6 100644 --- a/plugins/tech-insights-backend/package.json +++ b/plugins/tech-insights-backend/package.json @@ -43,6 +43,7 @@ "@backstage/plugin-tech-insights-common": "^0.2.6", "@backstage/plugin-tech-insights-node": "^0.3.3", "@types/express": "^4.17.6", + "@types/luxon": "^3.0.0", "express": "^4.17.1", "express-promise-router": "^4.1.0", "knex": "^2.0.0", @@ -56,8 +57,8 @@ "devDependencies": { "@backstage/backend-test-utils": "^0.1.27", "@backstage/cli": "^0.18.1", - "@types/supertest": "^2.0.8", "@types/semver": "^7.3.8", + "@types/supertest": "^2.0.8", "supertest": "^6.1.3", "wait-for-expect": "^3.0.2" }, From 43af5770912ebbca00f6000497f2090d5b4017bb Mon Sep 17 00:00:00 2001 From: Niek te Grootenhuis Date: Tue, 23 Aug 2022 10:10:40 +0200 Subject: [PATCH 7/7] chore: changeset patch instead of minor Signed-off-by: Niek te Grootenhuis --- .changeset/strong-planes-return.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/strong-planes-return.md b/.changeset/strong-planes-return.md index d7f02934c9..5b5648528a 100644 --- a/.changeset/strong-planes-return.md +++ b/.changeset/strong-planes-return.md @@ -1,6 +1,6 @@ --- -'@backstage/plugin-tech-insights-backend': minor -'@backstage/plugin-tech-insights-node': minor +'@backstage/plugin-tech-insights-backend': patch +'@backstage/plugin-tech-insights-node': patch --- Support for timeout in FactRetrieverRegistrationOptions