From aa15229ec39f7170b9abef67e14d6d3f8037ec77 Mon Sep 17 00:00:00 2001 From: Jussi Hallila Date: Fri, 10 Jun 2022 08:36:53 +0200 Subject: [PATCH] Introduce additional JsonValue types to be storable as facts. This enables the possibility to store more complex objects for fact checking purposes. The rules engine supports walking keyed object values directly to create rules and checks Modify facts database table to have a more restricted timestamp precision for cases where the postgres server isn't configured to contain such value. This fixes the issue where in some cases `maxItems` lifecycle condition didn't work as expected. resolves #11595 Signed-off-by: Jussi Hallila --- .changeset/warm-lions-retire.md | 8 +++++ ...2022060100821_facts_timestamp_precision.js | 36 +++++++++++++++++++ plugins/tech-insights-node/package.json | 1 + plugins/tech-insights-node/src/facts.ts | 13 +++++-- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 .changeset/warm-lions-retire.md create mode 100644 plugins/tech-insights-backend/migrations/2022060100821_facts_timestamp_precision.js diff --git a/.changeset/warm-lions-retire.md b/.changeset/warm-lions-retire.md new file mode 100644 index 0000000000..23cbf9d78b --- /dev/null +++ b/.changeset/warm-lions-retire.md @@ -0,0 +1,8 @@ +--- +'@backstage/plugin-tech-insights-backend': patch +'@backstage/plugin-tech-insights-node': patch +--- + +Introduce additional JsonValue types to be storable as facts. This enables the possibility to store more complex objects for fact checking purposes. The rules engine supports walking keyed object values directly to create rules and checks + +Modify facts database table to have a more restricted timestamp precision for cases where the postgres server isn't configured to contain such value. This fixes the issue where in some cases `maxItems` lifecycle condition didn't work as expected. diff --git a/plugins/tech-insights-backend/migrations/2022060100821_facts_timestamp_precision.js b/plugins/tech-insights-backend/migrations/2022060100821_facts_timestamp_precision.js new file mode 100644 index 0000000000..ea889d3928 --- /dev/null +++ b/plugins/tech-insights-backend/migrations/2022060100821_facts_timestamp_precision.js @@ -0,0 +1,36 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// @ts-check + +/** + * @param {import('knex').Knex} knex + */ +exports.up = async function up(knex) { + await knex.schema.alterTable('facts', table => { + table + .dateTime('timestamp', { precision: 0 }) + .defaultTo(knex.fn.now()) + .notNullable() + .comment('The timestamp when this entry was created') + .alter(); + }); +}; + +/** + * @param {import('knex').Knex} _knex + */ +exports.down = async function down(_knex) {}; diff --git a/plugins/tech-insights-node/package.json b/plugins/tech-insights-node/package.json index b17c635a8a..0312b1d91f 100644 --- a/plugins/tech-insights-node/package.json +++ b/plugins/tech-insights-node/package.json @@ -36,6 +36,7 @@ "@backstage/backend-common": "^0.14.0-next.2", "@backstage/config": "^1.0.1", "@backstage/plugin-tech-insights-common": "^0.2.4", + "@backstage/types": "^1.0.0", "@types/luxon": "^2.0.5", "luxon": "^2.0.2", "winston": "^3.2.1" diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index ffd3549bd5..bcc2aa42e1 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -15,6 +15,7 @@ */ import { DateTime, Duration, DurationLike } from 'luxon'; import { Config } from '@backstage/config'; +import { JsonValue } from '@backstage/types'; import { PluginEndpointDiscovery, TokenManager, @@ -55,6 +56,7 @@ export type TechInsightFact = { | string[] | boolean[] | DateTime[] + | JsonValue >; /** @@ -94,9 +96,16 @@ export type FactSchema = { * Type of the individual fact value * * Numbers are split into integers and floating point values. - * `set` indicates a collection of values + * `set` indicates a collection of values, `object` indicates JSON serializable value */ - type: 'integer' | 'float' | 'string' | 'boolean' | 'datetime' | 'set'; + type: + | 'integer' + | 'float' + | 'string' + | 'boolean' + | 'datetime' + | 'set' + | 'object'; /** * A description of this individual fact value