Merge pull request #8845 from RoadieHQ/fact-garbage-truck

[TechInsights] Add expiration configurations to fact retrievers
This commit is contained in:
Fredrik Adelöw
2022-01-17 16:22:46 +01:00
committed by GitHub
13 changed files with 555 additions and 33 deletions
+24 -1
View File
@@ -6,6 +6,7 @@
import { CheckResult } from '@backstage/plugin-tech-insights-common';
import { Config } from '@backstage/config';
import { DateTime } from 'luxon';
import { DurationLike } from 'luxon';
import { Logger as Logger_2 } from 'winston';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
@@ -37,6 +38,9 @@ export interface FactCheckerFactory<
): FactChecker<CheckType, CheckResultType>;
}
// @public
export type FactLifecycle = TTL | MaxItems;
// @public
export interface FactRetriever {
entityFilter?:
@@ -62,6 +66,7 @@ export type FactRetrieverContext = {
export type FactRetrieverRegistration = {
factRetriever: FactRetriever;
cadence?: string;
lifecycle?: FactLifecycle;
};
// @public
@@ -82,6 +87,11 @@ export type FlatTechInsightFact = TechInsightFact & {
id: string;
};
// @public
export type MaxItems = {
maxItems: number;
};
// @public
export interface TechInsightCheck {
description: string;
@@ -144,9 +154,22 @@ export interface TechInsightsStore {
[factRef: string]: FlatTechInsightFact;
}>;
getLatestSchemas(ids?: string[]): Promise<FactSchema[]>;
insertFacts(id: string, facts: TechInsightFact[]): Promise<void>;
insertFacts({
id,
facts,
lifecycle,
}: {
id: string;
facts: TechInsightFact[];
lifecycle?: FactLifecycle;
}): Promise<void>;
insertFactSchema(schemaDefinition: FactSchemaDefinition): Promise<void>;
}
// @public
export type TTL = {
timeToLive: DurationLike;
};
// (No @packageDocumentation comment for this package)
```
+38 -1
View File
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DateTime } from 'luxon';
import { DateTime, DurationLike } from 'luxon';
import { Config } from '@backstage/config';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { Logger } from 'winston';
@@ -190,6 +190,36 @@ export interface FactRetriever {
| Record<string, string | symbol | (string | symbol)[]>;
}
/**
* @public
*
* A Luxon duration like object for time to live value
*
* @example
* \{ timeToLive: 1209600000 \}
* \{ timeToLive: \{ weeks: 4 \} \}
*
**/
export type TTL = { timeToLive: DurationLike };
/**
* @public
*
* A maximum number for items to be kept in the database for each fact retriever/entity pair
*
* @example
* \{ maxItems: 10 \}
*
**/
export type MaxItems = { maxItems: number };
/**
* @public
*
* A fact lifecycle definition. Determines which strategy to use to purge expired facts from the database.
*/
export type FactLifecycle = TTL | MaxItems;
/**
* @public
*
@@ -216,4 +246,11 @@ export type FactRetrieverRegistration = {
*
*/
cadence?: string;
/**
* Fact lifecycle definition
*
* If defined this value will be used to determine expired items which will deleted when this fact retriever is run
*/
lifecycle?: FactLifecycle;
};
+11 -1
View File
@@ -18,6 +18,7 @@ import {
TechInsightFact,
FlatTechInsightFact,
FactSchemaDefinition,
FactLifecycle,
} from './facts';
import { DateTime } from 'luxon';
@@ -35,8 +36,17 @@ export interface TechInsightsStore {
*
* @param id - Unique identifier of the fact retriever these facts relate to
* @param facts - A collection of TechInsightFacts
* @param lifecycle - (Optional) Fact lifecycle object indicating the expiration logic for these items
*/
insertFacts(id: string, facts: TechInsightFact[]): Promise<void>;
insertFacts({
id,
facts,
lifecycle,
}: {
id: string;
facts: TechInsightFact[];
lifecycle?: FactLifecycle;
}): Promise<void>;
/**
* @param ids - A collection of fact row identifiers