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/.github/vale/Vocab/Backstage/accept.txt b/.github/vale/Vocab/Backstage/accept.txt index 198a16e566..4594b40b3e 100644 --- a/.github/vale/Vocab/Backstage/accept.txt +++ b/.github/vale/Vocab/Backstage/accept.txt @@ -302,6 +302,7 @@ superfences Superfences superset supertype +storable talkdesk Talkdesk tasklist 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/api-report.md b/plugins/tech-insights-node/api-report.md index bcccec65b5..09d409fecd 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 { JsonValue } from '@backstage/types'; import { Logger } from 'winston'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { TokenManager } from '@backstage/backend-common'; @@ -76,7 +77,14 @@ export type FactRetrieverRegistration = { // @public export type FactSchema = { [name: string]: { - type: 'integer' | 'float' | 'string' | 'boolean' | 'datetime' | 'set'; + type: + | 'integer' + | 'float' + | 'string' + | 'boolean' + | 'datetime' + | 'set' + | 'object'; description: string; since?: string; metadata?: Record; @@ -136,6 +144,7 @@ export type TechInsightFact = { | string[] | boolean[] | DateTime[] + | JsonValue >; timestamp?: DateTime; }; 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